Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java homework for this week. The first one i have about done, but this page full of loops is throwing me for a loop a)

Java homework for this week. The first one i have about done, but this page full of loops is throwing me for a loop

a) Converting numbers to Roman Numerals (some of them, not all). Ask the user for the number of conversions to perform. So, if I want to convert 4 numbers, the given input would be 4. Then, convert each number to its Roman number equivalent. The number entered by the user must be between 1 and 10, inclusive. If its not, allow the user to enter another number until the user enters a valid number. If the number is valid, display the corresponding Roman numeral number. Hope you can perform a simple web search to find the conversion codes (I is 1, II is 2, etc.). Output should include the input number and the corresponding Roman numeral. For example, something like: The Roman number for 1 is I. Here some sample test cases: number of items = 3 Enter a number: 2 Number = 2 and Roman number = II Enter a number: -1 Invalid try again Enter a number: 100 Invalid try again Enter a number: 3 Number = 3 and Roman number: III Enter a number: 9 Number = 9 and Roman number: IX ***Note that the program prompted the user for 3 numbers because the number of items was 3.

b) We can use a loop to calculate and display the value of the following series. The pattern seems pretty obvious and ideal for a simple loop. As you can see, Were starting the pattern for the numerator from 1 to 9 and the denominator stars from 9 and goes down to 1 with steps of 2. Ask the user for the starting value and the ending value and compute the total. I need the value of the total displayed on the screen. So, if the first number is 1 and the last number is 9, we get the following series/pattern. 1/9 + 3/7 + 5/5 + + 9/1 Make sure to watch for integer division and the problems with it. Hint: One loop with variables that handle the numerator and the denominator could do the job. Given the above series, the total should 12.87 be that you can test with your code. Format the total to display with 2 digits after the decimal point.

c) Write a program to process items that a user purchases. We like to be able to have the user enter prices for as many items that she wants to purchase. Allow for a sentinel value to end the input loop. You may pick a negative number as the sentinel value. ii. Do not allow the user to enter an invalid price (A number greater than $200). Issue an error message and allow the user to enter a valid price. iii. Calculate and display the total amount of all purchases and the number of items purchased. iv. Calculate and display the average price of all purchases. If the user enters the sentinel value at the beginning of the processing, the code should not display any totals or averages. Here is a sample run:

Enter the price of an item, enter -1 when done: -1 Thanks for using the price calculator Enter the price of an item, enter -1 when done: 100 1000 Invalid price Cannot handle anything over $200 try again 2000 Invalid price Cannot handle anything over $200 try again 50 -1 Total = 150 Average = 75 d)

d) Write a program to ask the user for an employees ID number, first name, last name, regular and overtime hours worked and the hourly pay rate for any number of employee. You may ask the user for the number of employees to be processed. Calculate employees gross pay and net pay. Note that overtime pay is 1.5 times the regular pay, if the employee worked more than 40 hours. Net pay is gross pay minus deductions. Assume that deductions are taken for tax withholding at 30% of gross pay and that parking costs $10. The tax rate and parking cost must be defined as named constants. Display the output (employee information entered and all calculated values) on the screen. Make sure that all monetary values are displayed with 2 digits after the decimal point and dollars signs are inserted where appropriate. The following example calculations should help with the formulas

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 2005 Databases

Authors: Karli Watson

1st Edition

0470044063, 978-0470044063

More Books

Students also viewed these Databases questions