Subject Computer Science Java Programming

Question

Part I: Time Flies When You’re Having Fun
Filename(s): PalindromicDate.java
Write a program that prompts the user to enter, in this order, (i) a month (which could be in mixed uppercase/lowercase), (ii) a day and (iii) a four-digit year. Then, the program prints the date in a format MM/DD/YY, with exactly two digits each for the month, day and year. It also prints whether the reformatted date is a palindrome.
Note: Your program must check for bad input, such as an invalid month name, invalid day of the month, or invalid year (less than 1). In such cases, print only the error message “Bad input.” and produce no other output.
Your program must handle leap years correctly.
Below are sample runs of the program.
Enter month: FEBruary
Enter day: 18
Enter year: 1979
Reformatted date: 02/18/79
Palindrome? no
Enter month: ocTobEr
Enter day: 11
Enter year: 2001
Reformatted date: 10/11/01
Palindrome? yes
Enter month: APRIL
Enter day: 31
Enter year: 2011
Bad input.

Part II: What A View! Wait, What’s That Smell?
Filename(s): StonyBrookResort.java
The Stony Brook Resort and Manure Depot offers a vacation package as follows:
• The regular price for each adult is $125 per day. However, any days beyond the fifth day that an adult stays are 25% off the regular price.
• The price for each child is $75 per day regardless of how many days a group stays.
• A $150 discount is given if the group’s stay begins on a Monday and lasts no more than 4 days (including Monday itself).
• A service charge of 5% of the original, non-discounted cost is applied for groups of 6 or more.
Write a program that prompts for, in this order, (i) the number of adults, (ii) the number of children, (iii) the length of the vacation in days, and (iv) the day of the week that the vacation begins (which might be given in mixed uppercase/lowercase).
Then, print the following values – again, in this order – formatted as dollar amounts with two digits after the decimal point for cents: (i) the total before any discounts have been applied, (ii) discounts (if any), (iii) service charges (if any), and (iv) the grand total.
Here is one test case. You should make up others yourself to fully test your code.
Note: Your program may assume that the user enters only valid input at the prompts.
Enter number of adults: 4
Enter number of children: 3
Enter length of vacation in days: 7
Enter day of week that vacation starts: Monday
Total before discounts: $5075.00
Discounts: $250.00
Service charges: $253.75
Grand total: $5078.75

Part III: Managed Chaos
Filename(s): Payday.java
A company employs four kinds of employees:
• managers, who receive a fixed weekly salary;
• hourly employees, who receive a fixed hourly wage for up to the first 35 hours they work and “double overtime” (2x their hourly wage) for overtime hours worked;
• commission workers, who receive $250 plus 5.7% of their weekly sales;
• pieceworkers, who receive a fixed amount of money per item that they produce (each pieceworker works on only one type of item)
Write a program that computes the net weekly pay for an employee and prints a summary containing, on separate lines and in this order, (i) the gross weekly pay, (ii) the income tax withheld, and (iii) the final, net weekly pay (i.e., gross pay minus taxes). The program begins by prompting for the kind of employee, as follows:
Choose employee type: (m) manager (h) hourly (c) commission (p) pieceworker:
Depending on the kind of employee, it then prompts only for the information required to determine that employee’s gross weekly pay. For instance, for a commission worker the program needs to prompt for only the weekly sales (as a double) because the $250 and 5.7% amounts are fixed and should be “hard-coded” into your program. Here’s an example:
Choose employee type: (m) manager (h) hourly (c) commission (p) pieceworker: c ←-
Enter weekly sales: 5420.65 ←-
After determining the gross weekly pay, the program subtracts 12.5% for taxes and computes the net pay. Assume that any values entered by the user could contain a decimal point. Use System.out.printf to format the three output values (gross pay, taxes and net pay) with a dollar sign and exactly two digits after the decimal point for cents. Below are sample runs of the program.
Note: Your program may assume that the user enters only valid input at the prompts.
Choose employee type: (m) manager (h) hourly (c) commission (p) pieceworker: m ←-
Enter weekly salary: 6700.50
Gross pay: $6700.50
Taxes: $837.56
Net pay: $5862.94
Choose employee type: (m) manager (h) hourly (c) commission (p) pieceworker: h Enter hourly wage: 14.25
Enter hours worked: 56.5
Gross pay: $1111.50
Taxes: $138.94
Net pay: $972.56
Choose employee type: (m) manager (h) hourly (c) commission (p) pieceworker: c
Enter weekly sales: 5420.65
Gross pay: $558.98
Taxes: $69.87
Net pay: $489.10
Choose employee type: (m) manager (h) hourly (c) commission (p) pieceworker: p Enter pieces produced: 156
Enter pay per piece: 2.50
Gross pay: $390.00
Taxes: $48.75
Net pay: $341.25

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.util.Scanner;

public class Payday {
    public static void calculateManager(){
       Scanner userInput = new Scanner(System.in);
       double managerPay=0;
       System.out.print("Enter weekly salary: ");
       managerPay = userInput.nextDouble();

       System.out.printf("Gross pay: $%.2f\n", managerPay);
       System.out.printf("Taxes: $%.2f\n", managerPay*0.125);
       System.out.printf("Net pay: $%.2f\n", managerPay-managerPay*0.125);

    }

    public static void calculateHourly(){
       Scanner userInput = new Scanner(System.in);
       double hoursWorked = 0;
       double hourlyWage = 0;

       System.out.print("Enter hourly wage: ");
       hourlyWage = userInput.nextDouble();
       System.out.printf("Enter hours worked: ");
       hoursWorked = userInput.nextDouble();

       double hourlyPay = 0;
       if (hoursWorked<=35){
            hourlyPay=hoursWorked*hourlyWage;
       }
       else if(hoursWorked>35){
            hourlyPay=35*hourlyWage+(hoursWorked-35)*hourlyWage*2;
       }

       System.out.printf("Gross pay: $%.2f\n", hourlyPay);
       System.out.printf("Taxes: $%.2f\n", hourlyPay*0.125);
       System.out.printf("Net pay: $%.2f\n", hourlyPay-hourlyPay*0.125);
    }...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats