Starting from:

$25

CSE110 - Assignment #1  - Solved

Topics 

•         Variables: declaration and value updates 

•         Arithmetic Expressions (+, -, /, *, %) 

•         Using Scanner class to get the input from the user 

Use the following Guidelines: 

•       Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc).  

•       Keep identifiers to a reasonably short length.  

•       User upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects).  

•       

 
 
 

Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent.  

•       Use white space to make your program more readable.  


                 

Part 1: Explain the solution in your words. (5 Pts) 

 

This assignment has two parts. The first part (Part 1) is to write the solution briefly in your words. It is not a coding question but English writing question. Do not spend a whole page for each question. Try to explain each solution within 150 words.  

The second part (Part 2) is to make a program to display the expected result(s) from user input. It is up to you to start from Part 1 or Part 2. In my case, I start the Part 2, and then answer the Part 1 after my program works correctly.  

 


Question 1) First, The amount of cents is converted into ... 

... 

 

Question 2) First, The amount of seconds is converted into ... ... */ 

 

Question 1) (2 Pts)
Develop a calculator to display the numbers of US dollar ($) bills, when a user inputs the total amount of money as an integer. For example, suppose that the input is 487. So the program 

displays  
$487 is  
 $100 Bills       4 

 $20  Bills       4
 $5   Bills       1 

 $1   Bills       2 

 

Of course, there are many other combinations. You have to develop a program to calculate the result so that the number of bills is minimum. In the above case, 11 (4 + 4 + 1 + 2) is the minimum. If you have more $20 bills, then the number is increased. 

Question 2) (3 Pts) 
Develop a calculator to display the numbers of Day, Hour, Minute, and Second, when a user inputs the total amount of time in seconds. For example, suppose that the input is 239,782 seconds. The program displays: 

 

 

      239,782 seconds are 

             2    Days 

            18    Hours 

            36    Minutes 

            22    Seconds 

Part 2: Programming (15 pts)  

Write a program called Assignment1.java for Question 1 and 2 in Part 1 above.  

 

•      Question 1 (5 pts):   

Display a question and ask the user type an amount of money. 

Once an integer is typed, then display the number of each US$ bill. 

 

•      Question 2 (5 pts):  

Display a question and ask the user type an amount of time in seconds Once an integer is types, then display the number of days, hours, minutes and seconds.  

At the last line, display the "**** End of Program ****"  

 

•     Display Form (5 pts): Look at the sample output carefully. Alignment of each word and number should be similar to the sample.  (Look at the printf() method in textbook) 

 

The program is to display questions and read user inputs, then calculate and print out the requested value with a proper format.  This program will follow a very simple process as shown below. 

 

 

 



Sample Output: 

•     The following is an example input and output. The user input is shown in red (489, and 239782). Test your program by making your own inputs rather than this example. Look at the comments/hints in the explosions. 

 

---------------- INPUT 1 

---------------- 

487 

239782  

 

---------------- YOUR OUTPUT 1 

---------------- 

*** Question 1 *** 

Please input the total amount of money. 489 

    $487 is 

        $100 Bills    4 

        $20  Bills    4 

        $5   Bills    1 

        $1   Bills    2 

 

*** Question 2 *** 

Please input the time in seconds. 239782 

    239,782 seconds are              2    Days 

            18    Hours 

            36    Minutes 

            22    Seconds 

 

*** End of Program *** 


More products