Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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 aptech;
- /**
- *
- * @author a1205m_nvlhai
- */
- import java.util.*;
- public class AptechElectronic {
- ArrayList al = new ArrayList();
- void inputList(){
- int cnt = 0;
- do{
- productManager pm = new productManager();
- pm.inputCode();
- if(pm.getCode() == 1) return;
- pm.inputName();
- pm.inputPrice();
- al.add(pm);
- cnt ++;
- }while(cnt!= 10 );
- }
- void displayList(){
- System.out.printf("%-7s%-15s%-5s\n", "Code", "Name", "Price");
- for(int i = 0; i < al.size();i++){
- productManager p = (productManager)al.get(i);
- System.out.printf("%-7d%-15s%-5d\n", p.getCode(), p.getName(), p.getPrice());
- }
- displayHigh();
- }
- void displayHigh(){
- productManager p = (productManager)al.get(0);
- int highestPrice = p.getPrice();
- String highestName = null;
- for(int i = 1; i < al.size();i++){
- productManager test = (productManager)al.get(i);
- if(test.getPrice() > highestPrice)
- highestPrice = test.getPrice();
- }
- for(int i = 0; i < al.size() ; i++){
- productManager test = (productManager)al.get(i);
- if(test.getPrice() == highestPrice)
- highestName = test.getName();
- }
- System.out.println("The highest price product : " + highestName + " : " +highestPrice );
- }
- void displayMin(){
- }
- public static void main(String[] args) {
- int choice;
- Scanner sc = new Scanner(System.in);
- AptechElectronic ae = new AptechElectronic();
- do {
- System.out.println("1.Enter Products.");
- System.out.println("2.Display list of products.");
- System.out.println("3.Search products.");
- System.out.println("4.Quit.");
- choice = sc.nextInt();
- switch (choice) {
- case 1:
- ae.inputList();
- break;
- case 2:
- ae.displayList();
- break;
- case 3:
- System.out.println("HUE");
- break;
- case 4:
- System.out.println("THOAT");
- return;
- default:
- System.out.println("NHAP LAI.");
- }
- } while (choice != 4);
- }
- }
- class productManager{
- private int Code;
- private String Name;
- private int Price;
- void inputCode(){
- Scanner sc = new Scanner(System.in);
- System.out.print("Nhap Code : ");
- Code = sc.nextInt();
- sc.nextLine();
- }
- void inputName(){
- Scanner sc = new Scanner(System.in);
- System.out.print("Nhap Name : ");
- Name = sc.nextLine();
- }
- void inputPrice(){
- Scanner sc = new Scanner(System.in);
- System.out.print("Nhap Price : ");
- Price = sc.nextInt();
- sc.nextLine();
- }
- public int getCode() {
- return Code;
- }
- public String getName() {
- return Name;
- }
- public int getPrice() {
- return Price;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement