Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m in java one and need help with this code. please follow the directions give

ID: 3690205 • Letter: I

Question

I'm in java one and need help with this code. please follow the directions given and test your program to make sure it works as it is required. I will apreciate your help. thank you.please use the given code as it is just fill the missing information to complete the program. thank you

here is the code   

cp ~lkoperski/1404_Lab/Exercises/Exercise13.java .

Programming Concepts

1. Classes

2. Objects

Exercise Location

For this exercise, you will copy a program from my directory into yours. It doesn't matter what directory this exercise is located in. You will need to copy this command and paste it into Loki:

cp ~lkoperski/1404_Lab/Exercises/Exercise13.java .

Exercise Description

You will be implementing a Car object. The Exercise13.java file is the driver file that creates an instance of the Car object, and your job is to create a file called Car.java, given the following UML diagram.

- make : String
- model : String
- fuel : Integer
- miles : Integer
- lightsOn : Boolean

+ << Constructor >> Car ( ma : String, mo : String, f : Integer, mi : Integer, l : Boolean )

+ drive ( mi : Integer )
+ getMake ( ) : String
+ getModel ( ) : String
+ getFuel ( ) : Integer
+ getMiles ( ) : Integer
+ getLightsOn ( ) : Boolean + setMake ( ma : String )

+ setModel ( mo : String )
+ setMiles ( mi : String )
+ setFuel ( f : Integer )
+ setLightsOn ( l : Boolean )

To compile the program, you can issue the command javac Exercise13.java, which will compile both the Exercise13.java file and the Car.java file.

Note: The l in setLightsOn() is the lowercase letter l, and not the number 1, or the uppercase letter I.

Note: You will not use all of the methods created, but just keep in mind that getters and setters generally exist for every class variable defined.

Description for the constructor

1. You simply just need to assign the class variables to the variables that were passed as parameters.

Description for the getters and setters

1. For each getter, you just need to return the value. For example, for getFuel(), you just need to return fuel.

2. For each setter, you just need to assign the class variable to the variable that was passed as the parameter. For example, for setFuel ( int f ), you just need to do fuel = f.

Description for the drive() method

1. The implementation of the getters and setters is straightforward. For the drive()method, it takes in the number of miles driven as an argument.

2. The number of miles that was passed to the method needs to be added to the class variable miles.

3. This car will get 30 miles per gallon, meaning, for every 30 miles the car has driven, you need to subtract one gallon of fuel from the class variable fuel.

a. You can use a loop and the modulus operator to determine how many times fuel needs to be decremented.

b. For example, if the number of miles driven is 90, then fuel should decrement by 3. If the number of miles driven is 30, then fuel should decrement by 1. If the number of miles driven is 100, then fuel should decrement by 3. If the number of miles driven is 200, then fuel should decrement by 6.

c. Don't worry about accounting for remainders. Obviously, 200 isn't divisible by 30, but don't take away 2/3rds of a gallon of fuel from the distance of 180 to 200. 30 can go into 200 at least 6 times, but not more, so you should decrement fuel only by 6. We're only dealing with integers.

User input is underlined

user@loki:~$ java Exercise12

Just created a new car!

Make: Ford

Model: T
Fuel: 10
Miles: 0
Lights On: false

About to drive 200 miles.

Make: Ford

Model: T
Fuel: 3
Miles: 200

Lights On: false

It's dark outside! About to turn the lights on.

Make: Ford

Model: T
Fuel: 3
Miles: 200

Lights On: true

About to refuel.

Make: Ford

Model: T
Fuel: 10

Miles: 200

Lights On: true

car

- make : String
- model : String
- fuel : Integer
- miles : Integer
- lightsOn : Boolean

+ << Constructor >> Car ( ma : String, mo : String, f : Integer, mi : Integer, l : Boolean )

+ drive ( mi : Integer )
+ getMake ( ) : String
+ getModel ( ) : String
+ getFuel ( ) : Integer
+ getMiles ( ) : Integer
+ getLightsOn ( ) : Boolean + setMake ( ma : String )

+ setModel ( mo : String )
+ setMiles ( mi : String )
+ setFuel ( f : Integer )
+ setLightsOn ( l : Boolean )

Explanation / Answer

public class Car {

   private String make;
   private String model;
   private int fuel;
   private int miles;
   private boolean lightsOn;
   Car(String ma,String mo,int f,int mi,boolean l){
       make=ma;
       model=mo;
       fuel=f;
       miles=mi;
       lightsOn=l;
   }
   public String getModel() {
       return model;
   }
   public void setModel(String mo) {
       model = mo;
   }
   public int getFuel() {
       return fuel;
   }
   public void setFuel(int f) {
       fuel = f;
   }
   public int getMiles() {
       return miles;
   }
   public void setMiles(int mi) {
       miles = mi;
   }
   public boolean isLightsOn() {
       return lightsOn;
   }
   public void setLightsOn(boolean l) {
       lightsOn = l;
   }
   public String getMake() {
       return make;
   }
   public void setMake(String ma){
       make=ma;
   }
   public void drive(int mi){
       miles+=mi;
       for(int i=1;i<=miles;i++){
           if(i%30==0){
               fuel-=1;
           }
       }
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote