Advertisement
Guest User

hue

a guest
May 22nd, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.50 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package aptech;
  7.  
  8. /**
  9.  *
  10.  * @author a1205m_nvlhai
  11.  */
  12. import java.util.*;
  13.  
  14. public class AptechElectronic {
  15.     ArrayList al = new ArrayList();
  16.    
  17.     void inputList(){
  18.        
  19.         int cnt = 0;
  20.         do{
  21.             productManager pm = new productManager();
  22.             pm.inputCode();
  23.             if(pm.getCode() == 1) return;
  24.             pm.inputName();
  25.             pm.inputPrice();
  26.             al.add(pm);
  27.             cnt ++;
  28.         }while(cnt!= 10 );
  29.     }
  30.  
  31.     void displayList(){
  32.         System.out.printf("%-7s%-15s%-5s\n", "Code", "Name", "Price");
  33.         for(int i = 0; i < al.size();i++){
  34.             productManager p = (productManager)al.get(i);
  35.             System.out.printf("%-7d%-15s%-5d\n", p.getCode(), p.getName(), p.getPrice());
  36.         }
  37.         displayHigh();
  38.     }
  39.    
  40.     void displayHigh(){
  41.         productManager p = (productManager)al.get(0);
  42.         int highestPrice = p.getPrice();
  43.         String highestName = null;
  44.        
  45.         for(int i = 1; i < al.size();i++){
  46.             productManager test = (productManager)al.get(i);
  47.             if(test.getPrice() > highestPrice)
  48.                 highestPrice = test.getPrice();
  49.         }
  50.        
  51.         for(int i = 0; i < al.size() ; i++){
  52.             productManager test = (productManager)al.get(i);
  53.             if(test.getPrice() == highestPrice)
  54.                 highestName = test.getName();
  55.         }
  56.        
  57.         System.out.println("The highest price product : " + highestName + " : " +highestPrice );
  58.     }
  59.    
  60.     void displayMin(){
  61.        
  62.     }
  63.    
  64.     public static void main(String[] args) {
  65.         int choice;
  66.         Scanner sc = new Scanner(System.in);
  67.         AptechElectronic ae = new AptechElectronic();
  68.         do {
  69.         System.out.println("1.Enter Products.");
  70.         System.out.println("2.Display list of products.");
  71.         System.out.println("3.Search products.");
  72.         System.out.println("4.Quit.");
  73.         choice = sc.nextInt();      
  74.             switch (choice) {
  75.                 case 1:
  76.                     ae.inputList();
  77.                     break;
  78.                 case 2:
  79.                     ae.displayList();
  80.                     break;
  81.                 case 3:
  82.                     System.out.println("HUE");
  83.                     break;
  84.                 case 4:
  85.                     System.out.println("THOAT");
  86.                     return;
  87.                 default:
  88.                     System.out.println("NHAP LAI.");
  89.             }
  90.         } while (choice != 4);
  91.     }
  92. }
  93.  
  94. class productManager{
  95.     private int Code;
  96.     private String Name;
  97.     private int Price;
  98.    
  99.     void inputCode(){
  100.         Scanner sc = new Scanner(System.in);
  101.         System.out.print("Nhap Code : ");
  102.         Code = sc.nextInt();
  103.         sc.nextLine();
  104.     }
  105.    
  106.     void inputName(){
  107.         Scanner sc = new Scanner(System.in);
  108.         System.out.print("Nhap Name : ");
  109.         Name = sc.nextLine();
  110.     }
  111.    
  112.     void inputPrice(){
  113.         Scanner sc = new Scanner(System.in);
  114.         System.out.print("Nhap Price : ");
  115.         Price = sc.nextInt();
  116.         sc.nextLine();
  117.     }
  118.  
  119.     public int getCode() {
  120.         return Code;
  121.     }
  122.  
  123.     public String getName() {
  124.         return Name;
  125.     }
  126.  
  127.     public int getPrice() {
  128.         return Price;
  129.     }
  130.    
  131.        
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement