By GokiSoft.com| 19:29 19/04/2024|
Java Basic

Bài tập Employee & StudentMark & Product trong lập trình OOP- lập trình Java căn bản - Java basic

Bài 1.

Cài đặt lớp Employee gồm các thông tin:

-       Họ tên             (String)

-       Giới tính          (String)

-       Quê quán        (String)

-       Chức vụ          (String)

-       Lương             (double)

 

Cài đặt 2 constructors.

Cài đặt các phương thức set/get cho các thuộc tính

Cài đặt hàm nhập, hiển thị.

Cài đặt lớp Test, có hàm main:

Khai báo 2 đối tượng của lớp.

1 đối tượng gọi constructor có tham số. 1 đối tượng gọi constructor không có tham số (phải gọi hàm nhập để lấy thông tin).

Gọi hàm hiển thị để hiển thị kết quả.

 

Bài 2.

Cài đặt lớp StudentMark gồm các thông tin:

-       Rollnumber

-       Họ tên

-       Lớp

-       Môn

-       Điểm.

 

Cài đặt đầy đủ: 2 constructor, các phương thức set/get.

Cài đặt hàm nhập, hiển thị.

Khai báo luôn hàm main trong lớp này:

Khai báo 2 đối tượng của lớp, khởi tạo 2 đối tượng bằng construcor không có tham số. Gọi hàm nhập để nhập vào các thông tin và hàm hiển thị để hiển thị các thông tin.

Hiển thị thông tin của người có điểm cao nhất.

 

Bài 3:

Cài đặt lớp Product gồm các thuộc tính (phải khai báo là private)

-       String maHH;

-       String tenHH;

-       float soLuong;

-       float gia1SP;

Cài đặt 2 construcors, các hàm get/set.

Cài đặt hàm input(), display().

Khai báo hàm main và thực hiện như sau:

-       Khai báo mảng có n phần tử kiểu Product.

-       Gọi nhập thông tin cho các phần tử của mảng.

-       Tìm ra sản phẩm nào có giá bán cao nhất.

Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)

Nguyễn Tiến Đạt [T2008A]
Nguyễn Tiến Đạt

2021-01-25 09:57:44

Bai 1


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lesson3;

import java.util.Scanner;

/**
 *
 * @author MyPC
 */
public class Employee {

    private String name, gender, country, position;
    private double wages;

    public Employee() {

    }

    public Employee(String name, String gender, String country, String position, double wages) {
        this.name = name;
        this.gender = gender;
        this.country = country;
        this.position = position;
        this.wages = wages;
    }

    public void Input() {
        Scanner scan = new Scanner(System.in);
        name = scan.nextLine();
        gender = scan.nextLine();
        country = scan.nextLine();
        position = scan.nextLine();
        wages = scan.nextDouble();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getPosition() {
        return position;
    }

    public void setPosition(String position) {
        this.position = position;
    }

    public double getWages() {
        return wages;
    }

    public void setWages(double wages) {
        this.wages = wages;
    }

    public void Display() {
        System.out.format("\nName: %s\nGender: %s\nCountry: %s\nPosition: %s\nWages: %f\n", name, gender, country, position, wages);
    }

}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lesson3;

/**
 *
 * @author MyPC
 */
public class EmployeeTest {
    public static void main(String[] args) {
        Employee employee1 = new Employee();
        employee1.Input();
        employee1.Display();
        
        Employee employee2 = new Employee("Nguyen Tien Dat", "Nam", "Ha Noi", "Giam doc", 184000000);
        employee2.Display();
    }
}



Đặng Trần Nhật Minh [T2008A]
Đặng Trần Nhật Minh

2021-01-25 09:32:35


Bai 1
package javalesson3;

import java.util.Scanner;

public class Employee {
    
    public String fullName;
    public String gender;
    public String homeTown;
    public String position;
    public double salary;
    
    public Employee(String fullName, String gender, String homeTown, String position, double salary) {
        
        this.fullName = fullName;
        this.gender = gender;
        this.homeTown = homeTown;
        this.position = position;
        this.salary = salary;
        
    }
    
    public Employee(){
        
    }
    
    public void input() {
        
        Scanner r = new Scanner(System.in);
        
        System.out.println("Full Name: ");
        this.fullName = r.nextLine();
        System.out.println("Gender: ");
        this.gender = r. nextLine();
        System.out.println("Home Town: ");
        this.homeTown = r.nextLine();
        System.out.println("Position: ");
        this.position = r.nextLine();
        System.out.println("Salary: ");
        this.salary = r.nextInt();
        
    }
    
    public void output() {
        
        System.out.println("Full Name: " + fullName);
        System.out.println("Gender: " + gender);
        System.out.println("Home Town: " + homeTown);
        System.out.println("Position: " + position);
        System.out.println("Salary: " + salary);
        
    }
    
}




package javalesson3;

import java.util.Scanner;

public class Test {

    public static void main(String[] args) {
        
        Scanner r = new Scanner(System.in);
        
        Employee emp1 = new Employee("Minh Dang", "Male", "Hanoi", "HR Specialist", 15.000);
        
        Employee emp2 = new Employee();
        emp2.input();
        
        emp1.output();
        emp2.output();

    }

}



hoangkhiem [C1907L]
hoangkhiem

2020-03-29 09:12:05



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package baitap;

import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Product {

    private String maHH;

    private String tenHH;

    private float soLuong;

    private float gia1SP;

    public Product() {
    }

    public Product(String maHH, String tenHH, float soLuong, float gia1SP) {
        this.maHH = maHH;
        this.tenHH = tenHH;
        this.soLuong = soLuong;
        this.gia1SP = gia1SP;
    }

    public String getMaHH() {
        return maHH;
    }

    public void setMaHH(String maHH) {
        this.maHH = maHH;
    }

    public String getTenHH() {
        return tenHH;
    }

    public void setTenHH(String tenHH) {
        this.tenHH = tenHH;
    }

    public float getSoLuong() {
        return soLuong;
    }

    public void setSoLuong(float soLuong) {
        this.soLuong = soLuong;
    }

    public float getGia1SP() {
        return gia1SP;
    }

    public void setGia1SP(float gia1SP) {
        this.gia1SP = gia1SP;
    }

    public void nhap() {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhập mã hàng hóa: ");
        maHH = input.nextLine();
        System.out.println("Nhập tên hàng hóa: ");
        tenHH = input.nextLine();
        System.out.println("Nhập số lượng: ");
        soLuong = Float.parseFloat(input.nextLine());
        System.out.println("Nhập đơn giá: ");
        gia1SP = Float.parseFloat(input.nextLine());
    }

    public void hienthi() {
        System.out.println("Mã hàng hóa là: " + maHH);
        System.out.println("Tên hàng hóa là: " + tenHH);
        System.out.println("Số Lượng là : " + soLuong);
        System.out.println("Đơn giá là : " + gia1SP);
    }

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println(" mời nhập số lượng hàng hóa : ");
        int n = Integer.parseInt(input.nextLine());
        ArrayList<Product> products = new ArrayList<>();
        float GCN;
        for (int i = 0; i < n; i++) {
            Product product = new Product();
            System.out.println("mời nhập thông tin cho sản phẩm thứ " + (i + 1) + " :");
            product.nhap();
            products.add(product);
        }
        System.out.println("***************************************");
        GCN = products.get(0).getGia1SP();
        System.out.println("Giá 1  = " + GCN);
        for (int i = 1; i < products.size(); i++) {
            if (products.get(i).getGia1SP() > GCN) {
                GCN = products.get(i).getGia1SP();
            }
        }
        System.out.println("Danh sách sản phẩm có giá cao nhất là: ");
        for (int i = 0; i < products.size(); i++) {
            if (products.get(i).getGia1SP() == GCN) {
                products.get(i).hienthi();
            }
        }
    }
}



hoangkhiem [C1907L]
hoangkhiem

2020-03-29 08:52:43



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package baitap;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class StudentMark {

    String rollnumber, hoten, classname, mon;
    float diem;

    public StudentMark() {
    }

    public StudentMark(String rollnumber, String hoten, String classname, String mon, float diem) {
        this.rollnumber = rollnumber;
        this.hoten = hoten;
        this.classname = classname;
        this.mon = mon;
        this.diem = diem;
    }

    public String getRollnumber() {
        return rollnumber;
    }

    public void setRollnumber(String rollnumber) {
        this.rollnumber = rollnumber;
    }

    public String getHoten() {
        return hoten;
    }

    public void setHoten(String hoten) {
        this.hoten = hoten;
    }

    public String getClassname() {
        return classname;
    }

    public void setClassname(String classname) {
        this.classname = classname;
    }

    public String getmon() {
        return mon;
    }

    public void setmon(String mon) {
        this.mon = mon;
    }

    public float getdiem() {
        return diem;
    }

    public void setdiem(float diem) {
        this.diem = diem;
    }

    public void nhap() {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhập mã sinh viên: ");
        rollnumber = input.nextLine();
        System.out.println("Nhập họ và tên: ");
        hoten = input.nextLine();
        System.out.println("Nhập lớp bạn học: ");
        classname = input.nextLine();
        System.out.println("Nhập môn bạn học : ");
        mon = input.nextLine();
        System.out.println("Nhập điểm của bạn: ");
        diem = Float.parseFloat(input.nextLine());
    }

    public void hienthi() {
        System.out.println("Rollnumber : " + rollnumber);
        System.out.println("Họ tên là : " + hoten);
        System.out.println("Lớp là : " + classname);
        System.out.println("Môn học là : " + mon);
        System.out.println("Điểm của sinh viên là : " + diem);
    }

    public static void main(String[] args) {
        StudentMark SV1;
        StudentMark SV2 = new StudentMark();
        SV1 = new StudentMark("D1", "Hoàng Gia KHiêm", "B002", "CNTT", 9);
        System.out.println("*******************************");
        SV2.nhap();
        SV1.hienthi();
        System.out.println("*******************************");
        SV2.hienthi();
        System.out.println("*******************************");
        System.out.println("Sinh viên có điểm cao nhất là: ");
        if (SV1.getdiem() > SV2.getdiem()) {
            SV1.hienthi();
        } else {
            SV2.hienthi();
        }
    }
}



nguyễn thị bích thủy [C1907L]
nguyễn thị bích thủy

2020-03-24 15:14:46

package bai5.Employee;

import java.util.Scanner;

/**

 *

 * @author Admin

 */

public class Employee {

    String HoTen;

    String GioiTinh;

    String QueQuan;

    String ChucVu;

    double Luong;

    public Employee(){};

    public Employee(String HoTen,

    String GioiTinh,

    String QueQuan,

    String ChucVu,

    double Luong){

    this.HoTen = HoTen;

    this.GioiTinh= GioiTinh;

    this.ChucVu = ChucVu;

    this.Luong= Luong;

    this.QueQuan=QueQuan;

    };

    public String getHoTen() {

        return HoTen;

    }


    public void setHoTen(String HoTen) {

        this.HoTen = HoTen;

    }


    public String getGioiTinh() {

        return GioiTinh;

    }


    public void setGioiTinh(String GioiTinh) {

        this.GioiTinh = GioiTinh;

    }


    public String getQueQuan() {

        return QueQuan;

    }


    public void setQueQuan(String QueQuan) {

        this.QueQuan = QueQuan;

    }


    public String getChucVu() {

        return ChucVu;

    }


    public void setChucVu(String ChucVu) {

        this.ChucVu = ChucVu;

    }


    public double getLuong() {

        return Luong;

    }


    public void setLuong(double Luong) {

        this.Luong = Luong;

    }

    

    public void input(){

        Scanner input = new Scanner(System.in);

        System.out.print("Nhap Ho va Ten: ");

        HoTen = input.nextLine();

        System.out.print("Nhap Gioi Tinh: ");

        GioiTinh = input.nextLine();

        System.out.print("Nhap Que Quan: ");

        QueQuan = input.nextLine();

        System.out.print("Nhap Chuc Vu: ");

        ChucVu = input.nextLine();

        System.out.print("Nhap Luong : ");

        Luong = double.parseDouble(input.nextLine());

    }

    

    public void output(){

        System.out.println("Ho Va Ten : "+HoTen);

        System.out.println("Gioi Tinh : "+GioiTinh);

        System.out.println("Que Quan : "+QueQuan);

        System.out.println("Chuc Vu : "+ChucVu);

        System.out.println("Luong: "+Luong);

    }

}

public class test {

    public static void main(String[] args) {

     Employee NV1 = new Employee();

        NV1.input();

        Employee NV2 = new Employee("Tran Van A","Nam","Ha Noi","Giam Doc", 20000000);

        NV1.output();

        NV2.output();

    }

}

package bai5.StudentMark;
import java.util.Scanner;
/**
 *
 * @author Admin
 */
public class StudentMark {
    String Rollnumber, HoTen, Lop, MonHoc;
    float Diem;
    public StudentMark(){};
    public StudentMark(String Rollnumber,String HoTen,String Lop,String MonHoc,
                        float Diem){
         this.Rollnumber=  Rollnumber;
         this.HoTen= HoTen;
         this.Lop=Lop;
         this.MonHoc=MonHoc;
         this.Diem= Diem;
    }
    public String getRollnumber(){
        return Rollnumber;
    }
    public void setRollnumber( String Rollnumber){
        this.Rollnumber = Rollnumber;
    }
    public String getHoTen(){
        return HoTen;
    }
    public void setHoTen( String HoTen){
        this.HoTen = HoTen;
    }
    public String getLop(){
        return Lop;
    }
    public void setLop(String Lop){
        this.Lop = Lop;
    }
    public String getMonHoc(){
        return MonHoc;
    }
    public void setMonHoc( String MonHoc){
        this.MonHoc = MonHoc;
    }
    public float getDiem(){
        return Diem;
    }
    public void setDiem( float Diem){
        this.Diem = Diem;
    }
     public void input(){
        Scanner input = new Scanner(System.in);
        System.out.print("Nhap Rollnumber : ");
        Rollnumber = input.nextLine();
        System.out.print("Nhap Ho va Ten: ");
        HoTen = input.nextLine();
        System.out.print("Nhap Lop: ");
        Lop = input.nextLine();
        System.out.print("Nhap Mon Hoc: ");
        MonHoc = input.nextLine();
        System.out.print("Nhap Diem: ");
        Diem = Float.parseFloat(input.nextLine());
        
    }
    
    public void output(){
        System.out.println("Rollnumber: "+Rollnumber);
        System.out.println("Ho Va Ten : "+HoTen);
        System.out.println("Lop : "+Lop);
        System.out.println("Mon Hoc : "+MonHoc);
        System.out.println("Diem : "+Diem);
    }
    public static void main(String[] args) {
     StudentMark Std1 = new StudentMark();
     StudentMark Std2 = new StudentMark();
        Std1.input();
        Std2.input();
        Std1.output();
        Std2.output();
        System.out.println("Nguoi co diem cao nhat la: ");
        if (Std1.Diem>Std2.Diem){
            Std1.output();
        }else{Std2.output();}
    }
}
package bai5.product;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Product {
    String maHH, tenHH;
    float soLuong, gia;
    public Product(){};
     public Product(String maHH, String tenHH,
                    float soLuong, float gia){
        this.maHH=maHH;
        this.tenHH=tenHH;
        this.soLuong=soLuong;
        this.gia=gia;
    };
     public String getmaHH(){
         return maHH;
     }
     public void setmaHH(String maHH){
         this.maHH=maHH;
     }
      public String gettenHH(){
         return tenHH;
     }
     public void settenHH(String tenHH){
         this.tenHH=tenHH;
     }
     public float getsoLuong(){
         return soLuong;
     }
     public void setsoLuong(float soLuong){
         this.soLuong=soLuong;
     }
     public float getgia(){
         return gia;
     }
     public void setgia(float gia){
         this.gia=gia;
     }
     public void input(){
        Scanner input = new Scanner(System.in);
        System.out.print("Nhap Max Hang : ");
        maHH = input.nextLine();
        System.out.print("Nhap ten hang: ");
        tenHH = input.nextLine();
        System.out.print("Nhap so luong: ");
        soLuong = Float.parseFloat(input.nextLine());
        System.out.print("Nhap gia: ");
        gia = Float.parseFloat(input.nextLine());
     }
      public void display(){
        System.out.println("Ma HH: "+maHH);
        System.out.println("Ten HH : "+tenHH);
        System.out.println("So Luong : "+soLuong);
        System.out.println("Gia : "+gia);
      }
      public static void main(String[] args){
          Scanner input = new Scanner(System.in);
           System.out.print("Nhập số luong hang hoa: ");
           int N = Integer.parseInt(input.nextLine());
        
    
}



hoangkhiem [C1907L]
hoangkhiem

2020-03-23 12:00:59



package baitap.battap2332020;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Employee {
    String Name;
    String Gender;
    String Country;
    String Work;
    int Salary;

    public Employee() {
    }

    public Employee (String Name, String Gender, String Country, String Work, int Salary) {
        this.Name = Name;
        this.Gender = Gender;
        this.Country = Country;
        this.Work = Work;
        this.Salary = Salary;
    }

    public String getName() {
        return Name;
    }

    public void setName(String Name) {
        this.Name = Name;
    }

    public String getGender() {
        return Gender;
    }

    public void setGender(String Gender) {
        this.Gender = Gender;
    }

    public String getCountry() {
        return Country;
    }

    public void setCountry(String Country) {
        this.Country = Country;
    }

    public String getWork() {
        return Work;
    }

    public void setWork(String Work) {
        this.Work = Work;
    }

    public int getSalary() {
        return Salary;
    }

    public void setSalary(int Salary) {
        this.Salary = Salary;
    }
    
    public void inputEmployee(){
        Scanner input = new Scanner(System.in);
        System.out.print("Please enter your full name: ");
        Name = input.nextLine();
        System.out.print("Please enter your gender: ");
        Gender = input.nextLine();
        System.out.print("Please enter your Hometown: ");
        Country = input.nextLine();
        System.out.print("Please enter your Position: ");
        Work = input.nextLine();
        System.out.print("Please enter your salary : ");
        Salary = Integer.parseInt(input.nextLine());
    }
    
    public void outputEmployee(){
        System.out.println("His name is : "+Name);
        System.out.println("Gender is : "+Gender);
        System.out.println("Hometown is : "+Country);
        System.out.println("Position is : "+Work);
        System.out.println("Salary is: "+Salary);
    }
}




package baitap.battap2332020;

/**
 *
 * @author Admin
 */
public class Test {
      public static void main(String[] args) {
     Employee Employee1 = new Employee();
        Employee1.inputEmployee();
        Employee Employee2 = new Employee("Hoang Van A","Nam","Ha Noi","Kiem toan",1567890);
        Employee1.outputEmployee();
        Employee2.outputEmployee();
}}



Hoàng Quang Huy [C1907L]
Hoàng Quang Huy

2020-03-22 08:07:45




package Lesson5;

import java.util.*;

public class Employee {

    String name, gender, country, job;
    double salary;

    public Employee() {
    }

    public Employee(String name, String gender, String country, String job, double salary) {
        this.name = name;
        this.gender = gender;
        this.country = country;
        this.job = job;
        this.salary = salary;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getJob() {
        return job;
    }

    public void setJob(String job) {
        this.job = job;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }
    
    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhập họ tên: ");
        name = input.nextLine();
        System.out.println("Giới tính: ");
        gender = input.nextLine();
        System.out.println("Nhập quê quán: ");
        country = input.nextLine();
        System.out.println("Nhập chức vụ: ");
        job = input.nextLine();
        System.out.println("Nhập lương: ");
        salary = Double.parseDouble(input.nextLine());
    }

    public void output() {
        System.out.println("Họ tên: " + name);
        System.out.println("Giới tính: " + gender);
        System.out.println("Quê quán: " + country);
        System.out.println("Chức vụ: " + job);
        System.out.println("Lương: " + salary);
    }
}

package Lesson5;

public class EmployeeTest {
    public static void main(String[] args) {
        Employee emp1;
        Employee emp2 = new Employee();
        emp1 = new Employee("Nguyễn Văn A","Nam","Hà Nội","Nhân viên", 400.0);
        emp2.input();
        emp1.output();
        emp2.output();
    }
}
---------------------------------------------------------------------------------
//Bài 2

package Lesson5;

import java.util.Scanner;

public class StudentMark {
    String rollnumber,name,classname,subject;
    float mark;

    public StudentMark() {
    }

    public StudentMark(String rollnumber, String name, String classname, String subject, float mark) {
        this.rollnumber = rollnumber;
        this.name = name;
        this.classname = classname;
        this.subject = subject;
        this.mark = mark;
    }

    public String getRollnumber() {
        return rollnumber;
    }

    public void setRollnumber(String rollnumber) {
        this.rollnumber = rollnumber;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getClassname() {
        return classname;
    }

    public void setClassname(String classname) {
        this.classname = classname;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public float getMark() {
        return mark;
    }

    public void setMark(float mark) {
        this.mark = mark;
    }
    
    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhập mã sinh viên: ");
        rollnumber = input.nextLine();
        System.out.println("Nhập họ tên: ");
        name = input.nextLine();
        System.out.println("Nhập lớp: ");
        classname = input.nextLine();
        System.out.println("Nhập môn học: ");
        subject = input.nextLine();
        System.out.println("Nhập điểm: ");
        mark = Float.parseFloat(input.nextLine());
    }

    public void output() {
        System.out.println("Mã sinh viên: "+rollnumber);
        System.out.println("Họ tên: " + name);
        System.out.println("Lớp: " + classname);
        System.out.println("Môn học: " + subject);
        System.out.println("Điểm: " + mark);
    }
    public static void main(String[] args) {
        StudentMark std1;
        StudentMark std2 = new StudentMark();
        std1 = new StudentMark("R001","Nguyễn Văn A","C001","Toán", 8);
        std2.input();
        std1.output();
        std2.output();
        System.out.println("Sinh viên có điểm cao nhất là: ");
        if(std1.getMark()>std2.getMark()){
            std1.output();
        }else{
            std2.output();
        }
    }
}

---------------------------------------------------------------------------------
//Bài 3
package Lesson5;

import java.util.*;

public class Product {

    private String productcode, productname;
    private float quantity, price;

    public Product() {
    }

    public Product(String productcode, String productname, float quantity, float price) {
        this.productcode = productcode;
        this.productname = productname;
        this.quantity = quantity;
        this.price = price;
    }

    public String getProductcode() {
        return productcode;
    }

    public void setProductcode(String productcode) {
        this.productcode = productcode;
    }

    public String getProductname() {
        return productname;
    }

    public void setProductname(String productname) {
        this.productname = productname;
    }

    public float getQuantity() {
        return quantity;
    }

    public void setQuantity(float quantity) {
        this.quantity = quantity;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }

    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhập tên hàng hóa: ");
        productname = input.nextLine();
        System.out.println("Nhập mã hàng hóa: ");
        productcode = input.nextLine();
        System.out.println("Nhập số lượng: ");
        quantity = Float.parseFloat(input.nextLine());
        System.out.println("Nhập đơn giá: ");
        price = Float.parseFloat(input.nextLine());
    }

    public void output() {
        System.out.println("Tên hàng hóa: " + productname);
        System.out.println("Mã hàng hóa: " + productcode);
        System.out.println("Số Lượng: " + quantity);
        System.out.println("Đơn giá: " + price);
    }

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhập số lượng hàng hóa: ");
        int n = Integer.parseInt(input.nextLine());
        ArrayList<Product> products = new ArrayList<>();
        float max;
        for (int i = 0; i < n; i++) {
            Product product = new Product();
            System.out.println("Nhập thông tin cho sản phẩm thứ " + (i + 1) + " :");
            product.input();
            products.add(product);
        }
        max = products.get(0).getPrice();
        System.out.println("max = "+max);
        for (int i = 1; i < products.size(); i++) {
            if (products.get(i).getPrice() > max) {
                max = products.get(i).getPrice();
            }
        }
        System.out.println("Danh sách sản phẩm có giá cao nhất là: ");
        for (int i = 0; i < products.size(); i++) {
            if (products.get(i).getPrice() == max) {
                products.get(i).output();
            }
        }
    }
}




trung [C1907L]
trung

2020-03-21 17:45:20



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Buoi5;

import java.util.Scanner;

/**
 *
 * @author prdox
 */
public class Employee {

    String name;
    String gender;
    String homeTown;
    String position;
    double salary;

    public Employee() {
    }

    public Employee(String name, String gender, String homeTown, String position, double salary) {
        this.name = name;
        this.gender = gender;
        this.homeTown = homeTown;
        this.position = position;
        this.salary = salary;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public void setHomeTown(String homeTown) {
        this.homeTown = homeTown;
    }

    public void setPosition(String position) {
        this.position = position;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public String getName() {
        return name;
    }

    public String getGender() {
        return gender;
    }

    public String getHomeTown() {
        return homeTown;
    }

    public String getPosition() {
        return position;
    }

    public double getSalary() {
        return salary;
    }

    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("Name of the employee:");
        this.name = input.nextLine();
        System.out.println("Gender: ");
        this.gender = input.nextLine();
        System.out.println("Home town: ");
        this.homeTown = input.nextLine();
        System.out.println("Position: ");
        this.position = input.nextLine();
        while (true) {
            try {
                System.out.println("Salary: ");
                this.salary = Double.parseDouble(input.nextLine());
                break;
            } catch (Exception e) {
                System.out.println("Invalid input");
            }
        }
    }
    
    public void output(){
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "Employee{" + "name=" + name + ", gender=" + gender + ", homeTown=" + homeTown + ", position=" + position + ", salary=" + salary + '}';
    }

}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Buoi5;

/**
 *
 * @author prdox
 */
public class Test {
//    Khai báo 2 đối tượng của lớp.
//
//    1 đối tượng gọi constructor có tham số. 1 đối tượng gọi constructor không có tham số (phải gọi hàm nhập để lấy thông tin).
//
//    Gọi hàm hiển thị để hiển thị kết quả.
    public static void main(String[] args) {
        Employee emp1 = new Employee("emp1","male","hanoi","boss",100);
        Employee emp2 = new Employee();
        emp2.input();
        emp1.output();
        emp2.output();
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Buoi5;

import java.util.Scanner;

/**
 *
 * @author prdox
 */
public class StudentMark {
    
    String rollNumber;
    String name;
    String sClass;
    String subject;
    float mark;

    public StudentMark() {
    }

    public StudentMark(String rollNumber, String name, String sClass, String subject, float mark) {
        this.rollNumber = rollNumber;
        this.name = name;
        this.sClass = sClass;
        this.subject = subject;
        this.mark = mark;
    }

    public String getRollNumber() {
        return rollNumber;
    }

    public String getName() {
        return name;
    }

    public String getsClass() {
        return sClass;
    }

    public String getSubject() {
        return subject;
    }

    public float getMark() {
        return mark;
    }

    public void setRollNumber(String rollNumber) {
        this.rollNumber = rollNumber;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setsClass(String sClass) {
        this.sClass = sClass;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public void setMark(float mark) {
        this.mark = mark;
    }
    
    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("Roll number:");
        this.rollNumber = input.nextLine();
        System.out.println("Name of student: ");
        this.name = input.nextLine();
        System.out.println("Class: ");
        this.sClass = input.nextLine();
        System.out.println("Subject: ");
        this.subject = input.nextLine();
        while (true) {
            try {
                System.out.println("Mark: ");
                this.mark = Float.parseFloat(input.nextLine());
                break;
            } catch (Exception e) {
                System.out.println("Invalid input");
            }
        }
    }
    
    public void output(){
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "StudentMark{" + "rollNumber=" + rollNumber + ", name=" + name + ", sClass=" + sClass + ", subject=" + subject + ", mark=" + mark + '}';
    }
    
    
    
    public static void main(String[] args) {
        StudentMark stdM1 = new StudentMark();
        StudentMark stdM2 = new StudentMark();
        stdM1.input();
        stdM2.input();
        StudentMark max = (stdM1.getMark() > stdM2.getMark()) ? stdM1 : stdM2;
        max.output();
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Buoi5;

import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author prdox
 */
public class Product {

    private String productCode;
    private String productName;
    private float quantity;
    private float unitPrice;

    public Product() {
    }

    public Product(String productCode, String productName, float quantity, float unitPrice) {
        this.productCode = productCode;
        this.productName = productName;
        this.quantity = quantity;
        this.unitPrice = unitPrice;
    }

    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("Input product code: ");
        this.productCode = input.nextLine();
        System.out.println("Product name: ");
        this.productName = input.nextLine();
        while (true) {
            try {
                System.out.println("Quantity");
                this.quantity = Float.parseFloat(input.nextLine());
                break;
            } catch (Exception e) {
                System.out.println("Invalid input");
            }
        }
        while (true) {
            try {
                System.out.println("Unit price: ");
                this.unitPrice = Float.parseFloat(input.nextLine());
                break;
            } catch (Exception e) {
                System.out.println("Invalid input");
            }
        }
    }

    public void display() {
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "Product{" + "productCode=" + productCode + ", productName=" + productName + ", quantity=" + quantity + ", unitPrice=" + unitPrice + '}';
    }

    public String getProductCode() {
        return productCode;
    }

    public String getProductName() {
        return productName;
    }

    public float getQuantity() {
        return quantity;
    }

    public float getUnitPrice() {
        return unitPrice;
    }

    public void setProductCode(String productCode) {
        this.productCode = productCode;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public void setQuantity(float quantity) {
        this.quantity = quantity;
    }

    public void setUnitPrice(float unitPrice) {
        this.unitPrice = unitPrice;
    }

    public static void main(String[] args) {
//-       Khai báo mảng có n phần tử kiểu Product.
        Scanner input = new Scanner(System.in);
        int n;
        while (true) {
            try {
                System.out.println("Nhap vao so luong phan tu");
                n = Integer.parseInt(input.nextLine());
                break;
            } catch (Exception e) {
                System.out.println("Invalid input");
            }
        }
        ArrayList<Product> products = new ArrayList<>();
//-       Gọi nhập thông tin cho các phần tử của mảng.
        for (int i = 0; i < n; i++) {
            Product product = new Product();
            product.input();
            products.add(product);
        }
//-       Tìm ra sản phẩm nào có giá bán cao nhất.
        Product productMax = products.get(0);
        for (Product product:products){
            if (product.getUnitPrice()>productMax.getUnitPrice()){
                productMax = product;
            }
        }
        System.out.println("Product with highest price is:");
        productMax.display();

    }
}



trung [C1907L]
trung

2020-03-21 17:26:27



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Buoi5;

import java.util.Scanner;

/**
 *
 * @author prdox
 */
public class Employee {

    String name;
    String gender;
    String homeTown;
    String position;
    double salary;

    public Employee() {
    }

    public Employee(String name, String gender, String homeTown, String position, double salary) {
        this.name = name;
        this.gender = gender;
        this.homeTown = homeTown;
        this.position = position;
        this.salary = salary;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public void setHomeTown(String homeTown) {
        this.homeTown = homeTown;
    }

    public void setPosition(String position) {
        this.position = position;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public String getName() {
        return name;
    }

    public String getGender() {
        return gender;
    }

    public String getHomeTown() {
        return homeTown;
    }

    public String getPosition() {
        return position;
    }

    public double getSalary() {
        return salary;
    }

    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("Name of the employee:");
        this.name = input.nextLine();
        System.out.println("Gender: ");
        this.gender = input.nextLine();
        System.out.println("Home town: ");
        this.homeTown = input.nextLine();
        System.out.println("Position: ");
        this.position = input.nextLine();
        while (true) {
            try {
                System.out.println("Salary: ");
                this.salary = Double.parseDouble(input.nextLine());
                break;
            } catch (Exception e) {
                System.out.println("Invalid input");
            }
        }
    }
    
    public void output(){
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "Employee{" + "name=" + name + ", gender=" + gender + ", homeTown=" + homeTown + ", position=" + position + ", salary=" + salary + '}';
    }

}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Buoi5;

/**
 *
 * @author prdox
 */
public class Test {
//    Khai báo 2 đối tượng của lớp.
//
//    1 đối tượng gọi constructor có tham số. 1 đối tượng gọi constructor không có tham số (phải gọi hàm nhập để lấy thông tin).
//
//    Gọi hàm hiển thị để hiển thị kết quả.
    public static void main(String[] args) {
        Employee emp1 = new Employee("emp1","male","hanoi","boss",100);
        Employee emp2 = new Employee();
        emp2.input();
        emp1.output();
        emp2.output();
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Buoi5;

import java.util.Scanner;

/**
 *
 * @author prdox
 */
public class StudentMark {
    
    String rollNumber;
    String name;
    String sClass;
    String subject;
    float mark;

    public StudentMark() {
    }

    public StudentMark(String rollNumber, String name, String sClass, String subject, float mark) {
        this.rollNumber = rollNumber;
        this.name = name;
        this.sClass = sClass;
        this.subject = subject;
        this.mark = mark;
    }

    public String getRollNumber() {
        return rollNumber;
    }

    public String getName() {
        return name;
    }

    public String getsClass() {
        return sClass;
    }

    public String getSubject() {
        return subject;
    }

    public float getMark() {
        return mark;
    }

    public void setRollNumber(String rollNumber) {
        this.rollNumber = rollNumber;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setsClass(String sClass) {
        this.sClass = sClass;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public void setMark(float mark) {
        this.mark = mark;
    }
    
    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("Roll number:");
        this.rollNumber = input.nextLine();
        System.out.println("Name of student: ");
        this.name = input.nextLine();
        System.out.println("Class: ");
        this.sClass = input.nextLine();
        System.out.println("Subject: ");
        this.subject = input.nextLine();
        while (true) {
            try {
                System.out.println("Mark: ");
                this.mark = Float.parseFloat(input.nextLine());
                break;
            } catch (Exception e) {
                System.out.println("Invalid input");
            }
        }
    }
    
    public void output(){
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "StudentMark{" + "rollNumber=" + rollNumber + ", name=" + name + ", sClass=" + sClass + ", subject=" + subject + ", mark=" + mark + '}';
    }
    
    
    
    public static void main(String[] args) {
        StudentMark stdM1 = new StudentMark();
        StudentMark stdM2 = new StudentMark();
        stdM1.input();
        stdM2.input();
        StudentMark max = (stdM1.getMark() > stdM2.getMark()) ? stdM1 : stdM2;
        max.output();
    }
}



trung [C1907L]
trung

2020-03-21 17:16:51



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Buoi5;

import java.util.Scanner;

/**
 *
 * @author prdox
 */
public class Employee {

    String name;
    String gender;
    String homeTown;
    String position;
    double salary;

    public Employee() {
    }

    public Employee(String name, String gender, String homeTown, String position, double salary) {
        this.name = name;
        this.gender = gender;
        this.homeTown = homeTown;
        this.position = position;
        this.salary = salary;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public void setHomeTown(String homeTown) {
        this.homeTown = homeTown;
    }

    public void setPosition(String position) {
        this.position = position;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public String getName() {
        return name;
    }

    public String getGender() {
        return gender;
    }

    public String getHomeTown() {
        return homeTown;
    }

    public String getPosition() {
        return position;
    }

    public double getSalary() {
        return salary;
    }

    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("Name of the employee:");
        this.name = input.nextLine();
        System.out.println("Gender: ");
        this.gender = input.nextLine();
        System.out.println("Home town: ");
        this.homeTown = input.nextLine();
        System.out.println("Position: ");
        this.position = input.nextLine();
        while (true) {
            try {
                System.out.println("Salary: ");
                this.salary = Double.parseDouble(input.nextLine());
                break;
            } catch (Exception e) {
                System.out.println("Invalid input");
            }
        }
    }
    
    public void output(){
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "Employee{" + "name=" + name + ", gender=" + gender + ", homeTown=" + homeTown + ", position=" + position + ", salary=" + salary + '}';
    }

}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Buoi5;

/**
 *
 * @author prdox
 */
public class Test {
//    Khai báo 2 đối tượng của lớp.
//
//    1 đối tượng gọi constructor có tham số. 1 đối tượng gọi constructor không có tham số (phải gọi hàm nhập để lấy thông tin).
//
//    Gọi hàm hiển thị để hiển thị kết quả.
    public static void main(String[] args) {
        Employee emp1 = new Employee("emp1","male","hanoi","boss",100);
        Employee emp2 = new Employee();
        emp2.input();
        emp1.output();
        emp2.output();
    }
}