daily pastebin goal
63%
SHARE
TWEET

Program.java

a guest Mar 25th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package polimorfismo.application;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Scanner;
  6.  
  7. import polimorfismo.entities.*;
  8.  
  9. public class Program {
  10.    
  11.     public static void main(String[] args) {
  12.        
  13.         Scanner sc = new Scanner(System.in);
  14.         System.out.print("Enter the number of products: ");
  15.         String name = null, manuDate = null;
  16.         double price = 0.0, alfTax = 0.0;
  17.         int n = sc.nextInt();
  18.        
  19.         Product com = new Product(name, price);
  20.         UsedProduct used = new UsedProduct(name, price, manuDate);
  21.         ImportedProduct imp = new ImportedProduct(name, price, alfTax);
  22.        
  23.         List<Product> prod = new ArrayList<>();
  24.        
  25.         for(int i = 1; i <= n; i++) {
  26.             System.out.print("Product #" + i + " data:");
  27.             System.out.println("Common, used or imported (c/u/i)? ");
  28.             char answer = sc.next().charAt(0);
  29.             sc.nextLine();
  30.             System.out.print("Name: ");
  31.             name = sc.nextLine();
  32.             System.out.print("Price: ");
  33.             price = sc.nextDouble();
  34.             sc.nextLine();
  35.             if (answer == 'c') {
  36.                 prod.add(com);
  37.             }
  38.             else if (answer == 'u') {
  39.                 System.out.print("Manufacture date (DD/MM/YY): ");
  40.                 manuDate = sc.nextLine();
  41.                 prod.add(used);
  42.                
  43.             }
  44.             else if (answer == 'i') {
  45.                 System.out.print("Customs fee: ");
  46.                 alfTax = sc.nextDouble();
  47.                 prod.add(imp);
  48.             } else {
  49.                 System.out.print("Your answer's invalid, please try again.");
  50.             }
  51.         }
  52.        
  53.         System.out.println("PRICE TAGS:");
  54.         for (Product x : prod) {
  55.             System.out.println(com);
  56.             System.out.println(used);
  57.             System.out.println(imp);
  58.         }
  59.        
  60.         sc.close();
  61.     }
  62.  
  63. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top