1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Yanka [14]
3 years ago
15

Design a class named Car that has the following fields:

Computers and Technology
1 answer:
snow_tiger [21]3 years ago
4 0

Answer:

// The class car is defined

public  class Car {

  // instance variable yearModel

  private int yearModel;

  // instance variable make

  private String make;

  // instance variable speed

  private int speed;

 

  // empty constructor

  // with instances inside it

  // the instances are from the question

  public Car(){

      yearModel = 2000;

      make = "Nissan";

      speed = 4;

  }  

  // overloaded constructor

  // constructor defined with three arguments

  public Car(int yearModel, String make, int speed) {

      // the arguments are assigned to the object's variable

      this.yearModel = yearModel;

      this.make = make;

      this.speed =speed;

  }

  // setter(mutator) method

  public void setYearModel(int yearModel){

      this.yearModel = yearModel;

  }

  // setter(mutator) method

  public void setMake(String make){

      this.make = make;

  }

  // setter(mutator) method

  public void setSpeed(int speed){

      this.speed = speed;

  }

  // getter(accessor) method

  public int getYearModel(){

      return yearModel;

   }

  // getter(accessor) method

  public String getMake(){

      return make;

   }

  // getter(accessor) method

  public int getSpeed(){

      return speed;

   }  

  // toString is override to display the car object properties

  public String toString(){

      return "Car's year model: " + getYearModel() + ", make: " + getMake() + ", speed: " + getSpeed();

  }

}

Explanation:

The code is well commented.

You might be interested in
When creating a storyboard, in which section do you mention how you move from one shot to the next?
tekilochka [14]

Answer: C

Explanation:

7 0
3 years ago
The Align Center option in the Alignment grouping on the Table Tools Layout tab will _____.
AnnyKZ [126]

the awnser would be d center the text vertically and horrizontaly in the cell

6 0
2 years ago
Read 2 more answers
In this exercise you will debug the code which has been provided in the starter file. The code is intended to take two strings,
vampirchik [111]

Answer:

Here is the corrected program:

import java.util.Scanner; //to accept input from user

public class 02_14_Activity_one { //class name

    public static void main(String[] args) { //start of main method

    Scanner scan = new Scanner(System.in); //creates Scanner class object

  System.out.println("Enter first string"); //prompts user to enter first string

          String s1 = scan.nextLine(); //reads input string from user

  System.out.println("Enter second string"); //prompts user to enter second string

          String s2 = scan.nextLine(); //reads second input string from user

    System.out.println("Enter number of letters from each word"); //enter n

          int n = scan.nextInt(); //reads value of integer n from user

          System.out.println(s1.substring(0,n) + s2.substring(s2.length() - n ));

         } } //uses substring method to print a string made up of the first n letters of s1 and the last n letters of s2.

Explanation:

The errors were:

1.

Scanner scan = Scanner(System.in);

Here new keyword is missing to create object scan of Scanner class.

Corrected statement:

 Scanner scan = new Scanner(System.in);

2.

String s1 = nextLine();  

Here object scan is missing to call nextLine() method of class Scanner

Corrected statement:

String s1 = scan.nextLine();

3.

String s2 = Scanner.nextLine();

Here class is used instead of its object scan to access the method nextLine

Corrected statement:

String s2 = scan.nextLine();

4.

String n = scan.nextLine();

Here n is of type String but n is a whole number so it should be of type int. Also the method nextInt will be used to scan and accept an integer value

Corrected statement:

int n = scan.nextInt();

5.

System.out.println(s1.substring(1,n-1) + s2.substring(s1.length()-n));

This statement is also not correct

Corrected statement:

System.out.println(s1.substring(0,n) + s2.substring(s2.length() - n ));

This works as follows:

s1.substring(0,n) uses substring method to return a new string that is a substring of this s1. The substring begins at the 0th index of s1 and extends to the character at index n.

s2.substring(s2.length() - n ) uses substring method to return a new string that is a substring of this s2. The substring then uses length() method to get the length of s2 and subtracts integer n from it and thus returns the last n characters of s2.

The screenshot of program along with its output is attached.

7 0
3 years ago
Which type of ethernet framing is used for TCP IP and DEC net​
umka21 [38]
Ethernet II
Trust me u will get it right
6 0
3 years ago
Two small engine technicians are disassembling the engine shown in Figure A-9. After observing the engine components, both techn
11Alexandr11 [23.1K]
<span>A splash-type lubrication system uses what the Technician A says :  that the engine uses a dipper that's attached to the connecting rod to splash oil from the crankcase onto its components. </span>In  the  engine, dippers on the connecting-rod bearing caps enter the oil pan with each revolution to produce the oil splash.  A passage is drilled in each rod from the dipper to the bearing to <span>ensure lubrication.</span> 
3 0
3 years ago
Other questions:
  • What are two statements that are true about using an external hard drive for backing up data
    14·1 answer
  • Approximately what percent of desktop PCs are used for work-related purposes?
    12·1 answer
  • What do you think of my profile picture
    8·2 answers
  • HELP I WILL MARK BRAINLIEST!!! I NEED ASAP!!!
    5·1 answer
  • write the program or pseudocode algorithm that computes the product and average of three integers and display the results​
    7·1 answer
  • Tara is creating a presentation for her science project about volcanoes. She added different animations to every slide for empha
    12·1 answer
  • Write a calculate_sq_inches_of_good_pizza function that accepts the diameter of a pizza and returns the area of the pizza minus
    7·1 answer
  • Use the variables k and total to write a while loop that computes the sum of the squares of the first 50 counting numbers, and a
    6·1 answer
  • How many times will line 7 be executed when the following code is run?
    5·1 answer
  • Two friends can share 100 songs from their Bluetooth enabled mobile devices
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!