I'm trying to read a data file like this:
N 1000.0 NY R 2000.0 CA 0.09 R 500.0 GA 0.07 N 2000.0 WY O 3000.0 Japan 0.11 20.0 N 555.50 CA O 3300.0 Ecuador 0.03 30.0 R 600.0 NC 0.06
and use it to fill an arrayList
My program consists of a abstract class and three classes to implement it:
1. NonProfitOrder
public class NonProfitOrder extends Order {
public NonProfitOrder(double price, String location) {
super(price, location);
}
public double calculateBill() {
return getPrice();
}
public String printOrder(String format){
String Long = "Non-Profit Order" + "\nLocation: " + getLocation() + "\nTotal Price: " + getPrice();
String Short = "Non-Profit Order-Location: " + getLocation() + ", " + "Total Price: " + getPrice();
if (format.equals("Long")){
return Long;
}
else{
return Short;
}
}
}
2. RegularOrder
public class RegularOrder extends Order {
double taxRate;
public RegularOrder(double price, String location, double taxRate) {
super(price, location);
this.taxRate = taxRate;
}
private double calcTax() {
double tax;
tax = getPrice() * taxRate;
return tax;
}
public double calculateBill() {
double bill;
bill = price + calcTax();
return bill;
}
public String printOrder(String format){
String Long = "Regular Order" + "\nLocation: " + getLocation() + "\nPrice: " + getPrice() +
"\nTax: " + calcTax() + "\nTotal Price: " + calculateBill();
String Short = "Regular Order-Location: " + getLocation() + ", " + "Total Price: " + calculateBill();
if (format.equals("Long")){
return Long;
}
else{
return Short;
}
}
}
and another very similar to RegularOrder
My problem comes in my main. I have to use a method readOrders(fileName:string):ArrayList<Order>
public static ArrayList<Order> readOrders (String fileName) throws FileNotFoundException{
String type;
Scanner s = new Scanner(new File("orders.txt"));
ArrayList<Order> orders = new ArrayList<Order>();
while (s.hasNext()){
type = s.nextLine();
}
switch(type) {
case 1: type = NonProfitOrder();
break;
case 2: type = RegularOrder();
break;
case 3: type = OverseasOrder();
return orders;
}
}
I can't figure out how to do this properly as it still says
readOrders can't be resolved to a type.
As well as other issues with the first readOrders
.
I updated my code with somewhat of a switch state, that doesn't work of. Instead of case 1,2,3 should I be using N,O,R or how would I refer to each type of order? Also I'm having "type mismatch" error but I'm having trouble fixing it.