|
home—info—lects—labs—exams—hws
tutor/PIs—breeze (snow day)
Object120 + its docs—java.lang docs—java.util docs
In lecture, we have seen
Completed from last time:
Data analysis:
a student has a name, a sid, a gpa, a major,
and a number of credit hours completed.
Create a java
Hint: (Compare that to “a song has an artist, a title, a length, and whether it's copyrighted”, and the code that resulted from that:
class Song { String title; String artist; double length; // in seconds. boolean isCopyrighted; } |
Task: Write a constructor for
Hint: (Compare that to:
class Song extends Object120 { String title; String artist; double length; // in seconds. boolean isCopyrighted; // Constructor: Song( String t, String a, double len, boolean isC ) { super( t, a, len, isC ); } // A test-driver, for song functions we'll write soon. void static testSong() { Song s1; s1 = new Song("Hit the floor", "Nickelback", 4*60+2, true ); Song s2; s2 = new Song("Everybody Knows", "Leonard Cohen", 3*60+27, true ); } } |
Compare this to:
// A test-driver, for song functions we'll write soon. void static testSong() { Song s1; s1 = new Song("Hit the floor", "Nickelback", 4*60+2, true ); Song s2; s2 = new Song("Everybody Knows", "Leonard Cohen", 3*60+27, true ); System.out.println( "Actual : " + diskSpaceUsed(s1) ); System.out.println( "Desired: " + (4*60+2)*0.0222 ); System.out.println( "Actual : " + diskSpaceUsed(s2) ); System.out.println( "Desired: " + (3*60+27)*0.0222 ); System.out.println( "Actual : " + diskSpaceUsed( new Song( "The Sound of Silence", ) ); System.out.println( "Desired: " + (3*60+27)*0.0222 ); } |
Compare this to:
void static double disKSpaceUsed( Song myTune ) { } |
Compare this to:
void static double disKSpaceUsed( Song myTune ) { return myTune.length * 0.0222; } |
home—info—lects—labs—exams—hws
tutor/PIs—breeze (snow day)
Object120 + its docs—java.lang docs—java.util docs
©2012, Ian Barland, Radford University Last modified 2012.Oct.04 (Thu) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |