The objective of this assignment is to implement a Car class.
First, create a new project in your IDE, call it CarPro, and add a class called Car.
The Car class should have the following instance variables:
int nsLocation; //distance North or South (North is positive)
int ewLocation; // distance East or West ( East is positive)
int orientation; // 0=N, 1=E, 2=S, 3=W
It should have a constructor that takes an orientation, a nsLocation and an ewLocation.
The only public behaviours (methods) that it should have are to travel, turnRight, turnLeft, showLocation and getNsLocation.
void travel (int distance) // distance in kms to travel(doesnâ??t change orientation of Car)
void turnRight() // turn car 90 degrees to the right
void turnLeft() // turn car 90 degrees to the left
void showLocation() // show (print to the screen) the current nsLocation, ewLocation
// and orientation of the Car
int getNsLocation() // return the current position of the Car in the North/South axis.
Next, to test your class Car, create another class called CarDriver that contains a main method. The code in the main method of CarDriver class should create two Car objects, one called honda and one called toyota.
The toyota should start at location 1 North, 2 East and facing South.
The honda should start at location 0 North, 0 East and facing West.
The main method of CarDriver should contain also these car navigation instructions:
For (int i=0;i<3;i++){
honda.travel(i+2);
honda.turnRight();
toyota.turnLeft();
toyota.travel(i+ honda.getNsLocation());
The main method should print out the final details of both carâ??s locations and orientations. At what location and facing in what direction do the Cars end up? Your code should provide data hiding and only allow the car object behaviors that are given above. Finally, you must submit a compressed file of your project including the source code on Blackboard. Also you will demonstrate your work by running your program in the lab.
I want answer for this Q.lolo November 30, 2011 at 10:27 PM
The objective of this assignment is to implement a Car class. First, create a new project in your IDE, call it CarPro, and add a class called Car. The Car class should have the following instance variables: int nsLocation; //distance North or South (North is positive) int ewLocation; // distance East or West ( East is positive) int orientation; // 0=N, 1=E, 2=S, 3=W It should have a constructor that takes an orientation, a nsLocation and an ewLocation. The only public behaviours (methods) that it should have are to travel, turnRight, turnLeft, showLocation and getNsLocation. void travel (int distance) // distance in kms to travel(doesnâ??t change orientation of Car) void turnRight() // turn car 90 degrees to the right void turnLeft() // turn car 90 degrees to the left void showLocation() // show (print to the screen) the current nsLocation, ewLocation // and orientation of the Car int getNsLocation() // return the current position of the Car in the North/South axis. Next, to test your class Car, create another class called CarDriver that contains a main method. The code in the main method of CarDriver class should create two Car objects, one called honda and one called toyota. The toyota should start at location 1 North, 2 East and facing South. The honda should start at location 0 North, 0 East and facing West. The main method of CarDriver should contain also these car navigation instructions: For (int i=0;i<3;i++){ honda.travel(i+2); honda.turnRight(); toyota.turnLeft(); toyota.travel(i+ honda.getNsLocation()); The main method should print out the final details of both carâ??s locations and orientations. At what location and facing in what direction do the Cars end up? Your code should provide data hiding and only allow the car object behaviors that are given above. Finally, you must submit a compressed file of your project including the source code on Blackboard. Also you will demonstrate your work by running your program in the lab.
javagaurav January 7, 2012 at 9:20 PM
how to set the value of data base in jtable
Post your Comment