Develop a functional flowchart and then write a menu-driven Java program, using
ID: 3627008 • Letter: D
Question
Develop a functional flowchart and then write a menu-driven Java program, using control constructs and user-defined functions, to solve for the following problem.( Delclare the parking fee schedule in const variables.)
The sign on the attendant's booth at WCCC parking lot is:
WCCC Vistors Parking(underlined)
Cars: First 1 Hour: Free
Next 2 Hours: $2.00 per hour
Next 5 Hours: $1.00 per hour
Thereafter: $0.50 per hour(more than 8 hours)
Motorcycles: First 1 Hour: $1.00
Next 5 Hours: $0.50 per hour
Next 8 Hours: $0.25 per hour
Thereafter: $0.10 per hour (more than 14 hours)
Senior Cititzens: Free
Upon execution of the program, the screen will be cleared and the following menu will appear at the top of the screen, properly centered:
Help Cars Motorcycles Senior Cititzens Quit
H or h (for Help) option will briefly explain how the program should be used. Display of the parking fees shown above along with explanatory notes will help here. Once the user finishes reading the help screen(s), striking any key(strike a key followed by Enter key) will clear the screen and the menu is displayed again.
C or c (for Cars) option will prompt the user for the number of minutes a vehicle has been in the lot. The program should then compute the appropriate charge and display the ticket on the monitor for the customer. Any part of an hour is to be counted as a full hour (e.g., 65 minutes will be two hours.) Once the user finishes viewing the ticket, striking any key will clear the screen and the above menu is displayed again.
M or m (for Motorcycles) option will prompt the user for the number of minutes a vehicle has been in the lot. The program should then compute the appropriate charge and display the ticket on the monitor for the customer. Any part of an hour is to be counted as a full hour (e.g., 45 minutes will be one hour.) Once the user finishes viewing the ticket, striking any key will clear the screen and the menu will be displayed again.
S or s (for Senior Citizens) option will prompt the user for the number of minutes a vehicle has been in the lot. The program performs no computations. The ticket shouyld show $0.00. Once the user finishes viewing the ticket, striking any key will clear the screen and the menu is displayed again.
Q or q (for Quit) option will clear the screen and returns the control to the programmer's IDE.
If you are able to complete this.. I'd love you forever. IF you can do it in GUI thats even better. Thanks
Explanation / Answer
please rate - thanks
import java.util.*;
public class parkinglot
{
public static void main(String []args)
{Scanner in=new Scanner(System.in);
char choice;
double cost=0;
choice=menu(in);
while(choice!='Q')
{switch(choice)
{case 'H': help(in);
break;
case 'C': cost=cars(in);
break;
case 'M': cost=motorcycles(in);
break;
case 'S': cost=senior(in);
break;
}
if(choice!='H')
System.out.printf("cost=$%.2f ",cost);
System.out.println("Press any key and enter to continue");
in.nextLine();
choice=menu(in);
}
}
public static void help(Scanner in)
{System.out.println("Cars: First 1 Hour: Free");
System.out.println("Next 2 Hours: $2.00 per hour");
System.out.println("Next 5 Hours: $1.00 per hour");
System.out.println("Thereafter: $0.50 per hour(more than 8 hours)");
System.out.println("");
System.out.println("Motorcycles: First 1 Hour: $1.00");
System.out.println("Next 5 Hours: $0.50 per hour");
System.out.println("Next 8 Hours: $0.25 per hour");
System.out.println("Thereafter: $0.10 per hour (more than 14 hours)");
System.out.println("");
System.out.println("Senior Cititzens: Free");
System.out.println("Press any key and enter to continue");
in.nextLine();
}
public static double cars(Scanner in)
{final double> final double two=2;
final double five=1;
final double eight=.5;
int m;
System.out.println("Enter minutes in the lot: ");
m=in.nextInt();
in.nextLine();
if(m<=60)
return one;
else if(m<=180)
return (m-1)/60*two;
else if(m<=480)
return (m-180+59)/60*five+2*two;
else
return 2*two+5*five+(m-60*8+59)/60*eight;
}
public static double motorcycles(Scanner in)
{final double> final double five=.5;
final double eight=.25;
final double fourteen=.1;
int m;
System.out.println("Enter minutes in the lot: ");
m=in.nextInt();
in.nextLine();
if(m<=60)
return one;
else if(m<=300)
return (m-60+59)/60*five+one;
else if(m<=60*14)
return (m-60*8+59)/60*eight +5*five+one;
else
return (m-60*14+59)/60*fourteen +8*eight+5*five+one;
}
public static double senior(Scanner in)
{System.out.println("Enter minutes in the lot: ");
in.nextInt();
in.nextLine();
return 0;
}
public static char menu(Scanner in)
{for(; ;)
{
clear();
center();
System.out.println("Help Cars Motorcycles Senior Cititzens Quit");
char c=in.nextLine().charAt(0);
c=Character.toUpperCase(c);
switch(c)
{case 'H': case 'C': case 'M': case 'S': case 'Q': return c;
default: System.out.println("invalid entry");
System.out.println("press any key and enter to continue");
}
}
}
public static void clear()
{for(int i=0;i<28;i++)
System.out.println();
}
public static void center()
{for(int i=0;i<28;i++)
System.out.print(" ");
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.