Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java In this assignment, you will create a Java program containing three classes named Gas Tank Engine, and Car. These classes will be used to

Java image text in transcribed
image text in transcribed
image text in transcribed
In this assignment, you will create a Java program containing three classes named Gas Tank Engine, and Car. These classes will be used to create Cur objects which can execute methods to compute locations and fuel levels after driving given distances and directions. 1. The Gas Tunk class represents an object to keep track of the current and maximum levels of fuel. It must: have a private instance variable that keeps track of an integer (maximum) capacity have a private instance variable that keeps track of a double (current) level have a constructor which takes one argument, an int, which is used to set the instance variable for capacity (but Ifa negative value is passed in it gets set to o), while the current level is initialized to have the following member functions implemented: public int getCapacity) publie double gettive) pubide void settovel (double levelin) the "get" functions should return the capacity and level a the "set" function should take a double argument to set the level, but if the argument is below it gets set to 0, or above the capacity it gets set to the capacity 2. The Engine class represents an engine object and stores a few attributes of the engine. It must: o have a private instance variable which stores a String description of the engine (es. "V) o have a private instance variable that keeps track of the integer miles per gallon (mp) value have a private instance variable that keeps track of the integer maximum speed value o have a constructor which takes three arguments (a String and 2 intepers) which are used to initialize the three instance variables. If the String argument has length 0, the description should be set to the value "Generic engine and if either integer argument is negative, the corresponding instance variable should be set to 0. - have public get" functions to return each of the description, mpe, and max speed. The function that returns the description should return the String description as well as the mpg and max speed.clearly labeled (et. "V (MPG: 20. Max speed: 120) 3. The Car class represents a car object which contains an engine and a gas tank, and has methods that allow it to keep track of its location and fuel level while being driven". It must have a private instance variable which stores a String description of the car le Sweet Ride") have private instance variables that keep track of integer values for the xcoordinate and coordinate and are Initialized to 0) . have a private instance CasTank variable live private instance Engine variable have a constructor which takes as arguments String description, an integer for the maximum fuel capacity, and an Engine object reference in that order). If the description is length, the corresponding instance variable should be set to "Generic car", and if u null reference is passed in for the Engine parameter, a new Engine should be created with an empty description and os for all values have the following member functions implemented: pering gert Description public int et 3. The Car class represents a car object which contains an engine and a gas tank, and has methods that allow it to keep track of its location and fuel level while being driven". It must: o have a private instance variable which stores a String description of the car (e.g. "Sweet Ride") have private instance variables that keep track of integer values for the x-coordinate and y-coordinate and are Initialized to 0) have a private instance Gas Tank variable o have a private instance Engine variable o have a constructor which takes as arguments a String description, an integer for the maximum fuel capacity, and an Engine object reference in that order). If the description is length 0, the corresponding instance variable should be set to "Generic car", and if u null reference is passed in for the Engine parameter, a new Engine should be created with an empty description and O's for all values . have the following member functions implemented: public String getDencription public int getX) poble int getY puble double get.Puellavalt public int getG) public void tillUp! poblia int got. Maxfpeed) pable double drivetint distance, double ratio, double yol getDescription() should return the description of the car as well as the description of its Engine, fuel level and capacity, and location, all clearly labeled (eg. "Sweet Ride (engine: V6 (MPG: 20. Max speed: 120)), fuel: 0.00/15, location: (0.0)") fillUp should cause the gas tank to be filled to its maximum capacity o drive(int distance, double xRatio, double y Ratio) should take the desired distance to travel as an integer, and two double values which, together, specify the direction as a ratio of horizonal to vertical distances. For example, if Ratio 1 and Ratio - 2. for every 1 unit to the right (positive x), the car would travel 2 units up (positive y). Negative values for Ratio and Ratio correspond to moving left and down, respectively. Given the distance and direction, this method should correctly compute the ending coordinates (luncated to integers). It should also correctly subtract the amount of fuel used. If the distance specified requires greater than the amount of fuel than the car currently has the car should travel as far as it can antil it is empty and print this text to the console: "Ran out of as her driving smiles." (with the correct value substituted in for x). The method should return the number of miles which were actually driven All double values which are printed out to the console should be formatted so that exactly 2 decimal places are displayed 4. Test your work. An example class named CarTest.java is provided (on the course site along with assignment 2) to help you test your code. Your classes must work with it, i.e. they must all compile correctly together and CarTest.java should work correctly when executed. However, when grading we will use more and/or different test cases, so you should also test various additional cases. Do not submit CarTest.java. Here is the output that my implementation gives with this file: Tank levelt 10.00 Enginelt V6 (PG1 20, Max speed: 120) CariCarl (engine: V6 (MPG: 20. Max npeedt 120>), tuoli 0.00/15, location (0,0) Car2 Generic car (enginet Generse engine (MPG 0, Max speedt 0)), fuel. 0.00/0, locations (0,0) Cart Card. (engine V6 (MTO: 20. Max speed: 120)), fuel 0.00/50, location: (0,0) Car3: Car3 engino V6 (MPG1 20, Max speed: 120), fuelt 50.00/50, location (0,0) Card drove 600.00 milen Cart Card (onginer V6 DMPG 20, Max speed: 120), fuell 20.00/50, location (-400,-360) Car) drove 300.00 miles Car3: Cnt) (engine 16 MPC 20. Max speed 120%), fuel: 5.00/50, location (-230.-193) Ran out of gas after driving 100.00 miles. car) drove 100.00 miles card card (ongine 26 (MPG 20, Max speedt 1203), fuel 0.00/50, location: (-130.-193) Card drove a total of 1000.00 miles. Card Card (engine V4 (H 30, Max apeod 100), foelt 0.00/30, loontlan (0,0) Carti Care (engine V4 MG 30, Max speedi 1003). tuelt 30.00/30, lovation (0,0) Card drove 100.00 miles Car Card engine RP 30, Max speed: 100): fuel 26.67/30, local. Loni (70.7a> Card drove 200.00 miles Card Card engine XMP 20, Max peedi 1001), fuel: 20.00/30, location (-115,144) Card drove 300.00 miles Card Card engine 30. Max speedt 1007) Fuel: 10.00/30, location (255,270). an out of gas after driving 300.00 miles. Card drove 300.00 miles Car Caxs engine (MPG 30. Max speeds 100fuel 0.00/30, louation (207,9) an out of an after driving 0.00 miles. Card drove 0.00 miles Card Cartoni V4 (HPO 30 Max speedi 1001). U 0.00/30, location (2079) Car drove total of 900,00 Iles. Note that if your values are within 1.0. that is sufficient In this assignment, you will create a Java program containing three classes named Gas Tank Engine, and Car. These classes will be used to create Cur objects which can execute methods to compute locations and fuel levels after driving given distances and directions. 1. The Gas Tunk class represents an object to keep track of the current and maximum levels of fuel. It must: have a private instance variable that keeps track of an integer (maximum) capacity have a private instance variable that keeps track of a double (current) level have a constructor which takes one argument, an int, which is used to set the instance variable for capacity (but Ifa negative value is passed in it gets set to o), while the current level is initialized to have the following member functions implemented: public int getCapacity) publie double gettive) pubide void settovel (double levelin) the "get" functions should return the capacity and level a the "set" function should take a double argument to set the level, but if the argument is below it gets set to 0, or above the capacity it gets set to the capacity 2. The Engine class represents an engine object and stores a few attributes of the engine. It must: o have a private instance variable which stores a String description of the engine (es. "V) o have a private instance variable that keeps track of the integer miles per gallon (mp) value have a private instance variable that keeps track of the integer maximum speed value o have a constructor which takes three arguments (a String and 2 intepers) which are used to initialize the three instance variables. If the String argument has length 0, the description should be set to the value "Generic engine and if either integer argument is negative, the corresponding instance variable should be set to 0. - have public get" functions to return each of the description, mpe, and max speed. The function that returns the description should return the String description as well as the mpg and max speed.clearly labeled (et. "V (MPG: 20. Max speed: 120) 3. The Car class represents a car object which contains an engine and a gas tank, and has methods that allow it to keep track of its location and fuel level while being driven". It must have a private instance variable which stores a String description of the car le Sweet Ride") have private instance variables that keep track of integer values for the xcoordinate and coordinate and are Initialized to 0) . have a private instance CasTank variable live private instance Engine variable have a constructor which takes as arguments String description, an integer for the maximum fuel capacity, and an Engine object reference in that order). If the description is length, the corresponding instance variable should be set to "Generic car", and if u null reference is passed in for the Engine parameter, a new Engine should be created with an empty description and os for all values have the following member functions implemented: pering gert Description public int et 3. The Car class represents a car object which contains an engine and a gas tank, and has methods that allow it to keep track of its location and fuel level while being driven". It must: o have a private instance variable which stores a String description of the car (e.g. "Sweet Ride") have private instance variables that keep track of integer values for the x-coordinate and y-coordinate and are Initialized to 0) have a private instance Gas Tank variable o have a private instance Engine variable o have a constructor which takes as arguments a String description, an integer for the maximum fuel capacity, and an Engine object reference in that order). If the description is length 0, the corresponding instance variable should be set to "Generic car", and if u null reference is passed in for the Engine parameter, a new Engine should be created with an empty description and O's for all values . have the following member functions implemented: public String getDencription public int getX) poble int getY puble double get.Puellavalt public int getG) public void tillUp! poblia int got. Maxfpeed) pable double drivetint distance, double ratio, double yol getDescription() should return the description of the car as well as the description of its Engine, fuel level and capacity, and location, all clearly labeled (eg. "Sweet Ride (engine: V6 (MPG: 20. Max speed: 120)), fuel: 0.00/15, location: (0.0)") fillUp should cause the gas tank to be filled to its maximum capacity o drive(int distance, double xRatio, double y Ratio) should take the desired distance to travel as an integer, and two double values which, together, specify the direction as a ratio of horizonal to vertical distances. For example, if Ratio 1 and Ratio - 2. for every 1 unit to the right (positive x), the car would travel 2 units up (positive y). Negative values for Ratio and Ratio correspond to moving left and down, respectively. Given the distance and direction, this method should correctly compute the ending coordinates (luncated to integers). It should also correctly subtract the amount of fuel used. If the distance specified requires greater than the amount of fuel than the car currently has the car should travel as far as it can antil it is empty and print this text to the console: "Ran out of as her driving smiles." (with the correct value substituted in for x). The method should return the number of miles which were actually driven All double values which are printed out to the console should be formatted so that exactly 2 decimal places are displayed 4. Test your work. An example class named CarTest.java is provided (on the course site along with assignment 2) to help you test your code. Your classes must work with it, i.e. they must all compile correctly together and CarTest.java should work correctly when executed. However, when grading we will use more and/or different test cases, so you should also test various additional cases. Do not submit CarTest.java. Here is the output that my implementation gives with this file: Tank levelt 10.00 Enginelt V6 (PG1 20, Max speed: 120) CariCarl (engine: V6 (MPG: 20. Max npeedt 120>), tuoli 0.00/15, location (0,0) Car2 Generic car (enginet Generse engine (MPG 0, Max speedt 0)), fuel. 0.00/0, locations (0,0) Cart Card. (engine V6 (MTO: 20. Max speed: 120)), fuel 0.00/50, location: (0,0) Car3: Car3 engino V6 (MPG1 20, Max speed: 120), fuelt 50.00/50, location (0,0) Card drove 600.00 milen Cart Card (onginer V6 DMPG 20, Max speed: 120), fuell 20.00/50, location (-400,-360) Car) drove 300.00 miles Car3: Cnt) (engine 16 MPC 20. Max speed 120%), fuel: 5.00/50, location (-230.-193) Ran out of gas after driving 100.00 miles. car) drove 100.00 miles card card (ongine 26 (MPG 20, Max speedt 1203), fuel 0.00/50, location: (-130.-193) Card drove a total of 1000.00 miles. Card Card (engine V4 (H 30, Max apeod 100), foelt 0.00/30, loontlan (0,0) Carti Care (engine V4 MG 30, Max speedi 1003). tuelt 30.00/30, lovation (0,0) Card drove 100.00 miles Car Card engine RP 30, Max speed: 100): fuel 26.67/30, local. Loni (70.7a> Card drove 200.00 miles Card Card engine XMP 20, Max peedi 1001), fuel: 20.00/30, location (-115,144) Card drove 300.00 miles Card Card engine 30. Max speedt 1007) Fuel: 10.00/30, location (255,270). an out of gas after driving 300.00 miles. Card drove 300.00 miles Car Caxs engine (MPG 30. Max speeds 100fuel 0.00/30, louation (207,9) an out of an after driving 0.00 miles. Card drove 0.00 miles Card Cartoni V4 (HPO 30 Max speedi 1001). U 0.00/30, location (2079) Car drove total of 900,00 Iles. Note that if your values are within 1.0. that is sufficient

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

Beginning PostgreSQL On The Cloud Simplifying Database As A Service On Cloud Platforms

Authors: Baji Shaik ,Avinash Vallarapu

1st Edition

1484234464, 978-1484234464

More Books

Students also viewed these Databases questions

Question

Active listening is hard work. True False

Answered: 1 week ago