Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package polimorfismo.application;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- import polimorfismo.entities.*;
- public class Program {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.print("Enter the number of products: ");
- String name = null, manuDate = null;
- double price = 0.0, alfTax = 0.0;
- int n = sc.nextInt();
- Product com = new Product(name, price);
- UsedProduct used = new UsedProduct(name, price, manuDate);
- ImportedProduct imp = new ImportedProduct(name, price, alfTax);
- List<Product> prod = new ArrayList<>();
- for(int i = 1; i <= n; i++) {
- System.out.print("Product #" + i + " data:");
- System.out.println("Common, used or imported (c/u/i)? ");
- char answer = sc.next().charAt(0);
- sc.nextLine();
- System.out.print("Name: ");
- name = sc.nextLine();
- System.out.print("Price: ");
- price = sc.nextDouble();
- sc.nextLine();
- if (answer == 'c') {
- prod.add(com);
- }
- else if (answer == 'u') {
- System.out.print("Manufacture date (DD/MM/YY): ");
- manuDate = sc.nextLine();
- prod.add(used);
- }
- else if (answer == 'i') {
- System.out.print("Customs fee: ");
- alfTax = sc.nextDouble();
- prod.add(imp);
- } else {
- System.out.print("Your answer's invalid, please try again.");
- }
- }
- System.out.println("PRICE TAGS:");
- for (Product x : prod) {
- System.out.println(com);
- System.out.println(used);
- System.out.println(imp);
- }
- sc.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement