110. Keychains for Sale, real ultimate power - Link
- Task
- Code
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 (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
111. Calling Functions from Other Files - Link
- Task
- Code
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()
112. Evenness Function - Link
- Task
- Code
Write a function like so:The function should return the value The function should return the value
true if n is an even number (evenly divisible by 2) and false otherwise.Also, writetrue 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 Output113. Finding Prime Numbers - Link
- Task
- Code
Write a function like so: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