You are on page 1of 6

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.
Group B assignment due 2 November 2010
1) Write a complete Java method that will count the number of occurrences of two
integers, x and y, in a given one-dimensional array of integers, N. The variables N and n
and y should be parameters to the method. 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, constructors, setter and getter methods from the following information about an
industrial boiler pressure controller.

Description of An Industrial Boiler Pressure Controller

The controller gets two inputs: sampled values of temperature and pressure
coming from the boiler. The controller checks these values against some set
maximum and minimum threshold values. If any read signal values are outside the
threshold values the controller prints warning messages on computer display for
operators .
If both read signal values are outside the threshold values the controller prints
warning messages on computer display for operators and starts an alarm .
Group C assignment due 2 November 2010
1) Given two equal sized double arrays : X, Y initialized with some non sorted numbers,
and a third equal sized boolean array Z . Write a Java method to check the
equality of corresponding elements of array X and Y elements , and put the result into
the corresponding index element of boolean array Z .
2)Given the following classes

public class Vehicle { public class Car extends


String model,make; Vehicle {
double speed,price,
engine_capacity; double carduty=0.50;
double acceleration =10;
int num_doors, public Car(double x, double h)
num_passengers; {
engine_capacity =
public Vehicle (String n, x;
double w,) { price = h;
speed=0; speed=10; }
model = n; public void
price = w; setSpeed( double s)
} {
speed=speed+100+s;
public Vehicle (double x, }
double h) { public void start() {
engine_capacity System.out.println(“Car
= x; starting at
price = h; ”+speed);
speed=0; }
} public double getDutyPrice()
{
public void return( carduty*price);
setSpeed( double }
t) { }
speed=speed+ (accelaration* public class CarTest {
t);
} public static void
public double getSpeed() { main(String args[]) {
return speed;
} Vehicle v=new
public void start() { Vehicle(“Mazda”,100
System.out.println(model+“ 0);
Starting at ” v.setSpeed(10);
+getSpeed() ); v.start();
} Car v1 =new Car(2,40000);
v1.setSpeed(10);
} v1.start();
System.out.print( v1.getDut
yPrice();}
}
a) Write what would be printed out if the CarTest program was executed.
b) Comment on the following declarations
i) Car mycar= new Vehicle(“MV”,20);
ii) Vehicle v2 =new Car( 3,2000
Group D assignment due 2 November 2010
1) Given three equal sized double arrays : X, Y initialized with some non sorted numbers,
and Z . Write a Java program to get sum of corresponding elements of array X and Y
elements , and put the result into the array Z . Print all the elements in Z .
2) Given the following classes

class myQuestion {
class myProblem extends myQuestion {
protected int a; protected int c;
protected int b; public myProblem() {
public myQuestion() { c = 0;
a = 0; }
b = 0; public myProblem(int x, int y, int z) {
} super(y,z);
public myQuestion(int x, int y) { c = x;
a = x; }
b = y; public myProblem(int x, int y) {
} this();
public myQuestion(int x) { super(x,y);
this(); }
a = x; public myProblem(int x){
} c = x;
public int enquire() { }
return a + b; public int enquire() {
} c = a * b;
public int interrogate(int x) { return c;
return (a + b)* x; }
} public void display() {
public void display() { System.out.println(a + “ “ +b + “ “
System.out.println(a + “ “ + b); +c);
} }
} }

What is the output of the program segments:


What is the output of the program segments:
a) myQuestion q;
q=new myQuestion(1);
System.out.print(q.interrogate(9) + “ “); q.display();
b) myQuestion q =new myQuestion(20,2);
System.out.print(q.enquire()); q.display();
c) myProblem p; p=new myProblem(20,2);
System.out.println(p.enquire());
System.out.print(p.interrogate(2) + “ “); p.display();
d) myProblem p=new myProblem(20,2,4);
p.display(); p.enquire(); p.display();
System.out.print(q.enquire() + “ “); q.display();
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; i < x.size; i++){
System.out.println((x[i] + 1) % 3);
}
}
public static void printSequence()
{ int y[ ]={1,2,3,4,5};
for (int i = 0; i < y.size; i++){
printNext(y);}
}

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.

public class CarDriver {


public static void main String( args[]){
double duty=0.2;
TopDriver driver= new TopDriver(“Peter”)
driver.setTarget(80.90);
driver.setW( 10);

Vehicle v1= new Vehicle(“Benz”);


Vehicle v2= new Vehicle(“Mazda”);
v1.setFuelLevel(200); //litres
v1.driveMe(“Today”);
v2.setFuelLevel(20); //litres
v1.setMaximumSpeed(200); //km/hour
v2.setA( 0.98);
v2.accellerate( 11.2);
System.out.println(v2.getModel() +” costs ” +v2.getPrice( duty));

driver.drive(v1);
driver.drive(v2);
System.out.println(v1.getModel() +” has ” +v1.getFueLevel() + “ litres remaining”);
//litres
System.out.println(driver.getID() +” has travelled ” + driver.getLog() ); //km
}
}

You might also like