CSC108 Midterm Solution -- Friday section
=========================================

Solution to question 1
----------------------

i = 2 + 3 * 5 : 17

i = 7 % 3 + 1 : 2

i =  4 / 2.0 : 
	 Error:  The right side of the assignment statement 
	 	 is a double but the left side is an int.
	 	 You cannot perform a widening type conversion
	 	 without an explicit cast.

f = 5 * 2 : 10.0

s = "Hi" + "There" : "HiThere"

c = s.charAt(1) : 'i'

b = s.startsWith('H') : 
	 Error:  The argument to startsWidth should be a String 
	 	 but it is a char in the expression above. 
	 	 Java can't convert char to String.

b = 10 > 2 + 3 : true

i = (int) 6.75 : 6

b = i == 6 || 7 : 
	 Error:  The two arguments to the operator || 
	 	 must be booleans, but in the expression above 
	 	 the second argument is an int. 
	 	 Java can't convert int to boolean.


Solution to question 2(a)
-------------------------


class Customer {
   
   String name ;	// you could declare these variable to be private
   long number ;        // it's not a good idea to make them public
   double balance;

   Customer ( String name, long number, double balance ) {
      this.name = name ;
      this.number = number ;
      this.balance = balance ;
   }

   public void print ( ) {
      System.out.println ( "\nThe customer's name is:     " + name 
                         + "\nThe customer's number is:   " + number 
                         + "\nThe customer's balance is:  " + balance ) ;
   }
}

Solution to question 2(b)
-------------------------

     Customer new_customer = new Customer ( "John Doe", 94523, 99.67 ) ;
     new_customer.print () ;

Solution to question 3
----------------------

   String reverse ( String word ) {

      String drow = "" ;

      for ( int i = 0; i < word.length(); i++ )
          drow = word.charAt(i) + drow ;

      return drow ;
   }