Purchase Solution

Java Class Car and CarTest

Not what you're looking for?

Ask Custom Question

Design a Java class named Car with the following fields:
- yearModel,
- make: references a string,
- speed: holds the car's current speed.

In addition, it should also have the following constructor and other methods:
- Constructor: should assign 0 to the speed field, accept the year model and make as arguments which are assigned to the object's yearModel and make fields respectively.
- Accessors: methods to get the values stored in yearModel, make and speed fields.
- accelerate: method should add 5 to the speed field each time it is called.
- brake: should subtract 5 from the speed field when called.

Also design a test program that creates a Car object, then calls the accelerate method five times, and after each call gets the current speed of the car and displays it. Then it calls the brake method five times, and after each call gets the current speed and displays it.

Purchase this Solution

Solution Summary

Solution consists of two files: Car.java that implements class Car, and CarTest.java that implements a test program to test this Car class.

Java and Java compiler (javac) version 1.7.0_45 were used during development and testing of this solution.

Solution Preview

Attached 585315.zip contains two files -

Car.java : implements class Car, and
CarTest.java : implements test program to test class Car.

Java and Java compiler (javac) version 1.7.0_45 were used during development and testing of this solution.

Here is how you can compile and execute the CarTest ...

Purchase this Solution


Free BrainMass Quizzes
C++ Operators

This quiz tests a student's knowledge about C++ operators.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Basic Networking Questions

This quiz consists of some basic networking questions.

C# variables and classes

This quiz contains questions about C# classes and variables.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.