guys, estou fazendo um exercício do curso, porem realizei o mesmo mas a minha data não funciona. já consultei o código do professor e nada. segue o meu código e o exemplo do exercício.
package application;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Scanner;
import entities.ImportedProduct;
import entities.Product;
import entities.UsedProduct;
public class Program {
public static void main(String[]arg) throws ParseException {
Locale.setDefault(Locale.US);
Scanner sc = new Scanner(System.in);
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy)");
List <Product> list = new ArrayList<>();
System.out.print("Enter the number of products: ");
int numberProducts = sc.nextInt();
for (int i = 1; i <= numberProducts; i++) {
System.out.print("Common, used or imported (c/u/i)? ");
char option = sc.next().charAt(0);
sc.nextLine();
System.out.print("Name: ");
String name = sc.nextLine();
System.out.println("Price: ");
double price = sc.nextDouble();
if (option == 'u') {
System.out.print("Manufacture date (DD/MM/YYYY): ");
Date date = sdf.parse(sc.next());
Product pro2 = new UsedProduct(name, price,date);
list.add(pro2);
}
else if (option == 'i') {
System.out.print("custom fee: ");
double customFee = sc.nextDouble();
Product pro = new ImportedProduct(name, price, customFee);
list.add(pro);
}
else if (option == 'c') {
Product pro1 = new Product(name, price);
list.add(pro1);
}
}
System.out.println();
System.out.println("Price tags");
for(Product pro : list) {
System.out.println(pro.priceTag());
}
sc.close();
}
}
package entities;
import java.text.SimpleDateFormat;
import java.util.Date;
public class UsedProduct extends Product {
private static final SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy)");
private Date manufactureDate;
public UsedProduct(String name, double price, Date manufactureDate) {
super(name, price);
this.manufactureDate = manufactureDate;
}
public Date getManufactureDate() {
return manufactureDate;
}
public void setManufactureDate(Date manufactureDate) {
this.manufactureDate = manufactureDate;
}
@Override
public String priceTag() {
return getName() + " USed" + String.format("%.2f", getPrice()) + " (Manufacture date: " + sdf.format(manufactureDate) + " )";
}
}