Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using java programming use a Scanner with Car Class Write a class named car that has the following fields: yearModel. The yearMode1 field is an

Using java programming

image text in transcribed

use a Scanner with

image text in transcribed

Car Class Write a class named car that has the following fields: yearModel. The yearMode1 field is an int that holds the car's year model. make. The make field is a string object that holds the make of the car, such as "Ford", "Chevrolet", "Honda", etc. speed. The speed field is an int that holds the car's current speed In addition, the class should have the following methods. - Constructor. The constructor should accept the car's year model and make as arguments. These values should be assigned to the object's yearMode1 and make fields. The constructor should also assign 0 to the speed field. Accessor. The appropriate accessor methods get the values stored in an object's yearMode1, make, and speed fields. accelerate. The accelerate method should add 5 to the speed field each time it is called. . brake. The brake method should subtract 5 from the speed field each time it is called Demonstrate the class in a program that creates a car object, and then calls the accelerate method five times. After each call to the accelerate method, get the current speed of the car and display it. Then, call the brake method five times. After each call to the brake method, get the current speed of the car and display it. @Before public void setUp() car new Car (2015 "Ford Edge) ) Tears down the test fixture. Called after every test case method. t/ @After public void tearDown) @Test public void testGetYearModel) assertEquals (2015, car.getYearModel)); ) @Test public void testGetMake() assertEquals( "Ford Edge", car getMake()); ) @Test public void testGetSpeed ( assertEquals (0, car.getSpeed ()): ) @Test public void testAccelerate) f car.accelerate(); assertEquals (5, car.getSpeed()); car..accelerate); assertEquals (10, car getSpeed()) @Test public void testBrake() car setSpeed (20): car.brake(O: assertEquals (15, car.getSpeed ))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 1 Lncs 8055

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013 Edition

3642402844, 978-3642402845

More Books

Students also viewed these Databases questions