Making Decisions/Mars Rover 2
CS 305J

Due:  10/26/04 (at 10:00pm)
50 points


Mars Rover (again)

Mars Rover

Create a class called MarsRover2. The rover will have certain properties:

A name (e.g. Opportunity)
A fuel efficiency (feet per electric unit)
A fuel amount (in electric units)
An Odometer that keeps track of the total distance the rover has driven (in feet)
A variable that contains the current state of the solar panel (visible or not visible)
A direction that the rover is facing encoded as an integer (0-North, 1-East, 2-South, 3-West)
A current x location (a double)
A current y location (a double)

You must write several methods for this class.

A constructor that takes as parameters, the name of the rover and its fuel efficiency (as a double).
public MarsRover2 (String name, double roverFuelEfficiency)

A constructor that takes as parameters, the name of the rover, its fuel efficiency (as a double), its starting x position, and starting y position.
public MarsRover2 (//fill in as necessary)

A method called reCharge that charges the fuel cell. You will gain 0.536 electric units for each hour of recharging. Note: The solar panel must be deployed and visible before charging.
public void reCharge (double hours)

A method called moveRover that simulates the rover moving a certain number of feet. (Of course, the odometer should move forward that many feet  and the fuel cell charge amount should go down.)
Note:
1) The rover can't move if the solar panel is visible. You must fold the solar panel before moving the vehicle.
2) You also need to update the x,y location of the rover. Assume that moving north will be in the positive y direction. It is ok for the rover to have negative coordinates. Assume each foot is a unit in the x,y system.
3) Remember that the rover can't move after the fuel cell charge reaches zero.  If the rover is asked to move further than the current fuel will allow, move the rover as far as possible.
public void moveRover (double feet)

A method called getChargeLevel that returns the current number of electrical units (a double).
public double getChargeLevel ()

A method called getOdometer that returns the total number of feet the rover has moved (a double).
public double getOdometer()

A method called deploySolarPanel that changes the current state of the solar panel to visible.  Deploying the solar panel if it is already deployed will cause the rover to become confused. Always check to make sure the panel is not deployed before deploying.
public void deploySolarPanel()

A method called foldSolarPanel that changes the current state of the solar panel to not visible. Folding the solar panel if it is already folded will cause the rover to become confused. Always check to make sure the panel is not folded before folding.
public void foldSolarPanel()

YOU WILL NEED MORE METHODS!!


1) Name the file MarsRover2.java.

2) Remember that you can't move the rover if it runs out of charge. You can assume that the rover will retain enough charge to deploy the solar panel.

3) Write a test program to see if your MarsRover2 class works. You don't have to hand in the test/driver program. We will create a program of our own to test your code. Where provided, you must use the exact method names and signatures listed above. You will have to come up with some parameter lists yourselves.

4) You will not have a "main" method in the MarsRover2 class because it will only serve to create rover objects for another program. 

5) Each method should have a short comment block that explains what the method does, including any properties of the object that are changed.

6) You should have an accessor method for every instance variable.

7) You need a method to change the direction the rover is facing.



You will do this program by yourselves. I encourage discussion about what the assignment means or clarification, but please come up with your own algorithms and code. Lab proctors, tutors, TAs, and I can help with syntax and logic errors, but please try to do as much as you can by yourself first. 


Last Updated: 9/28/04