EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
bartleby

Concept explainers

bartleby

Videos

Question
Book Icon
Chapter 5, Problem 8PE
Program Plan Intro

Automobile application

Program plan:

  • In a file “Automobile.java”, create a class “Automobile”,
    • Declare the necessary variables.
    • Define the constructor,
      • Call the method “set_Id()”,
      • Call the method “set_Make()”,
      • Call the method “set_Model()”,
      • Call the method “set_Color()”,
      • Call the method “set_Year()”,
      • Call the method “set_Mpg()”,
    • Define the method “set_Id()”,
      • Initialize the final variable.
      • Check whether either the id is less than “0” or greater than maximum id,
        • If it is true, set the id to “0”.
          • Otherwise, set the initial id.
    • Define the method “set_Make()” to set the initial make value.
    • Define the method “set_Model()” to set the initial model value.
    • Define the method “set_Color()” to set the initial color value.
    • Define the method “set_Year(),
      • Initialize the minimum year and maximum year.
      • Check whether either the year is less than the minimum year or greater than the maximum year,
        • If it is true, set the year to “0”.
          • Otherwise, set the initial year.
    • Define the method “set_Mpg()”,
      • Initialize the minimum and maximum miles per gallon.
      • Check whether either the Miles Per Gallon(MPG) is less than the minimum mpg or greater than the maximum mpg,
        • If it is true, set the MPG to “0”.
          • Otherwise, set the mpg value.
    • Define the method “get_Id()” to return the id.
    • Define the method “get_Make()” to return the Make.
    • Define the method “get_Model()” to return the Model.
    • Define the method “get_Color()” to return the Color.
    • Define the method “get_Year()” to return the year.
    • Define the method “get_Mpg()” to return the MPG.
  • In a file “TestAutomobiles.java”, create a class “TestAutomobiles”,
    • Define the method “main ()”,
      • Call the constructor “Automobile()” that instantiates several job automobile dealers.
      • Call the method “display1()” for first automobile dealer.
      • Call the method “display1()” for second automobile dealer.
      • Call the method “set_Id()” for first automobile dealer.
      • Call the method “display1()” for first automobile dealer.
      • Call the method “set_Id()” for first automobile dealer.
      • Call the method “display1()” for first automobile dealer.
      • Call the method “set_Make()” for first automobile dealer.
      • Call the method “set_Model()” for first automobile dealer.
      • Call the method “display1()” for first automobile dealer.
      • Call the method “set_Id()” for second automobile dealer.
      • Call the method “set_Color()” for second automobile dealer.
      • Call the method “set_Year()” for second automobile dealer.
      • Call the method “display1()” for second automobile dealer.
      • Call the method “set_Mpg()” for second automobile dealer.
      • Call the method “display1()” for second automobile dealer.
      • Call the method “set_Mpg()” for second automobile dealer.
      • Call the method “display1()” for second automobile dealer.
    • Define the method “display1()”,
      • Print the output.

Blurred answer
Students have asked these similar questions
create an automobile class for a dealership.  include fields fo an ID number, model, make, color, year and miles per gallon.  include get and set methods for each field. do not allow the ID to be negative or more than 9999; if it is, set the ID to 0.  do not allow the year to be earlier than 2005 or later than 2019, if it is, set year to 0. do not allow the miles per gallon to be less than 10 or more than 60; if it is, set the miles per gallon to 0. include a constructor that accepts arguments for each field value and uses the set methods to assign the values.
Create an Automobile class for a dealership. Include fields for an ID number, make, model, color, year, and miles per gallon. Include get and set methods for each field. Do not allow the ID to be negative or more than 9999; if it is, set the ID to 0. Do not allow the year to be earlier than 2005 or later than 2019; if it is, set the year to 0. Do not allow the miles per gallon to be less than 10 or more than 60; if it is, set the miles per gallon to 0. Include a constructor that accepts arguments for each field value and uses the set methods to assign the values.
use this code template to help you continue: private boolean included Indicates whether the item should be taken or not   public Item(String name, double weight, int value) Initializes the Item’s fields to the values that are passed in; the included Field is initialized to false   public Item(Item other)  Initializes this item’s fields to the be the same as the other item’s   public void setIncluded(boolean included) Setter for the item’s included field (you don’t need setters for the other fields)   Given code: public class Item {       private final String name;     private final double weight;     private final int value;       public Item(String name, double weight, int value) {         this.name = name;         this.weight = weight;         this.value = value;     }       static int max(int a, int b)     {         if(a > b)             return a;         return b;     }       // function to print the items which are taken     static void printSelection(int W, Item[] items, int…
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY