My question is : [B]Modify the programme that can calculate total sales of the day, total wholesaler(s), total retailer(s). The user will need to enter 'E' for customer type to the stop the program/B]
How do I execute the program right away at the first prompt-user(type of customer) without entering input for the second one (no. of units)?
import java.util.Scanner;
public class MarinePackingCompany02
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("INSTRUCTIONS; Enter a code based on type of customer, enter E to quit");
System.out.println("eg. Wholesaler ==> w");
System.out.println(" Retailer ==> r");
System.out.println(" ");
System.out.print("Enter code : ");
String customer = sc.next();
System.out.print("Enter no. of unit(s) : ");
int unit = sc.nextInt();
double price=0, total=0;
int w=0, r=0;
while (!customer.equals("E"))
{
if (customer.equals("w"))
{
w = w + 1;
if (unit >= 5)
price = 9*unit;
else
price = 10*unit;
}
else if (customer.equals("r"))
{
r = r + 1;
if (unit <= 3)
price = 15*unit;
else if (unit <= 8)
price = 14*unit;
else
price = 12*unit;
}
else
System.out.println("Invalid code entered");
total = total + price;
System.out.println(" ");
System.out.print("Enter code : ");
customer = sc.next();
System.out.print("Enter no. of unit(s) : ");
unit = sc.nextInt();
}
System.out.println("Total sales of the day = RM" + String.format("%.2f",total));
System.out.println("Total wholesaler(s) : " + w);
System.out.println("Total retailer(s) : " + r);
}
}