Sie sind auf Seite 1von 5

UNIVERSITY OF ZIMBABWE B.Sc.

ENGINEERING (HONOURS) PART I COMPUTER SCIENCE FOR ENGINEERS EE103 FINAL EXAMINATION, DECEMBER 2007 TIME ALLOWED : 3 HOURS This paper has seven questions on five printed pages. ANSWER ANY FIVE QUESTIONS QUESTION 1 a) What is a Java Interface? Why is it used? [3marks] b) What are Java Abstract classes.Why are they used? [3 marks] c) Design a Java class PressureController with appropriate data variables, co nstructors, setter and getter methods from the following information about an in dustrial boiler pressure controller. Description of An Industrial Boiler Pressure Controller The controller gets two inputs: sampled values of temperature and pressure comi ng from the boiler. The controller checks these values against some set maximum and minimum threshold values. If the read signal values are outside the threshol d values the controller prints warning messages on computer display for operat ors .

[14 marks]

QUESTION 2 a) Define a Java class called Circle with data fields for centre coordinate values , circle radius and circle area, where the area is given by Math.PI*radi us*radius. The class also has a Circle constructor with arguments for the cent re coordinate ( x,y) and radius. The class also has a public method for getti ng circle area. [8 marks] b) Using the Circle class created in 2(a), write a Java applet that draws a Circle object whose centre coordinate values and radius is given as PARAM fie lds in the HTML file. Give the HTML file also. [12 marks] QUESTION 3 a) Consider the following methods:

public void printNext(int x) { System.out.println((x + 1) % 3); } public void printSequence() { for (int i = 0; i < 4; i++){ printNext(i);} } What sequence of numbers is printed by printSequence()? [4 marks] b) Given the following declarations double x = 12.8; double y = -1.5; int m = 18; int n = 4; what is the value of each of the following expressions? i) x / n + y ii) m / n + m % n iii) 4 * y - n / 5 iv) (int) x

[4 marks] c) ers Write a complete program Largest.java that reads in a sequence of 3 numb

entered from standard input and prints out the largest value. Your n umber extraction must handle the NumberFormatException from java.lang package [12 marks] QUESTION 4 a) Create an overloaded e argument of either an integer it should return a double, and an integer. In the latter case [6 marks] b) Consider the following code: class uba { public static double bar(double X, int n) if (n==0) return 1; else return X*(bar(X,n-1)); } public static void main(String[] args) { System.out.println(bar(4,3)); } } s] method called swapType. It should take a singl or a double. If the argument is an integer then if it is a double then the method should return numbers should be rounded to nearest integer.

What will happen when you attempt to run this program?

[6 mark

c) Given the following code public static void f( int y ) { try { System.out.print(A); int x = 1 / y ; // generates ArithmeticException if y == 0 System.out.print(B); } catch (ArithmeticException e) { System.out.print(C); } finally { System.out.print(D); } } What will be printed for the following method calls? f(1); f(0); [8 marks]

QUESTION 5 Given the following classes public class Vehicle { String double double int model,make; speed,price, engine_capacity; acceleration =10; num_doors, num_passengers;

public Vehicle (String n, double w,) { speed=0; model = n; price = w; } public Vehicle (double x, double h) { engine_capacity = x; price = h; speed=0; } public void setSpeed( double t) { speed=speed+ (accelaration* t); } public double getSpeed() { return speed; } public void start() { System.out.println(model+ Starting at +getSpeed() ); } } } public class Car extends Vehicle { double carduty=0.50; public Car(double x, double h) { engine_capacity = x;

price = h; speed=10;

public void setSpeed( double s) { speed=speed+100+s; } public void start() { System.out.println(Car starting at +speed); } public double getDutyPrice(){ return( carduty*price); } } public class CarTest { public static void main(String args[]) { Vehicle v=new Vehicle(Mazda,1000); v.setSpeed(10); v.start(); Car v1 =new Car(2,40000); v1.setSpeed(10); v1.start(); System.out.print( v1.getDutyPrice();} } a) Write what would be printed out if the CarTest program was executed. [12 marks] b) Comment on the following declarations i) icle(MV,20); ii) r( 3,2000); [8 marks] QUESTION 6 a) Consider the terms variable, method, object, and class. These are fun damental concepts related to data representation in java programming. Dis cuss these terms. What are the relationships among them? [8 marks] b) What do you consider to be the main advantages of object oriented programmi ng [12 marks] QUESTION 7 a) Define a class called Time which has two integer data fields hour and minute, and a double data field ,second. The class has one constructor with th ree appropriate parameters, and also two methods, isNow and isAfter. Both metho ds should have one parameter time of type Time. Vehicle v2 =new Ca Car mycar= new Veh

The method isNow should return true if a Time object is equal to time and false otherwise. The method isAfter should return true if a Time object is after time and false o therwise. [10 marks] b) Using the Time class defined in a), write a bubble sort method that sor ts an array of Time objects into ascending time order.

Das könnte Ihnen auch gefallen