my instructions on the project were as followed or here is a link to a more detailed instruction page of the assignment (https://imgur.com/a/m8KDeaY):
Use a sentinel value loop. To create a Rental Car Calculator
Ask each user for:
Type of vehicle, if the fuel tank is full, Days rented. Then Calculate the Rental cost, Taxes and, fuel charge (For each customer). [NOTE: May use something other than strings, such as 1 for an economy, 2 for a sedan, etc.]
There are six different rental options with separate DAILY & WEEKLY rates. Daily rates: Economy @ 31.76, sedan @ 40.32, SUV @ 47.56. Weekly rates: Economy @ 158.80, sedan @ 201.60, SUV @ 237.80. [NOTE: all weekly rates are 5 times the daily rates. You may use a constant, or just calculate this off the daily rental fee]
Sales tax is = to 6% on the TOTAL.
Display after each full Calculator entry: The fuel charge, subtotal, rental cost, taxes and, grand total.
Display summary data when the program exits with:
The total number of customers, Total money collected, total fuel charges. total taxes and, the average bill. Also, Include IPO, algorithm, and desk check values (design documents).
{WHAT I HAVE GOING ON SO FAR}
package tests;
import java.util.InputMismatchException;
import java.util.Scanner;
public class Tester {
public static void main(String []args){
int days, cus, carType, fuel, count=0;
double dailyFee=0, nonTaxTotal=0, total=0, fullTotal=0, fuelcharge=0, taxes=0, avrg=0;
boolean checkRunOrQuit = false, chooseTypeVehicle = false, numberOfDAysChosen = false, fuellevel = false;
Scanner in=new Scanner(System.in);
while ( checkRunOrQuit = false ) {
System.out.print("Press 1 to enter Rental Calculator or else press 0 to quit\n");
System.out.println("Please only enter 1 or 0. Also, please only enter number(s) not letter(s)");
try {
cus=in.nextInt();
switch ( cus ) {
case 0: System.out.print("End of application\n");
System.out.println("Count of customers: " + count);
System.out.printf("Total of the Day: $ %.2f \n", fullTotal);
System.out.printf("Subtotal: $ %.2f \n", nonTaxTotal);
System.out.printf("Total taxes collected: $ %.2f \n", taxes);
System.out.printf("The average bill was: $ %.2f \n", avrg);
System.exit(0);
break;
case 1: checkRunOrQuit = true;
break;
default:
System.out.println("Number must be either 1 or 0");
}
} catch (InputMismatchException ex) {
System.out.println("Invalid entry: ");
in.next();
}
}
Pleasebaby: while( !chooseTypeVehicle ) { // --> simplified comparison
count++;
System.out.print("What vehical would you like to rent?\n");
System.out.println("Enter 1 for an economy car");
System.out.println("Enter 2 for a sedan car");
System.out.println("Enter 3 for an SUV");
try {
carType = in.nextInt();
chooseTypeVehicle = true;
switch ( carType ) {
case 1: dailyFee = 31.76;
break;
case 2: dailyFee = 40.32;
break;
case 3: dailyFee = 47.56;
break;
default:
System.out.print("Number must be 1-3\n");
chooseTypeVehicle = false;
break;
}
} catch (InputMismatchException ex) {
System.out.println("Answer must be a number");
in.next();
}
}
while ( !fuellevel ) {
try {
System.out.print("Is the fuel empty?\n");
System.out.println("Please enter 1 for yes.");
System.out.println("Please enter 2 for no.");
fuel = in.nextInt();
if (fuel <= 0 |fuel > 2.1) {
System.out.print("Please enter a 1 or 2\n");
} else {
fuellevel = true;
switch ( fuel ) {
case 1: fuelcharge = 40.00;
break;
case 2: fuelcharge = 0.00;
break;
}
}} catch (InputMismatchException ex) {
System.out.println("Answer must be a number");
in.next();
}
}
while ( !numberOfDAysChosen ) {
try {
System.out.print("Please enter the number of days rented. (Example; 3) : ");
days = in.nextInt();
if (days <= 0) {
System.out.println("Number of days must be more than zero");
} else {
nonTaxTotal = (dailyFee * days);
nonTaxTotal = (nonTaxTotal + fuelcharge);
total = (nonTaxTotal * 1.06);
taxes = (total - nonTaxTotal);
avrg = ( total/count );
fullTotal+=total;
numberOfDAysChosen = true;
}
} catch(InputMismatchException ex) {
System.out.println("Answer must be a number");
in.next();
}
}
System.out.print("Press 1 to enter Rental Calculator or else press 0 to quit\n");
System.out.println("Please only enter 1 or 0. Also, please only enter number(s) not letter(s)");
try {
cus=in.nextInt();
switch ( cus ) {
case 0: System.out.print("End of application. \n");
System.out.println("Count of customers: " + count);
System.out.printf("Total of the Day: $ %.2f \n", fullTotal);
System.out.printf("Subtotal: $ %.2f \n", nonTaxTotal);
System.out.printf("Total taxes collected: $ %.2f \n", taxes);
System.out.printf("The average bill was: $ %.2f \n", avrg);
System.exit(0);
break;
case 1:
break Pleasebaby;
default:
System.out.println("Number must be either 1 or 0");
}
} catch (InputMismatchException ex) {
System.out.println("Invalid entry: ");
in.next();
}
in.close();
System.out.println("Count of customers : " + count );
System.out.printf("total of the Day : $%.2f \n", fullTotal);
System.out.printf("total taxes collected : $%.2f ", taxes);
}
}
{Questions}
-
I was attempting to
break Pleasebaby
in order to loop my entire calculator again if "1" was entered. but it prompts that the label does not exist? -
would anyone be able to help me with the differences between my TOTAL summary data and summary data per user? It seems I have only created the TOTAL summary data and I'm unsure where to start to just make a total per user.
-
im bad at math is there any thoughts on how I can setup my weekly rates? without messing up my total/summary info?
Aucun commentaire:
Enregistrer un commentaire