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
Dahasolnce [82]
3 years ago
6

Lab Assignment 3 Phase 1 Create a class named Car, which is supposed to represent cars within a Java program. The following are

the attributes of a typical car: - year which indicates the year in which the car was made. - price indicating the price of the car The year attribute is an integer, whereas the price is a double value. The year can only lie between 1970 and 2011. The price can be any value between 0 and 100000. The class Car should be constructed in such a way that any attempt to place an invalid value in the year and/or price, will result in the attribute being set to its lowest possible value. Create the class, which contains the necessary attributes and setter/getter methods: setYear( ), getYear( ), setPrice( ) and getPrice( ). Test all of its public members, which in this case only represents the setter/getter methods. The instructor will provide his/her own testing code to verify that the class is functioning properly
Computers and Technology
1 answer:
noname [10]3 years ago
3 0

Answer:

Check the explanation

Explanation:

Car.java

//class Car

public class Car {

  //private variable declarations

  private int year;

  private double price;

  //getYear method

  public int getYear() {

      return year;

  }

  //setYear method

  public void setYear(int year) throws CarException {

      //check for the year is in the given range

      if(year>=1970&&year<=2011)

          this.year = year;

      //else throw an exception of type CarException

      else

          throw new CarException("Invalid Year");

  }

  //getPrice method

  public double getPrice() {

      return price;

  }

  //setPrice method

  public void setPrice(double price) throws CarException {

      //check for the price is in the given range

      if(price>=0&&price<=100000)

          this.price = price;

      //else throw an exception of type CarException

      else

          throw new CarException("Invalid Price");

  }

  //default constructor to set default values

  public Car(){

      this.year=1970;

      this.price=0;

  }

  //overloaded constructor

  public Car(int year, double price) {

      //check for the year is in the given range

      if(year>=1970&&year<=2011)

          this.year = year;

      //else initialize with default value

      else

          this.year=1970;

      //check for the price is in the given range

      if(price>=0&&price<=100000)

          this.price = price;

      //else initialize with default value

      else

          this.price=0;

     

  }

  //copy constructor

  public Car(Car c){

      this.year=c.year;

      this.price=c.price;

  }

  //toString method in the given format

  public String toString() {

      return "[Year:" + year + ",Price:" + (int)price + "]";

  }

  //finalize method

  public void finalize(){

      System.out.println("The finalize method called.");

  }

  public static void main(String args[]) throws CarException{

      Car a=new Car();

      System.out.println(a.toString());

      Car b=new Car(1986,25000.98);

      System.out.println(b.toString());

      Car c=new Car();

      c.setYear(1900);

      c.setPrice(23000);

      System.out.println(c.toString());

      Car d=new Car();

      d.setYear(2000);

      d.setPrice(320000);

      System.out.println(d.toString());

  }

}

CarException.java

//exception class declaration

public class CarException extends Exception{

  //private variable declaration

  private String message;

  //constructor

  public CarException(String message) {

      super();

      this.message = message;

  }

  //return error message

  public String getMessage(){

      return message;

  }

 

}

You might be interested in
Define a function setheight, with int parameters feetval and inchesval, that returns a struct of type heightftin. the function s
ehidna [41]

It is given that the feetVal and inchesVal are parameters of the SetHeight() function. Since the return type of the function is structute, so we need to define a structure.

After that, we need to create a structure variable within the function definition. Now, assign the feet and inches with the feetVal and inchesVal respectively. Finally return the structure variable.

Further explanation:

#include<stdio.h>

//define the structure

typedef struct HeightFtIn_struct {

int feet;

int inches;

} HeightFtIn;

//define the function

HeightFtIn SetHeight(int feetVal, int inchesVal)

{

HeightFtIn Htft; //creating a structure variable of type HeightFtIn

//assign the value of feetVal

Htft.feet = feetVal;  

Htft.inches = inchesVal; //assigning the value of inchesval

//return the structure variable

return Htft;

}

int main(void) {

HeightFtIn studentHeight;

int feet;

 int inches;

printf("Enter the values of feet and the inches: ");

scanf("%d %d", &feet, &inches);

studentHeight = SetHeight(feet, inches);

printf("The student's height is %d feet and %d inches.\n", studentHeight.feet, studentHeight.inches);

return 0;

}

Output:

Enter the values of feet and the inches: 5 9

The student's height is 5 feet and 9 inches.

Learn more:

1. A company that allows you to license software monthly to use online is an example of ? brainly.com/question/10410011  

2. How does coding work on computers?  brainly.com/question/2257971 

Answer details:

Grade: College Engineering

Subject: Computer Science

Chapter: C  Programming

Keyword:

C++, input, output, programming, statements,  loops, if, else, statements, firstname, lastname, base class, derive class, vector, print

6 0
3 years ago
The function of a start winding in a split-phase motor is to A. provide the starting torque. B. reduce the starting current. C.
gulaghasi [49]
The most appropriate answer is A, the the start winding on a split-phase motor is to provide a starting torque. A split-phase motor is a single phase electrical motor (common in many household applications such as washing machines and household fans), with two distinct windings on the stator coils, the start windings and the run windings, at 90 degrees apart. When the motor is energised the start coils acts like a second phase (2 phase motor) and helps provide the rotating magnetic field that is necessary to turn the rotor. Once moving, only the run winding (single phase) is required to keep the motor spinning.

The other answers are irrelevant for the starting of the motor.
4 0
3 years ago
When you try to boot your computer it hangs after post?
Likurg_2 [28]
What are you trying to ask...
4 0
3 years ago
1. Readability, navigation, consistency, layout and typography are all factors which
miv72 [106K]

Answer:

1) Readability is the ease with which a reader can understand a written text. Readability is more than simply legibility—which is a measure of how easily a reader can distinguish individual letters or characters from each other.

2) Navigation is a field of study that focuses on the process of monitoring and controlling the movement of a craft or vehicle from one place to another. The field of navigation includes four general categories: land navigation, marine navigation, aeronautic navigation, and space navigation. It is also the term of art used for the specialized knowledge used by navigators to perform navigation tasks.

3) In classical deductive logic, a consistent theory is one that does not entail a contradiction. The lack of contradiction can be defined in either semantic or syntactic terms. The semantic definition states that a theory is consistent if it has a model, i.e., there exists an interpretation under which all formulas in the theory are true. This is the sense used in traditional Aristotelian logic, although in contemporary mathematical logic the term satisfiable is used instead.

4) The way in which the parts of something are arranged or laid out.

5) Typography is the art and technique of arranging type to make written language legible, readable and appealing when displayed. The arrangement of type involves selecting typefaces, point sizes, line lengths, line-spacing (leading), and letter-spacing (tracking), and adjusting the space between pairs of letters (kerning ).

Explanation:

Hope it helps :)

3 0
3 years ago
A consumer-directed digital or computer device that has a video output signal for displaying a video game is called a .......
Allushta [10]
I think the first problem is B. and the second problem is D.
4 0
4 years ago
Other questions:
  • The Modified Greiss chemical test is used to detect the presence of what chemicals that indicate muzzle to target distance?
    11·1 answer
  • You have just built a new system from scratch. you turn the computer on but the system boot fails and sounds a beep code. what m
    15·1 answer
  • Top Down Design makes it easier to solve a problem by:___________
    10·1 answer
  • How long does it take to wash 12 t-shirts in the quickest way?​
    15·2 answers
  • When converting the relationships to the relational model and the database schema, it is possible that some of the relationships
    15·1 answer
  • Which of the following are the benefits of using Responsive Display Ads?
    9·1 answer
  • The following is a mock-up of a Battleship game board. The square with a X marks the position of a battleship.
    13·1 answer
  • This is a while loop question for Information technology.
    11·1 answer
  • Saitama And Tatsumaki Both Go Shopping Together ,Both have Have 50 loafs of bread , And Saitama takes 43 , How much do Tatsumaki
    14·1 answer
  • What is folded card publishing?​
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!