Programming and Problem Solving with Java

(やまだぃちぅ) #1
265

If the input integer is an even number, it should be increased to the next odd
number. Use meaningful variable names, proper indentation, appropriate com-
ments, and good prompting messages. Use System.infor input and a
PrintWriterobject for output.

2.Design and write a Java application that takes as input an integer larger than 1
and calculates the sum of the squares from 1 to that integer. For example, if the
integer equals 4, the sum of the squares is 30 (1 + 4 + 9 + 16). The output should
be the value of the integer and the sum, properly labeled on the screen. The ap-
plication should repeat this process for several input values. Use a sentinel
value to end processing, and use screen input and output.


3.You are burning some music CDs for a party. You’ve arranged a list of songs in
the order in which you want to play them. You would like to maximize your use
of space on the CD, which holds 80 minutes of music. To do so, you want to fig-
ure out the total time for a group of songs and see how well they fit. Design and
write a Java application to help you do this. The data is on the file songs.dat.
The time is entered as seconds. For example, if a song takes 7 minutes and 42
seconds to play, the data entered for that song would be


462
After all the data has been read, the application should print a message
indicating the time remaining on the CD.
The output should be in the form of a table with columns and headings
written on a file. For example:

Song Song Time Total Time
Number Minutes Seconds Minutes Seconds
------ ------- ------- ------- -------
1 5 10 5 10
2 7 42 12 52
5 4 19 17 11
3 4 33 21 44
4 10 27 32 11
6 8 55 41 6
There are 38 minutes and 54 seconds of space left on the 80 minute CD.
Note that the output converts the input from seconds to minutes and seconds.
Free download pdf