Develop a functional flowchart and then write a menu-driven Java program using G
ID: 3658940 • Letter: D
Question
Develop a functional flowchart and then write a menu-driven Java program using GUI, and 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.Explanation / Answer
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.util.Scanner;
import javax.swing.JOptionPane;
//This Program shows Payroll for an employee
public class Payroll{
static String first;
static String last;
static double hours;
static double pay;
static double tickets;
static double statetax;
static double fedtax;
static double totalded;
//main method begins program execution
public static void main(String args[]) {
// Obtain input
String f = JOptionPane.showInputDialog(null,
"Input file name:(filename)",
"Input", JOptionPane.QUESTION_MESSAGE);
File file = new File(f);
try {
//
// Create a new Scanner object which will read the data
// from the file passed in. To check if there are more
// line to read from it we check by calling the
// scanner.hasNextLine() method. We then read line one
// by one till all line is read.
//
Scanner s = new Scanner(file);
while (s.hasNext()) {
first = s.next();
last = s.next();
hours = Double.parseDouble(s.next());
pay = Double.parseDouble(s.next());
tickets = Double.parseDouble(s.next());
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
CalculateNetPay();
try{
// Create file
FileWriter fstream = new FileWriter("out.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.append(first + " " + last + " ");
out.append(" Basic Pay $" + (CalculateGrossPay()-CalculateOverTime()));
out.append(" Overtime Pay $" + CalculateOverTime());
out.append(" Gross Pay $" + CalculateGrossPay()) ;
out.append(" State Tax Amt $" +statetax);
out.append(" Fed Tax Amt $" +fedtax);
out.append(" Total Taxes $" + (fedtax+statetax));
out.append(" Net Pay $" + CalculateNetPay()); //Close the output strea m
out.append(" Parking Ticket $" + CalculateTickets());
out.append(" Total Pay $" + (CalculateNetPay()-CalculateTickets()));
out.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}//End main
//calculate gross pay
static Double CalculateGrossPay(){
return hours * pay;
}
//calculate overtime
static Double CalculateOverTime(){
//calculate the overtime rate
if (hours > 40)
{
return (( (hours -40) * pay) * 1.5);
}
else
{
return 0.0;
}
}
//calculate net pay
static Double CalculateNetPay(){
double fedTaxWithholding = CalculateGrossPay() * 0.20;
double stateTaxWithholding = CalculateGrossPay() * 0.09;
statetax = (int)(stateTaxWithholding * 100) / 100.0;
fedtax = (int)(fedTaxWithholding * 100) / 100.0;
double totalDeduction = (fedTaxWithholding + stateTaxWithholding);
totalded = (int)(totalDeduction + CalculateTickets()) * 100 / 100.0;
return (CalculateGrossPay() - totalDeduction) + CalculateOverTime() + CalculateTickets();
}
//calculate parking tickets
static Double CalculateTickets(){
double charge;
if (tickets <= 0) return 0.00;
else
if (tickets <= 2) return 20.00;
else
if (tickets <= 6) return 50.00;
else
if (tickets > 5) return 100.00;
else return 0.00;
}
}//end class CompanyPayroll
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.