Question: I have also attached the code for the Vehicle Class Here is the link to the program. Let me know if you need anything. https://drive.google.com/file/d/1vfITw510EMi5WnkNmHx-7G4YU9pJeZTL/view?usp=sharing
I have also attached the code for the Vehicle Class



Here is the link to the program. Let me know if you need anything.
https://drive.google.com/file/d/1vfITw510EMi5WnkNmHx-7G4YU9pJeZTL/view?usp=sharing
This is a graded discussion: 10 points possible Discussion: Module 3 Thoughts We've covered a great deal of information so far about classes, objects, and associated concepts. Let's reflect on what we've learned and apply some of those concepts in a class of our own creation. For this discussion posting, please create a class. Your class should model something in the real world. As an example, I will create the first posting using a modified version of the Vehicle class from programming project #1. Your class should at minimum contain the following: overloaded constructors (at least two) instance variables / fields (at least two) a static field (at least one) setters and getters for all fields - or if not, explain your design decision instance methods (at least two) Please attach your class to your discussion post as in my example. In your post, explain anything that is unclear. CONSTRAINT: DO NOT MODEL THE SAME THING THAT A CLASSMATE HAS ALREADY POSTED IN THEIR CLASS. Choose something new, and try to incorporate a new twist that we haven't yet seen! Search entries or author Unread Reply o Here is my Vehicle class. Take a look and use this as a model as you build out your own class. Notes: I've gone overboard with the comments to explain what I am doing. You should have some comments but you don't need this many. I've implemented more constructors, instance variables, and so on than are required. You should feel free to include as many as you like; just be sure to hit the minimums as noted above. Let me know if you have any questions! Vehicle.java edit: as is often the case, formatting is negatively impacted when rendered via HTML. I recommend downloading the file and opening it in a text editor or IDE. public class Vehicle { // static fields (shared by entire class / all instances of class) private static int vehiclesCreated = 0; // tracks how many vehicles we've created // private fields (internal data / each instance gets its own set of variables) private int year; // year the vehicle was manufactured String make; string model; private int miles; // miles on the total odometer private int tripMiles; // miles on the trip odometer private double mpg; // miles per gallon the vehicle gets private int tires; // number of tires the vehicle uses boolean spare; // is there a spare tire? // public methods (operations) // constructors - used to create an object from the class // default (0-arg) constructor: public vehicle() { vehiclescreated++; // increment counter miles = 0; // default mileage since none was passed in tires = 4 i spare = true; // there are no real good default values for the other variables, // so let's just leave them out; they can be assigned later by setters. // we don't have to assign default values, but sometimes we might want to. } this. // overloaded constructor with arguments for all instance variables: public vehicle(int year, string make, string model, int m, int tm, double mpg, int tires, boolean spare) { vehiclesCreated++; // increment counter // assign each argument's value to the corresponding instance variable. // "this" keyword means "this object's" instance variable. // variable name without "this" refers to the parameter. // refer to the concept of "variable shadowing" to learn more about // https://en.wikipedia.org/wiki/Variable_shadowing this year = year ; this.make = make this.model = model; this.mpg = mpg; this. tires = tires ; this.spare = spare // for these two instance variables, the arguments do not have the same // thus we don't need to use the "this" keyword to differentiate the name. two. // we can if we want to - but we don't need to. // either way, the result is the same - we assign // the argument value to the instance variable. miles = m; this.tripMiles = tmi } // overloaded constructor with arguments for some instance variables: public vehicle(int year, string make, string model) { vehiclesCreated++; // increment counter this.year = year this.make = make; this.model = model ; miles // we can assign a default value if we want to } // setters (mutators) and getters (accessors) public int getyear() { return year; 1/ return THIS object's year value } publicznosa ser rear eart year) { il set THIS Object's year to argument (year) value } public int getMiles() { return miles; } // return THIS Object's miles value public void setMiles(int miles) { this.miles = miles; value // set THIS Object's miles to argument (miles) public double getMpg() { return mpg; } // return THIS Object's mpg value public void setMpg(double mpg) { this.mpg = mpg; // set THIS Object's mpg to argument public void setMpg(double mpg) { this.mpg = mpg; (mpg) value // set THIS Object's mpg to argument // etc. public String getMake() { return make; } public void setMake(String make) { this.make = make; } public String getModel() { return model; } public void setModel(String model) { this.model = model; } public int getTripiles() { return tripMiles; } public void setTripMiles(int tripMiles) { this.tripMiles = tripMiles; } public int getTires() { return tires; } public void settires(int tires) { this.tires = tires; } public boolean isspare() { return spare; } public void setspare(boolean spare) { this. spare = spare; } // we can invoke this static method using the class name and dot operator: // vehicle.getvehiclescreated(); public static int getvehiclesCreated() { return vehiclesCreated; } // don't need a setter for this; it can only be incremented by constructors. public static void setvehiclesCreated(int vehiclesCreated) { 1/ Vehicle.vehiclesCreated = vehiclesCreated; } // instance methods public void drive(int miles) this.miles += miles; miles } 1/ add argument miles value to THIS object's public void shift(char gear) { // here we might implement some code to shift gears, based on the letter // passed in (i.e. chosen by the gear shift) } public String honk() { return "HOOOOONK" // the vehicle has a deep, Loud horn sound! // return "meep!" } // or maybe it has a wimpy sounding horn? } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
