motorcar_example

motorcar_example - Refer to Example 1, motor car. Write a...

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: Refer to Example 1, motor car. Write a class called MotorCar . Include: a) Fields make, model, maximum speed, and tank capacity. b) A constructor that initializes these fields. c) Accessor methods that return the value of each variable. d) Mutator methods - addPetrol that adds petrol in the tank, and drive that reduces the petrol by some amount. Remember the conventions for naming the class, variables, and methods Define a test class called TestMotorCar . Create two objects car1 and car2 with initial values shown in the table below Make Model Maximum speed Capacity car1 Ford Mustang 120 mph 15 gallons car2 Toyota Corolla 150 mph 12 gallons 1. public class MotorCar 2. { 3. 4. } // Adding the variables 1. public class MotorCar 2. { 3. private String make, model; 4. private double engine, max_speed, tank; 5. } // Adding the constructor 1. public class MotorCar 2. { 3. private String make, model; 4. private double engine, max_speed, tank; 5....
View Full Document

Page1 / 4

motorcar_example - Refer to Example 1, motor car. Write a...

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