Group A assignment due 2 November 2010

1) Given three arrays A, B initialized with some non sorted integers, and C with a size equal to the sizes of A and B put together, write a Java program to combine array A and B elements into the array C and print all the elements in C. 2) Given public class Journey{ public static void main(String[] args){ double distance = 400.48; double fuel = 21.4; AutoTrip myTrip = new AutoTrip(); myTrip.ID=12457; myTrip.stops[]={“Harare”,”Chegutu”,”Bulawayo”,”Plumtree”}; double cost= myTrip. getMileageCost (fuel,distance); System.out.println(" my mileage cost was " + cost); if( myTrip.isPossible(cost)){ System.out.println(" I am off”); } } } Create an AutoTrip class that will allow the Journey class to work correctly.

N. Description of An Industrial Boiler Pressure Controller The controller gets two inputs: sampled values of temperature and pressure coming from the boiler. setter and getter methods from the following information about an industrial boiler pressure controller.Group B assignment due 2 November 2010 1) Write a complete Java method that will count the number of occurrences of two integers. If any read signal values are outside the threshold values the controller prints warning messages on computer display for operators . The method should print the final count of each integer and return the total count of both 2) Design a Java classes PressureController and Alarm with appropriate data variables. The variables N and n and y should be parameters to the method. constructors. x and y. The controller checks these values against some set maximum and minimum threshold values. . If both read signal values are outside the threshold values the controller prints warning messages on computer display for operators and starts an alarm . in a given one-dimensional array of integers.

println(model+“ Starting at ” +getSpeed() ). price = h. num_passengers. } public void setSpeed( double t) { speed=speed+ (accelaration* t).50. speed=0. speed=10. Y initialized with some non sorted numbers. double h) { engine_capacity = x. Car v1 =new Car(2.setSpeed(10). } public void start() { System. double h) { engine_capacity = x.print( v1. } public double getSpeed() { return speed.100 0). } } public class CarTest { public static void main(String args[]) { Vehicle v=new Vehicle(“Mazda”.make. } public double getDutyPrice() { return( carduty*price). } public Vehicle (double x. and put the result into the corresponding index element of boolean array Z .price.Group C assignment due 2 November 2010 1) Given two equal sized double arrays : X. Write a Java method to check the equality of corresponding elements of array X and Y elements .println(“Car starting at ”+speed). v.40000). double w. and a third equal sized boolean array Z . v1. engine_capacity. v. } public void setSpeed( double s) { speed=speed+100+s.setSpeed(10). v1.out. 2)Given the following classes public class Vehicle { String model.out. System. public Vehicle (String n.getDut yPrice().start(). public Car(double x. } public void start() { System. price = h. double acceleration =10.} } . price = w. int num_doors. model = n.) { speed=0.start(). double speed.out. } } public class Car extends Vehicle { double carduty=0.

b) Comment on the following declarations i) Car mycar= new Vehicle(“MV”. ii) Vehicle v2 =new Car( 3.a) Write what would be printed out if the CarTest program was executed.20).2000 .

System.display(). } public void display() { System.println(p.enquire()).out. } public myQuestion(int x) { this().interrogate(9) + “ “). myProblem p.out.enquire() + “ “).out.out. } public void display() { System. p. and Z . p=new myProblem(20. } public myProblem(int x.enquire().2). q. System. public myQuestion() { a = 0. System.display().display(). } public int enquire() { return a + b. a = x. c = x. p. p.z).2).y).interrogate(2) + “ “). b = 0.print(q.out.println(a + “ “ +b + “ “ +c). } } class myProblem extends myQuestion { protected int c. Print all the elements in Z . . 2) Given the following classes class myQuestion { protected int a. System. q. int z) { super(y. } public myProblem(int x){ c = x.print(p.Group D assignment due 2 November 2010 1) Given three equal sized double arrays : X. p. return c. public myProblem() { c = 0. b = y. myQuestion q =new myQuestion(20. } public myProblem(int x. myProblem p=new myProblem(20.println(a + “ “ + b). b) c) d) q=new myQuestion(1).display(). } } What is the output of the program segments: What is the output of the program segments: a) myQuestion q.print(q.out. int y) { this(). } public int enquire() { c = a * b. and put the result into the array Z . int y. Y initialized with some non sorted numbers. q.2.4).enquire()). super(x. protected int b.print(q. System.display().out.display(). } public int interrogate(int x) { return (a + b)* x. Write a Java program to get sum of corresponding elements of array X and Y elements . } public myQuestion(int x. int y) { a = x.

98).getFueLevel() + “ litres remaining”). } } public static void printSequence() { int y[ ]={1. Vehicle v1= new Vehicle(“Benz”).getModel() +” has ” +v1.println(driver.setA( 0.driveMe(“Today”). driver. v2.90).out.println(v1. //km/hour v2. //litres v1. i++){ printNext(y). TopDriver driver= new TopDriver(“Peter”) driver.out. //km } } .out. //litres v1. driver. System. //litres System.accellerate( 11. System.Group E assignment due 2 November 2010 1)Consider the following methods in a runnable class: public static void printNext(int x[ ]) { for (int i = 0.out. public class CarDriver { public static void main String( args[]){ double duty=0.println((x[i] + 1) % 3). for (int i = 0.setTarget(80.setFuelLevel(200). driver. i < y.setMaximumSpeed(200). v2.} } What sequence of numbers is printed by printSequence()? 2) Create Vehicle and TopDriver classes that will make the following CarDriver program compile and run properly.setFuelLevel(20).size. i++){ System.2).getPrice( duty)).size.setW( 10).5}.2.getLog() ). i < x.getID() +” has travelled ” + driver.getModel() +” costs ” +v2.4.3. Vehicle v2= new Vehicle(“Mazda”).drive(v2). v1.2.println(v2.drive(v1).

Sign up to vote on this title
UsefulNot useful