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 ex3;
- import java.io.InputStream;
- import java.util.Scanner;
- /**
- *
- * @author Toan Tran
- */
- public class Ex3 {
- /**
- * @param args the command line arguments
- */
- // tao 1 class Product
- public static class Product {
- double Price;
- String ID, Name, Company, Color;
- public Product(){
- }
- public Product(String id, String name, String company, String color, double price)
- {
- ID = id;
- Name = name;
- Company = company;
- Color = color;
- Price = price;
- }
- public String getID() {
- return ID;
- }
- public void setID(String x) {
- ID = x;
- }
- public String getName() {
- return Name;
- }
- public void setName(String s) {
- Name = s;
- }
- public String getCompany() {
- return Company;
- }
- public void setCompany(String s) {
- Company = s;
- }
- public String getColor() {
- return Color;
- }
- public void setColor(String s) {
- Color = s;
- }
- public double getPrice() {
- return Price;
- }
- public void setPrice(double s) {
- Price = s;
- }
- public double calDiscount(){
- return Price * 0.08;
- }
- }
- public static void main(String[] args) {
- // TODO code application logic here
- // System.out.print("Hello world");
- // Product product = new Product(1,"SH 2020", "Honda", "RED", 100000);
- // System.out.println(product.getCompany());
- int n;
- System.out.println("Nhap so san pham");
- Scanner sc = new Scanner(System.in);
- n = sc.nextInt();
- Product []product = new Product[n];
- // Nhap n san pham
- for (int i = 0; i < n; i++) {
- // ID, Name, Company, Color, Price
- product[i] = new Product();
- //InputStream.skip();
- sc.nextLine();
- // sc nexline de xoa bo nho cache (phien ban 2 cua cin.inorge() in c++ xD ??? :D)
- System.out.println("San pham thu " + (i+1));
- System.out.print("ID = ");
- product[i].setID(sc.nextLine());
- System.out.print("Name = ");
- product[i].setName(sc.nextLine());
- System.out.print("Company = ");
- product[i].setCompany(sc.nextLine());
- System.out.print("Color = ");
- product[i].setColor(sc.nextLine());
- System.out.print("Price = ");
- product[i].setPrice(sc.nextDouble());
- }
- // in so luong san pham
- for (int i = 0; i < n; i++)
- {
- String color = product[i].getColor();
- if ("RED".equals(color) || "BLUE".equals(color))
- {
- System.out.println("Thong tin san pham thu " + (i+1));
- System.out.println("ID = " + product[i].getID());
- System.out.println("Name = " + product[i].getName());
- System.out.println("Company = " + product[i].getCompany());
- System.out.println("Color = " + color);
- System.out.println("Price = " + product[i].getPrice());
- }
- }
- // end code
- // how to run file: ctrl a - >> then click right mouse run file or shift f6
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement