In: Computer Science
BEFORE YOU START: Before working on this assignment you should have completed Assignment 1. PROGRAM STATEMENT AND REQUIREMENTS:
You will implement in Java the WIFI troubleshooting program you created in Assignment 1 with the following additional conditions: At the end of the program, you will ask if the client wants to purchase a regular router for $50 or a super high-speed router for $200, adding the cost to the total amount the client needs to pay. Once your program calculates the final bill amount, it needs to ask if the client is a member of the military. If so, your program should reduce by 10% the total amount the client needs to pay. Finally, your program must print on the screen the final bill amount to pay, together with the amount reduced for a military discount if applicable (e.g. if the total amount for a military client was $220, your program must show something like this: "Your total bill is $198. This includes a $22 military discount").
Note:
Make sure to format all number outputs so only 2 decimals are shown.
Add all necessary comments to your code, including the header comment and body comments explaining your code.
Test your program several times and paste the testing output show in the console as a comment at the bottom of your source code in the driver/main class program file.
Correctly name your classes, methods, and variables.
Suggestion: Add the steps to the flow chart you created in Assignment 1 and use it to help you plan your program. You may include the updated flow chart in your submission, but it is not required.
import java.util.Scanner;
public class Router {
public void Calculate(double inital_cost){
double additional_cost = 0;
Scanner sc = new Scanner(System.in);
String s;
System.out.println("Do you want to purchase a regular router for 50 dollars or a super high speed router for 200 dollars?");
// Enter 1 for regular or 2 for high speed. Keep taking input till valid input is entered.
System.out.println("Enter 1 for regular router and 2 for high speed router.");
s = sc.nextLine();
while(!s.equals("1") && !s.equals("2")){
System.out.println("Please enter a valid input.");
s = sc.nextLine();
}
if(s.equals("1")){
additional_cost += 50;
}
else{
additional_cost += 200;
}
double military_discount = 0;
// Enter y for yes and n for No. Keep taking input till valid input is entered.
System.out.println("Are you a member of the military? Enter Y/y for yes and N/n for no");
String m = sc.nextLine();
m = m.toLowerCase();
while(!m.equals("y") && !m.equals("n")){
System.out.println("Please enter a valid input");
m = sc.nextLine();
m = m.toLowerCase();
}
// calculate total cost and military discount.
double total_cost = inital_cost + additional_cost;
if(m.equals("y")){
military_discount = total_cost/10;
}
total_cost = total_cost - military_discount;
if(military_discount != 0){
System.out.printf("Your total bill is $%.2f. This includes a $%.2f military discount\n",total_cost, military_discount);
}
else{
System.out.printf("Your total bill is $%.2f\n", total_cost);
}
}
public static void main(String[] args){
Router r = new Router();
r.Calculate(100);
}
}
Please copy paste the code from the calculate method to the end of the code in assignment 1, or simply call the calculate method from the end of code from assignment1 while passing the value of bill cost calculated in assignment1.
Appropriate comments have been added for better readability.
I would love to resolve any queries in the comments. Please consider dropping an upvote to help out a struggling college kid :)
Happy Coding!!