Question

In: Computer Science

We started creating a Java class for Car. In this lab we are going to complete...

We started creating a Java class for Car. In this lab we are going to complete it in the following steps:
1- First create the Car class with some required instance variables, such make, model, year, price, speed,
maxSpeed, isOn, isMoving, and any other properties you like to add.
2- Provide couple of constructors for initializing different set of important properties, such as make,
model, year, and price. Make sure that you do not repeat initialization of instance variables in every
constructor, and instead call one constructor from another one when needed to prevent code
repetition.
3- Provide required accessor (getter) and mutator (setter) methods. Especially, accelerate, decelerate,
turnOn, turnoff, stop, etc.
4- Test the class by creating a tested class. Inside the tester class, create couple of Car’s instance objects
and change their statuses by calling corresponding methods, and compare the actual and expected
outputs.
5- Provide standard Java documentation for the Car class and create the html for the documentation.
6- Modify the Car class by adding properties, fuel efficiency, measured in liters/km, and a certain
amount of fuel in the gas tank. Provide a constructor to initialize a specific fuel efficiency and also
the initial fuel level as 0. Supply a method drive that simulates driving the car for a certain distance,
reducing the amount of gasoline in the fuel tank. Also, supply methods getGasInTank, returning the
current amount of gasoline in the fuel tank, and addGas, to add gasoline to the fuel tank.
You may assume that the drive method is never called with a distance that consumes more than the
available gas. After implementation the class, test it again in the CarTester class that tests all the new
methods.

Solutions

Expert Solution

public class Car {
        
        private String make;
        private String model;
        private int year;
    private int price;
        private double speed;
        private double maxspeed;
        
        

        public Car(String make, String model, int year, double speed, double maxspeed) {
                this.make = make;
                this.model = model;
                this.year = year;
        this.speed = speed;
                this.maxspeed = maxspeed;
        }
        
        public void printInfo(){
                System.out.println("Print information about the car:");
                System.out.println("Make: " + this.make);
                System.out.println("Model: " + this.model);
                System.out.println("Year: " + this.year);
                System.out.println("speed: " + this.speed);
                System.out.println("maxspeed: " + this.maxspeed);
        System.out.println();
        }

        public void isOn(){
                System.out.println("Car is on.");
        }
        
        public void isMoving() {
                System.out.println("Car is moving.");
        }

        public String getmake() {
                return make;
        }

        public String getModel() {
                return model;
        }

        public int getYear() {
                return year;
        }
        public double getspeed() {
                return speed;
        }
        public double getmaxspeed() {
                return maxspeed;
        }

        public void setspeed(int maxspeed) {
                this.maxspeed = maxspeed;
        }
    public void accelerate(){
        speed += 5;
        //if (speed >= 0) && (speed <= maxspeed)
    }
    public void brake(){
        speed -= 5;
    }

        
}

Related Solutions

In C++ In this lab we will be creating a stack class and a queue class,...
In C++ In this lab we will be creating a stack class and a queue class, both with a hybrid method combining linked list and arrays in addition to the Stack methods(push, pop, peek, isEmpty, size, print) and Queue methods (enqueue, deque, peek, isEmpty, size, print). DO NOT USE ANY LIBRARY, implement each method from scratch. Both the Stack and Queue classes should be generic classes. Don't forget to comment your code.
In Java In this lab we will creating two linked list classes: one that is a...
In Java In this lab we will creating two linked list classes: one that is a singly linked list, and another that is a doubly linked list ( This will be good practice for your next homework assignment where you will build your own string class using arrays and linked list ) . These LinkedList classes should both be generic classes. and should contain the following methods: Print Add - Adds element to the end of the linked list. IsEmpty...
For today's lab we will be using the Car Object Class which we built in Lab...
For today's lab we will be using the Car Object Class which we built in Lab 1. I have attached my solution if you would prefer to use my solution instead of your own solution. We will working on remembering how to build sub-classes and user interfaces. So we will be creating new Java files for: An Interface called GreenHouseGasser Requires a method called CO2() which returns how much carbon dioxide the Object produces. Make sure to update Car so...
For this homework we are going to walk you through creating a class. Lets look at...
For this homework we are going to walk you through creating a class. Lets look at a pizza restaurant and create a class for this. We will call our class pizza. The goal for every class is to include everything that has to happen for that class in 1 place. So whenever we create a class we need to think of what the nouns or variables will be for that class and then what the actions or methods will be...
Lab 1 – Databases, Schemas, and Basic Tables For this lab we will be creating a...
Lab 1 – Databases, Schemas, and Basic Tables For this lab we will be creating a small Student Loan Database. Make sure to open your screenshot word document. Include the required screenshots of your code in the document. Database: Create a new database: StudentLoan_LastName. Schemas: Create the following schemas. Make sure to screenshot and run your code: 1. Student 2. Guarantor 3. Institution 4. Activity 5. Loan 6. Lender Tables: First complete the word document for designing the tables like...
Lab to be performed in Java. Lab: 1.) Write a class named TestScores. The class constructor...
Lab to be performed in Java. Lab: 1.) Write a class named TestScores. The class constructor should accept an array of test scores as its argument. The class should have a method that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an IllegalArgumentException. Write a driver class to test that demonstrates that an exception happens for these scenarios 2.) Write a class named InvalidTestScore...
Begin by creating a Java project with one class – Addition. Start with the class Addition...
Begin by creating a Java project with one class – Addition. Start with the class Addition as shown in Figure 12.2. This program uses dialog boxes for I/O to get two integers and display the result of adding them together. The program should run “as is”. Change the program so that it gets and adds two doubles instead of integers. When that is working get a third double using a dialog box. Add the three doubles together, and display the...
JAVA CODING PLEASE Create a class SportsCar that inherits from the Car class (CAR CLASS LISTED...
JAVA CODING PLEASE Create a class SportsCar that inherits from the Car class (CAR CLASS LISTED BELOW THIS QUESTION). Include the following: A variable Roof that holds the type of roof (Ex: Convertible, Hard-Top, Soft-Top) A variable Doors that holds the car’s number of doors (Ex: 2, 4) Implement the ChangeSpeed method to add 20 to the speed each time it is called. Add exception handling to the ChangeSpeed method to keep the speed under 65. Implement the sound method...
In the previous lab you created a Car class and a Dealership class. Now, in this...
In the previous lab you created a Car class and a Dealership class. Now, in this activity change the design of the Dealership class, in which the list of the cars inside a dealership will be stored in an ArrayList. Then, provide required getter and setter methods to keep the records of all its cars. In your tester class, test your class and also printout the list of all cars of a given dealership object. // Java program import java.util.ArrayList;...
Lab 8 Acid Base Properties of Solutions Lab Report Worksheet In today’s lab we are going...
Lab 8 Acid Base Properties of Solutions Lab Report Worksheet In today’s lab we are going to utilize a simulation to determine the pH of various salt solutions. We will then use those pH values to determine concentrations of hydronium and Hydroxide in solutions. From there we will determine the Ka or Kb Pre-Work: In the table below, use just the salt formula to identify the salt as acidic, basic, or neutral. Table 1: Acidic, Basic, or Neutral Salt Predictions...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT