Q BgQuestion:

      
Novice
Karma Points: 37
Respect (79%):
posted by  Al3x 84 on 11/5/2009 8:06:32 PM  |  status: Closed  |  Earned Karma: 37

Java !Please help! will rate livesaver...

Course Textbook Chapter Problem Needs by
N/A N/A N/A N/A 11/6/2009 at 11:00:00 AM
Question Details:
I need help to set up a code according to the following specifications...
 

To accomplish these objectives, it is  required the implementation and the utilization of a class Car and of a class CarTest.

Project Specification

2.1 Class Car specification

The following self describing instance variables should be defined for the class Car:

make (of type String)

model (of type String)

year (of type integer)

price (of type integer)

The class Car should define the following methods:

four get type methods (getMake, getModel, getYear, getPrice), each returning the value of the corresponding instance variable.

setPrice for setting a new price for the car. The new price is specified as method parameter.

print for displaying car's specific data. When the print method is invoked, the make, model, year and price values should be displayed on the screen, each on a separate line.

The class Car also defines a default constructor and a constructor with parameters.

The default constructor builds Car objects with the following values of their instance variables: "Ford" for make, "Mondeo" for model, 2009 for year and 19,900 dollars for price.

The constructor with parameters builds and initializes a car object based on constructor parameters.

Bonus Point Alert! Earn +7 additional karma points for helping this gold member.

AAnswers:

Answer Question Ask for clarification
Oracle
Karma Points: 18,820
posted by Marth on 11/5/2009 8:26:59 PM  |  status: Live
Asker's Rating: Lifesaver   
Response Details:
public class Car
{
      // instance fields
      private String make;
      private String model;
      private int year;
      private int price;

      // constructors
      public Car()
      {
            this("Ford", "Mondeo", 2009, 19900);
      }
      public Car(String make, String model, int year, int price)
      {
            this.make = make;
            this.model = model;
            this.year = year;
            this.price = price;
      }

      // accessors
      public String getMake()
      {
            return make;
      }
      public String getModel()
      {
            return model;
      }
      public int getYear()
      {
            return year;
      }
      public int getPrice()
      {
            return price;
      }

      // print
      public void print()
      {
            System.out.println(toString());
      }
      public String toString()
      {
            return getMake()+"\n"+getModel()+"\n"+getYear()+"\n"+getPrice();
      }

      // modifiers
      public void setPrice(int price)
      {
            this.price = price;
      }
}




Thank you for rating my response. Feel free to PM me if you have further questions.

Java Genius

"Lois Lane is falling, accelerating at an initial rate of 32ft per second per second. Superman swoops down to save her by reaching out two arms of steel. Ms. Lane, who is now traveling at approximately 120 miles per hour, hits them, and is immediately sliced into three equal pieces." - Sheldon
Answer Question Ask for clarificarion

Join Cramster's Community

Cramster.com brings together students, educators and subject enthusiasts in an online study community. With around-the-clock expert help and a community of over 100,000 knowledgeable members, you can find the help you need, whenever you need it. Join for free today » How Cramster is different from tutoring »