CSC 108 Midterm - Spring 1998 - Tuesday Section =============================================== 1. [10 marks] Below is a Java program segment that begins with some variable declarations and ends with a sequence of assignment statements. Each assignment statement attempts to give a new value to a variable. To the right of each assignment statement, write the value assignmed to the variable, and do not include a decimal point otherwise. In addition, put single quotes around characters, put double quotes around strings, and clearly indicate whether or not a blank is included in the string. If the assignment statement would fail, write the word "Error" and briefly explain what the error is to the right of the statement. boolean b; float f; int i; String s; i = 4 + 2 * 3; i = 5 % 2 + 1; i = 3 * (1 / 2); i = 5.0 / 2.0; f = 2 * 3; i = (int) 7.8; s = "Good" + "Luck"; i = s.indexOf ('d'); b = 2 + 3 > 10; b = true || false; 2. [10 marks: 8 marks for part (a), 2 marks for part (b)] (a) The Widget Company needs a program to keep track of its parts. Write a Java class called Part with the instance variables name (String), number (long) and price (double). Include a constructor in the class to initialize these instance variables when you instantiate an object of this class. Also include a print method in the class to print the name, number, and price of the object. (b) Write a brief Java program segment to instantiate an object called new_part of the Part class and initialize its instance variables name to "Widget Wheel," number to 94523 and price to 9.99. Then call the print method associated with the object to print the information associated with the object. 3. [10 marks] A palindrome is a word that reads the same backwards and forwards. The words "a", "dad", "mom", "noon", and "madam" are all palindromes; the words "yes" and "no" are not. Write a Java boolean method called is_palindrome that accepts one String argument word and returns true if word is a palindrome and false otherwise. To make the problem simpler, you may assume (without checking) that the String word consists of small letters only.