RU beehive logo ITEC dept promo banner
ITEC 120
2009spring
ibarland
nokie
jmdymacek

homeinfolectslabsexamshws
textbooktutor/PIsjava.lang docsjava.util docs

hw02
songs and rectangles

Due Feb.06 (Fri).
(You know everything you need to do #1, and are encouraged to finish it soon. #2-6 will use concepts we talk about on Monday.)
(Here are some notes for PI/tutors.)
  1. (15pts) Write a program that has the user enter the information for two songs: the band and song-title, followed by the playing-time (entered as minutes and seconds separately). You may use calls to JOptionPane.showInputDialog(String) to enter this data.

    Then, display the total running time (in seconds), the average running time (in seconds), and the length of the each title.

    For example, if the user enters the following information (through a series of six dialog boxes):

    The Beatles: Being for the Benefit of Mr. Kite!
    3
    25
         Coldplay: Yes
    7
    0
    
    then your program will print out (using System.out.println):
    Total   playing time: 625 seconds
    Average playing time: 312.5 seconds
    Length of each title: 34, 3
    

    The user must type in the information using the format “bandName: songTitle” (that is, exactly one colon and one space between the band-name and the song-title. You may assume that neither the band-name nor the song-title themselves contain a colon.) However, the user can type extra spaces or tabs (“whitespace”) at the front or end of the line; your program should not consider that part of the band-name or song-title. (Hint: there is a String method whose name starts with 't' which will help you.) You may assume the user will not include extra spaces when entering the number of minutes or seconds1.

    (Another hint: You've used the method length to find a string's entire length, but how will we find the length of just the song-title? Use the method indexOf in a clever way. Work through a few examples by hand, and see if that can help you figure out a general approach.)

    Here is a demo-version, if you need to see the program in action. To do this, follow the instructions for how-to-get-jar-files-into-BlueJ—Downloading .jar files into BlueJ. Also, see Friday's lecture notes to review reading what the user types in, and converting Strings to numbers.

  2. (3pts) R2.7 (2ed2: R2.6)
  3. (2pts) R2.8 (2ed: R2.7)
  4. (4pts) R2.9 (2ed: R2.8)
  5. (2pts) R2.11 (2ed: R2.10)
  6. (4 pts) P2.2. Be sure to figure out the expected answer before you run your program the first time.
    (You'll name your class PerimeterTester; that class will have one method, which actually does some testing: public static void main( String[] args ).)

Note: This homework does not involve drawing any rectangles on the screen! Some of the problems have you create Rectangle objects, and call their methods, but never draw them on the screen. (This is analogous to having a program which creates String objects, and calls its methods, but never println them on the screen.)


1You are free to guard against such a case if you like, though.      

2 “2ed” stands for “2nd edition [of the book]”; ignore those problem-numbers if you have the more recent 3ed.      

homeinfolectslabsexamshws
textbooktutor/PIsjava.lang docsjava.util docs


©2009, Ian Barland, Radford University
Last modified 2009.Feb.06 (Fri)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme