Design Question

Hello all

I have an exam tomorrow on Program Design and OOP Concepts. The majority of the exam will consist of questions that test your ability in distinguishing between terms. This will be the easy part. However, the more difficult portion of the test will contain a free response problem of multiple parts called a "design question."

Can you verify if I am doing this correctly:

Design a class to represent CAR. Instance variables stored about a car should be:

1. the make(Toyota, Ford)
2. mileage
3. the total gallons used
4. whether the car is an economy model, a moderately fuel efficient car or a gas guzzler.
5. miles per gallon
6. vehicle weight

Clients of this class should be able to access to find out the value of all attributes about a car. Clients should be able to modify instance variables 1, 2, 3, and 6. In writing the design, do not write any code. Just declare the instance variables and write the header for the methods.

My code:
Code:
public class Car {

private string make;
private double mileage;
private double totalgal;
private string classcar;
private double milespergal;
private double vehicleweight;
private double milespergallon;

public string getMake {
.
.
.

public double mileage {

.
.
.
I am not sure if I am doing this correctly. Do I put accessors and modifiers for each of the methods? How would I call the methods?

Any help is greatly appreciated

Thanks!
 
Last edited:
32,106
3,989
Hello all

I have an exam tomorrow on Program Design and OOP Concepts. The majority of the exam will consist of questions that test your ability in distinguishing between terms. This will be the easy part. However, the more difficult portion of the test will contain a free response problem of multiple parts called a "design question."

Can you verify if I am doing this correctly:

Design a class to represent CAR. Instance variables stored about a car should be:

1. the make(Toyota, Ford)
2. mileage
3. the total gallons used
4. whether the car is an economy model, a moderately fuel efficient car or a gas guzzler.
5. miles per gallon
6. vehicle weight

Clients of this class should be able to access to find out the value of all attributes about a car. Clients should be able to modify instance variables 1, 2, 3, and 6. In writing the design, do not write any code. Just declare the instance variables and write the header for the methods.

My code:
Code:
public class Car {

private string make;
private double mileage;
private double totalgal;
private string classcar;
private double milespergal;
private double vehicleweight;
private double milespergallon;

public string getMake {
.
.
.

public double mileage {
.
.
.
I am not sure if I am doing this correctly.
There are several problems with your code. You have more properties than the problem asks for (you have a miles-per-gallon property twice). Also, your headers for the accessor methods are not correct -- they are missing the parentheses for the argument list.
courtrigrad said:
Do I put accessors and modifiers for each of the methods?
According to the problem description, you need get accessors for each of the six properties, but you need set accessors only for properties 1, 2, 3, and 6.
courtrigrad said:
How would I call the methods?
Your textbook or notes should have examples of how a client of the class would use the methods on the class.
 

Want to reply to this thread?

"Design Question" You must log in or register to reply here.

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving
Top