Advertisement
toantranct

W1_E3

May 9th, 2021
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.72 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 ex3;
  7.  
  8. import java.io.InputStream;
  9. import java.util.Scanner;
  10.  
  11. /**
  12.  *
  13.  * @author Toan Tran
  14.  */
  15. public class Ex3 {
  16.  
  17.     /**
  18.      * @param args the command line arguments
  19.      */
  20.    // tao 1 class Product
  21.     public static class Product {
  22.         double Price;
  23.         String ID, Name, Company, Color;
  24.         public Product(){
  25.            
  26.         }
  27.         public Product(String id, String name, String company, String color, double price)
  28.         {
  29.         ID = id;
  30.         Name = name;
  31.         Company = company;
  32.         Color = color;
  33.         Price = price;
  34.         }
  35.         public String getID() {
  36.             return ID;
  37.         }
  38.         public void setID(String x) {
  39.             ID = x;
  40.         }
  41.         public String getName() {
  42.             return Name;
  43.         }
  44.         public void setName(String s) {
  45.             Name = s;
  46.         }
  47.           public String getCompany() {
  48.             return Company;
  49.         }
  50.         public void setCompany(String s) {
  51.             Company = s;
  52.         }
  53.           public String getColor() {
  54.             return Color;
  55.         }
  56.         public void setColor(String s) {
  57.             Color = s;
  58.         }
  59.           public double getPrice() {
  60.             return Price;
  61.         }
  62.         public void setPrice(double s) {
  63.             Price = s;
  64.         }
  65.         public double calDiscount(){
  66.             return Price * 0.08;
  67.         }
  68.     }
  69.    
  70.     public static void main(String[] args) {
  71.         // TODO code application logic here
  72. //        System.out.print("Hello world");
  73. //      Product product = new Product(1,"SH 2020", "Honda", "RED", 100000);
  74. //      System.out.println(product.getCompany());
  75.         int n;
  76.         System.out.println("Nhap so san pham");
  77.         Scanner sc = new Scanner(System.in);
  78.         n = sc.nextInt();
  79.         Product []product = new Product[n];
  80.         // Nhap n san pham
  81.        
  82.         for (int i = 0; i < n; i++) {
  83.              // ID, Name, Company, Color, Price
  84.              product[i] = new Product();
  85.              //InputStream.skip();    
  86.              sc.nextLine();
  87.              // sc nexline de xoa bo nho cache (phien ban 2 cua cin.inorge() in c++ xD ??? :D)
  88.              System.out.println("San pham thu " + (i+1));
  89.              System.out.print("ID = ");
  90.              product[i].setID(sc.nextLine());
  91.        
  92.              
  93.              System.out.print("Name = ");
  94.              product[i].setName(sc.nextLine());
  95.              
  96.              System.out.print("Company = ");
  97.              product[i].setCompany(sc.nextLine());
  98.              
  99.              System.out.print("Color = ");
  100.              product[i].setColor(sc.nextLine());
  101.              
  102.              System.out.print("Price = ");
  103.              product[i].setPrice(sc.nextDouble());
  104.             }
  105.         // in so luong san pham
  106.        
  107.         for (int i = 0; i < n; i++)              
  108.         {
  109.          String color = product[i].getColor();
  110.          if ("RED".equals(color) || "BLUE".equals(color))
  111.          {
  112.               System.out.println("Thong tin san pham thu " + (i+1));
  113.               System.out.println("ID = " + product[i].getID());
  114.               System.out.println("Name = " + product[i].getName());
  115.               System.out.println("Company = " + product[i].getCompany());
  116.               System.out.println("Color = " + color);
  117.               System.out.println("Price = " + product[i].getPrice());
  118.          }
  119.              
  120.         }
  121.  
  122.     // end code
  123.     // how to run file: ctrl a - >> then click right mouse run file or shift f6
  124. }
  125. }
  126.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement