CS99

Fundamental Programming Concepts
Summer 2001

 

Lab 2: Solutions


Test.TXT

Part A:
You should have gotten an error like NoClassDefFound Exception.  CodeWarrior is looking for a class called Test, not test, so when it can't find it, it tells you so.

Part B:
No error because Emergency is considered a part of the text message.

Part C:
Error   : ')' expected.
Test.java line 3     System.out.println( An Emergency Broadcast." );

Error   : String not terminated at end of line.
Test.java line 3     System.out.println( An Emergency Broadcast." );

Part D:
Error   : String not terminated at end of line.
Test.java line 3     System.out.println( "An Emergency Broadcast. );

Error   : ')' expected.
Test.java line 4    }


Notice in parts C and D, the compiler doesn't tell you what the exact error is: that you're simply missing a quotation mark.  That's because compilers aren't perfect.  Notice too that the two errors you get the same errors for parts C and D, only in opposite order.

Part E:
Error   : Undefined variable, class, or package name: system
Test.java line 3     system.out.println( "An Emergency Broadcast." );

Part F:
This error depends on which version of CodeWarrior you're running.  But essentially you should have seen an error that told you that there is no main in the class.  CodeWarrior always looks for the method with the signature public static void main( String[] args) to run an application, if it can't find that, it can't run anything.  You couldn't tell CodeWarrior to run another method for instance.
 

Part G:
Error   : Method bogus(java.lang.String) not found in class java.io.PrintStream.
Test.java line 3     System.out.bogus( "An Emergency Broadcast." );

Part H:
No error, because it's text.

Part I:
Error   : ';' expected.
Test.java line 3     System.out.println( "An Emergency Broadcast." )

Part J:
Error   : '}' expected.
Test.java line 4    }


/**
 * CS99 Lab 1
 * Author: Alan Renaud
 * NetID: 555555
 * Date: 26 June 2001
 */
class Lab2 {
   public static void main( String[] args ) {
      System.out.println( "Jenny Kiss'd Me\n\n"
         + "Jenny kiss'd me when we met,\n\tJumping from the chair she sat in;\n" 
         + "Time, you thief, who love to get\n\t Sweets into your list, put that in!\n"
        
+ "Say I'm weary, say I'm sad, \n\tSay that health and wealth have miss'd me,\n"
         + "Say I'm growing old, but add, \n\tJenny kiss'd me. \n\n"
         + "\t\t--Leigh Hunt, Poet."

      
); 
   }
}