Question

Given the CarRecord class definition below define the following: 1) A default constructor that initializes yearMade to 2006 a

also write accessor and mutator methods for the class. please
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Source Code:

class CarRecord
{
   private int yearMade;
   private int vehicleIdNum;
   CarRecord()
   {
       this.yearMade=2006;
       this.vehicleIdNum=1000;
   }
   CarRecord(int yearMade,int vehicleIdNum)
   {
       this.yearMade=yearMade;
       this.vehicleIdNum=vehicleIdNum;
   }
   void setYearMade(int yearMade)
   {
       this.yearMade=yearMade;
   }
   void setVehicleIdNum(int vehicleIdNum)
   {
       this.vehicleIdNum=vehicleIdNum;
   }
   int getYearMade()
   {
       return this.yearMade;
   }
   int getVehicleIdNum()
   {
       return this.vehicleIdNum;
   }
}
class ex
{
   public static void main(String[] args) {
       CarRecord cr=new CarRecord(2020,1234);
       System.out.println("Vehicle Id: "+cr.getVehicleIdNum());
   }
}

{ } { 1 class CarRecord 2 3 private int yearMade; 4 private int vehicleIdNum; 5 CarRecord() 6 7 this.yearMade=2006; 8 this.ve

32 class ex 33 { 34 public static void main(String[] args) { 35 CarRecord cr=new CarRecord(2020,1234); System.out.println(VeSample input and output:

(base) rgukti@rgukt-TravelMate-P243-M:-/Desktop$ java ex Vehicle Id: 1234 (base) rgukt1@rgukt-TravelMate-P243-M:~/Desktops |

Add a comment
Know the answer?
Add Answer to:
also write accessor and mutator methods for the class. please Given the CarRecord class definition below...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Please write the following program in Python 3. Also, please create a UML and write...

    1. Please write the following program in Python 3. Also, please create a UML and write the test program. Please show all outputs. (The Fan class) Design a class named Fan to represent a fan. The class contains: Three constants named SLOW, MEDIUM, and FAST with the values 1, 2, and 3 to denote the fan speed. A private int data field named speed that specifies the speed of the fan. A private bool data field named on that specifies...

  • Your will write a class named Gasket that can be used to build Gasket objects (that...

    Your will write a class named Gasket that can be used to build Gasket objects (that represent Sierpinski gaskets) that you can display graphically.  Your Gasket class is defined in the provided file Gasket.h.   DO NOT CHANGE the file Gasket.h.  The attributes and methods defined for class Gasket are described below.     ·sideLength            an int that holds the length of each side of the Gasket.  The length of the side is measured as a number of pixels ·xLocation              an int that holds the x coordinate (in pixels)...

  • 1a. Create a class named Inventory - Separate declaration from implementation (i.e. Header and CPP files)...

    1a. Create a class named Inventory - Separate declaration from implementation (i.e. Header and CPP files) 1b. Add the following private member variables - a int variable named itemNumber - an int variable named quantity - a double variable named cost - a double variable named totalCost. Total cost is defined as quantity X cost. - updateTotalCost() which takes no arguments and sets the values of the variable totalCost. 1c. Add the following public functions: - Accessor and Mutators for...

  • In JAVA Algorithm Workbench 1. Write the first line of the definition for a Poodle class....

    In JAVA Algorithm Workbench 1. Write the first line of the definition for a Poodle class. The class should extend the Dog class. 2. Look at the following code, which is the first line of a class definition: public class Tiger extends Felis In what order will the class constructors execute? 3. Write the statement that calls a superclass constructor and passes the arguments x, y, and z. 4. A superclass has the following method: public void setValue(int v) value...

  • JAVA 1.            Given the following class definition, what are the contents of the fields x and...

    JAVA 1.            Given the following class definition, what are the contents of the fields x and y of the object p ?    class MyPoint {      int x;      int y; public MyPoint (int x, int y){        x = x;        y = y;      } --------------------------------------- MyPoint p = new MyPoint( 100, 88 ); 2.            static and non-static members What would happen if you tried to compile and run the following code ? public class Driver {...

  • 7. (10 points=2+2+3+3) Give the class declaration below, class CD Account public: CDAccounto); CDAccount(double bal, double...

    7. (10 points=2+2+3+3) Give the class declaration below, class CD Account public: CDAccounto); CDAccount(double bal, double intRate, int T); double get InterestRate(); double InitialBalance(); double Balance AtMaturityO; int Term(); void input(); void output(); private: double balance; double interestRate; // in PER CENT int term; // months to maturity; Answer the following questions: a. List all the data field names. b. How many methods are there? - c. Write the definition for the accessor method get. InterestRate. d. Write the definition...

  • Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the...

    Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...

  • Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and...

    Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and a driver program called invoiceDriver.cpp. The class Invoice is used in a hardware store to represent an invoice for an item sold at the store. An invoice class should include the following: A part number of type string A part description of type string A quantity of the item being purchased of type int A price per item of type int A class constructor...

  • Overload a relational operator for the Job class: Assume that this operator is not overloaded for...

    Overload a relational operator for the Job class: Assume that this operator is not overloaded for the Salary class. a) Write how the function will be declared in your code. b) Write an external function definition (not inside the class). solve it in C++10 to solve this you nedd question number 1. Create a composition between the classes Job and Salary. Class Salary a. data member:    1. money b. constructors:    1. default constructor    2. user defined constructor with a parameter...

  • Making a rectangle class in java write a simple class that will represent a rectangle. Later...

    Making a rectangle class in java write a simple class that will represent a rectangle. Later on, we will see how to do this with graphics, but for now, we will just have to use our imaginations for the visual representations ofWthe rectangles. Instance Variables Recall that an object is constructed using a class as its blueprint. So, think about an rectangle on your monitor screen. To actually draw a rectangle on your monitor screen, we need a number of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT