Skip to main content
You’re going to add some error checking and additional features, to Keychains2.You need to make sure that the user always has a positive number, or 0, of keychains in the order.You need to check for a valid menu choice. If not, display an error message and show the menu again.You will need 3 new variables in main, one to store the sales tax (8.25%), one to store the shipping cost per order (5.00),andonetostoretheadditionalperkeychainshippingcost(5.00), and one to store the additional per keychain shipping cost (1.00).view_order() will need to be passed the three additional variables, a total of five, and have a return type of void. It will display, on different lines, the number of keychains in the order, the price per keychain, the shipping charges on the order, the subtotal before tax, the tax on the order, and the final cost of the order.view_order() might look like public static void view_order( int num_keychains, double price_per_keychain, double tax, int base_shipping, int per_keychain_shipping )checkout() will need to be passed the same values as view_order(), and have a return type of void. It will ask the user for his/her name in order to deliver them correctly, then call view_order() to display the order information, and then thank the user, by name, for ordering.Sample Output
Ye Olde Keychain Shoppe

1. Add Keychains to Order
2. Remove Keychains from Order
3. View Current Order
4. Checkout

Please enter your choice: 1

You have 0 keychains. How many to add? 3
You now have 3 keychains.

1. Add Keychains to Order
2. Remove Keychains from Order
3. View Current Order
4. Checkout

Please enter your choice: 2

You have 3 keychains. How many to remove? 1
You now have 2 keychains.

1. Add Keychains to Order
2. Remove Keychains from Order
3. View Current Order
4. Checkout

Please enter your choice: 3

You have 2 keychains.
Keychains cost $10 each.
Shipping charges are $5.00.
Subtotal before tax is $20.00.
Tax on the order is $1.65.
Total cost is $26.65.

1. Add Keychains to Order
2. Remove Keychains from Order
3. View Current Order
4. Checkout

Please enter your choice: 4

CHECKOUT

What is your name? Biff
You have 2 keychains.
Keychains cost $10 each.
Shipping charges are $5.00.
Subtotal before tax is $20.00.
Tax on the order is $1.65.
Total cost is $26.65.
Thanks for your order, Biff!
Rewrite the Weekday Calculator to have almost no functions in it. Start by opening up WeekdayCalculator.java and saving a copy of it as CallingFunctionsFromOtherFiles.java.Then erase all the functions except for main() and weekday().Now, when you compile it, you should get a lot of errors about undefined functions.Then rewrite all the function calls so that they refer to versions in your previous assignments. The functions will be these:
  • MonthName.month_name()
  • WeekdayName.weekday_name()
  • MonthOffset.month_offset()
  • WeekdayCalculator.is_leap()
Write a function like so:
public static boolean isEven( int n )
The function should return the value true if n is an even number (evenly divisible by 2) and false otherwise.Also, write
public static boolean isDivisibleBy3( int n )
The function should return the value true if n is evenly divisible by 3 and false otherwise.Write a main() that contains a for loop to generate all the numbers from 1 to 20. Use if statements inside the loop to mark the number with a ”<” if it’s even, with a ”=” if it’s evenly divisible by 3, and with both if it’s divisible by both 2 and 3.Sample Output
1
2 <
3 =
4 <
5
6 <
6 =
7
8 <
9 =
10 <
11
12 <
12 =
13
14 <
15 =
16 <
17
18 <
18 =
19
20 <
Write a function like so:
public static boolean isPrime( int n )
The function should return the value true if n is a prime and false otherwise.Remember that a number is prime if is isn’t evenly divisible by anything except for 1 and itself. You can figure this out by using a for loop inside the function.Make the for loop run through all the numbers from 2 up to n. Inside the loop, use an if statement that determines if n is evenly divisible by your loop control variable.If you find any number which divides it evenly, you can go ahead and return false from the function without finishing the loop.If the loop finishes and doesn’t find any numbers which divide it, then return true from the function.After you finish writing the function write a main() that contains another for loop. Have it print out all the numbers from 2 to 20, and mark each prime number with a ”<”.Sample Output
2 <
3 <
4
5 <
6
7 <
8
9
10
11 <
12
13 <
14
15
16
17 <
18
19 <
20