Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Question at end of post) I have the java code: public class ProcessOrder { publ

ID: 3753926 • Letter: #

Question

(Question at end of post) I have the java code:

public class ProcessOrder {
public static void ProcessOrder(String[] args) {
try {
Scanner infile = new Scanner(new File("orders.dat"));
while(infile.hasNext()){
Order ord = new Order();
ord.setOrderID(infile.next());
ord.setSize(infile.next().charAt(0));
ord.setType(infile.next());
ord.setPrice(infile.nextFloat());
ord.setQuantity(infile.nextInt());
//now process order

float graphicsFactor = 0;
float ounceFactor = 0;
float typeFactor = 0;
float priceDrink = 0;
float drinkPrice = 0;
float priceGraphics = 0;
float orderPrice = 0;

switch (ord.getSize()) {
case 'S':
ounceFactor = (float)12;
graphicsFactor = (float)57;
break;
case 'M':
ounceFactor = (float)20;
graphicsFactor = (float)81;
break;
case 'L':
ounceFactor = (float)32;
graphicsFactor = (float)110;
break;
}

switch (ord.getType()) {
case "soda":
typeFactor = (float).2;
break;
case "tea":
typeFactor = (float).12;
break;
case "punch":
typeFactor = (float).15;
break;
  
}

priceDrink = ounceFactor * typeFactor;
priceGraphics = graphicsFactor * ord.getPrice();
drinkPrice = priceDrink + priceGraphics;
orderPrice = drinkPrice * ord.getQuantity();

/*
THIS IS WHERE I WOULD APPLY A DISCOUNT if ord.getOrderID matches with a ID in the PreferredCustomer Array

*/

}
infile.close();
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
}
}
}

------------------------

public class Customer {

String id;

String fname, lname;

float moneySpent;

public Customer(String id, String fname, String lname, float moneySpent){

this.id = id;

this.fname = fname;

this.lname = lname;

this.moneySpent = moneySpent;

}

}

------------------------

public class PreferredCustomer extends Customer {

float discount;

public PreferredCustomer(String id, String fname, String lname, float moneySpent,float discount) {

super(id, fname, lname, moneySpent);


this.discount=discount;

}

}

-------------------

public class Main {

public Main() {

// TODO Auto-generated constructor stub

}

public static void main(String[] args) {

ArrayList customer = new ArrayList<>();

ArrayList preferredCustomer=new ArrayList<>();

try (Scanner scanner = new Scanner(new FileInputStream("user.dat"));) {

while (scanner.hasNextLine()) {

String id = scanner.next();

String fname = scanner.next();

String lname = scanner.next();

float money = scanner.nextFloat();

float discount=scanner.nextFloat();

scanner.nextLine(); // clears newlines from the buffer

Customer u = new Customer(id, fname, lname, money);

customer.add(u);

PreferredCustomer pc=new PreferredCustomer(lname, lname, lname, money, discount);
discount=Float.parseFloat(PreferredCustomer(discount).replace("%",""));

preferredCustomer.add(pc);

}

} catch (IOException e) {

System.out.println("File not found");

}

}

}

//////////////////////////////////////////////////////////////////////////////////////////////////////

How do I make a switch case that seperates orders where

case ord.setOrderID = PreferredCustomerID {

/*

do this

*/

}

case ord.setOrderID = CustomerID

(

/*

do something else

*/

}

Explanation / Answer

In Java programing expression return type must be char, byte, short, int, Character, Byte, Short, Integer, String, constant Value for SWITCH CASE.

But Relational operators (<,<=,>,>=) results in boolean and which is not allowded

//////////////////////////////////////////////////////////////////////////////////////////////////////

// Possible solution if getter method for all varialbe present in Order class then we can call getOrderID() method to get order ID.

int ID = ord.getOrderID();

switch(ID){

case CustomerID :

break;

case PreferredCustomerID :

// Apply discount Code

break;

}