This web page requires JavaScript to be enabled.

JavaScript is an object-oriented computer programming language commonly used to create interactive effects within web browsers.

How to enable JavaScript?

Bài thực hành 5 – Hàng hoá [oop]

10cth1-2 March 22, 2012 1

Do code bố trí khác nên ko suất danh sách ra mà chỉ xuất cái mặt hàng vừa nhập, các bạn tự edit nha [emot]uplook[/emot]

[codes=java]import java.util.*;
import java.io.*;

class hang
{
  protected  int mahang;
  protected String tenhang;
  protected int gia;
  
  public hang(int ma, String ten, int gi)
  {
    mahang=ma;tenhang=ten;gia=gi;
  }
  
  public void nhap()
  {
    Scanner nh=new Scanner(System.in);
    System.out.print(“\nNhap ma hang: “);mahang=nh.nextInt();nh.nextLine();
    System.out.print(“Nhap ten hang: “);tenhang=nh.nextLine();
    System.out.print(“Nhap gia: “);gia=nh.nextInt();
  }
  
  public void xuat()
  {
    System.out.print(mahang+ “\t” +tenhang+ “\t” +gia);
  }
  
}

class dienmay extends hang
{
  private String timebh;
  private int dienap,congsuat;
  
  public dienmay(int ma, String ten, int gia, String time, int dien, int cs)
  {
    super(ma,ten,gia);
    timebh=time;
    dienap=dien;
    congsuat=cs;
  }
  
  public void nhap()
  {
    super.nhap();
    Scanner dm=new Scanner(System.in);
    System.out.print(“Nhap TG bao hanh: “);timebh=dm.nextLine();
    System.out.print(“Dien ap (V): “);dienap=dm.nextInt();
    System.out.print(“Cong suat (W): “); congsuat=dm.nextInt();
  }
  
  public void xuat()
  {
    super.xuat();
    System.out.println(timebh+ “\t” +dienap+ “V\t” +congsuat+”W”);
  }
}

class thucpham extends hang
{
  private String ngaysx, ngayhh;
  
  public thucpham(int ma, String ten, int gia, String sx, String hh)
  {
    super(ma,ten,gia);
    ngaysx=sx;ngayhh=hh;
  }
  
  public void nhap()
  {
    super.nhap();
    Scanner tp=new Scanner(System.in);
    System.out.print(“Nhap ngay san xuat: “);ngaysx=tp.nextLine();
    System.out.print(“Nhap ngay het date: “);ngayhh=tp.nextLine();
  }
  
  public void xuat()
  {
    super.xuat();
    System.out.println(ngaysx+ “\t” + ngayhh);
  }
}
class Test
{
  public static void main (String[] args)
  {
    /*
    dienmay h=new dienmay(0,””,0,””,0,0);
    h.nhap();
    h.xuat();
    
    thucpham t=new thucpham(0,””,0,””,””);
    t.nhap();
    t.xuat();
    */
    int n, chon;
    System.out.print(“Nhap so luong mat hang: “);
    Scanner x=new Scanner(System.in);
      n=x.nextInt();
      hang ds[]= new hang[n];
      for(int i=0; i        do{
          System.out.print(“Phim 0: Thoat\nPhim 1: Hang dien may\nPhim 2: Hang thuc pham\nPhim 3: DS\n”);
          chon=x.nextInt();
          switch(chon)
          {
            case 1:
            {
              ds[i]=new dienmay(0,””,0,””,0,0);
              ds[i].nhap();
            //  ds[i].xuat();
              break;
            }
            
            case 2:
            {
              ds[i]=new thucpham(0,””,0,””,””);
              ds[i].nhap();
            //  ds[i].xuat();
              break;
            }
            
            case 0:
            {
              chon=0;
              break;
            }
            
            case 3:
            {
              ds[i].xuat();
            }
            
            default:
            {
              System.out.print(“\nNhap lai coi!\n\n”);
            }
          }
        }while(chon!=0);
  }
}[/codes]


Last modified on December 5th, 2020 at 1:08 am

Nam Le
lequocnam



One respond

  1. le.qnam says:

    cái xuất các bạn tự cho for vào he

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.