Car - {make = m;} /*step 6: The setSpeed method has one...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/** Car class Chapter 6, Programming Challenge 2 */ //step 1: Create the header for the class named Car public class Car {//beginning of body //step2: declare three fields as page 359, question 2 int yearModel; String make; int speed; /*step3 Write a constructor that initializes the car's year model and make. It accepts the car's year model and make as argument. These values should be assigned to The car's yearModel and make fields. The constructor should assign 0 to the speed field. */ public Car (int year, String m) {make = m; speed = 0; yearModel = year;} /* step4: The setYearModel method has one parameter and sets the car's year model with the parameter y. */ public void setYearModel(int year) {yearModel = year;} /*step5: The setMake method has one parameter and sets the car's make. with the parameter */ public void setMake(String m)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: {make = m;} /*step 6: The setSpeed method has one parameter and sets speed with the parameterset . */ public void setSpeed(int s) {speed = s;} /*step 7: The getYearModel method returns the car's year model. @return The car's year model. */ public int getYearModel() {return yearModel;} /*step 8: The getMake method returns the car's make. @return The car's make. */ public String getMake() {return make;} /*step 9: The getSpeed method returns the car's current speed. @return The car's current speed. */ public int getSpeed() {return speed;} /*step 10: The accelerate method increases the car's speed by 5 MPH. */ public void accelerate() {speed +=5;} /*step 11: The brake method decreases the car's speed by 5 MPH. */ public void brake() {speed -=5;} }//end of class Car...
View Full Document

This note was uploaded on 12/02/2008 for the course CSCI 1301 taught by Professor Liu during the Spring '08 term at GCSU.

Page1 / 2

Car - {make = m;} /*step 6: The setSpeed method has one...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online