In: Computer Science
Scenario: The human resources department for your company needs a program that will determine how much to deduct from an employee’s paycheck to cover healthcare costs. Health care deductions are based on several factors. All employees are charged at flat rate of $150 to be enrolled in the company healthcare system. If they are married there is an additional charge of $75 to cover their spouse/partner. If they have children, the cost is $50 per child. In addition, all employees are given a 10% deduction in the total cost if they have declared to be a “non-smoker”. Your goal is to create a program that gathers the employee’s name, marital status, number of children and whether or not they smoke tobacco for a single employee. While gathering this information, if the user enters at least one invalid value, the program must display one error message telling the user they made a mistake and that they should re-run the program to try again. The program must then end at this point. However, if all valid values are entered, the program should calculate the total cost of the healthcare payroll deduction and then print a well-formatted report that shows the employee’s name, marital status, total number of children, and smoker designation, and total deduction amount.
1. Create a defining diagram that shows the input, processing, and output
2. Show testing using the desk checking table method, to include test data, expected results, and a desk checking table. Make sure your desk checking considers multiple cases including both valid and invalid test data to prove your algorithm will work in all cases
Java Code for the following Scenario.
import java.util.*;
class Main
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
System.out.println("Please Enter your Name:");
String name=in.next();
System.out.println("Please Enter your marital status:\n 1 - Yes\n 0 - No");
int ms=in.nextInt(); //ms for storing Martial Status.
System.out.println("Please Enter the No of Children:");
int children=in.nextInt(); //for storing no. of children.
System.out.println("Do you Smoke Tobacco:\n 1 - Yes\n 0 - No ");
int smoke=in.nextInt(); //for storing weather they smoke or not.
if( (ms==0 || ms==1) && (children>=0) && (smoke==0 || smoke==1))
{
double amount=150; //it is intialized with 150$ beacuse all employee will be charged 150$.
if(ms==1) //checking the martial status,if 1 then married otherwise not.
{
amount=amount+75; //we have to add 75$
}
int childcost=children*50; //finding the cost for children by multiplying no of children with 50$.
amount=amount+childcost; //adding childcost.
// checking the smoking status.
if(smoke==0)
{
int deduction=(amount*10)/100;
amount=amount-deduction;
}
System.out.println("Name :"+name);
if( ms==0)
System.out.println("Martial Status : Unmarried");
else
System.out.println("Martial Status : Married");
System.out.println("No of Children: "+children);
if(smoke==0)
System.out.println("Smoker Designation : Non Smoker");
else
System.out.println("Smoker Designation : Smoker");
System.out.println("Your Total Deduction Amount is :"+amount);
}
else //re-run
{
System.out.println("Please Re Run the Program because entered details are Invalid.");
}
}
FLOW