Question

Given the following class scenarios write the statements to define the default constructor for the class...

Given the following class scenarios write the statements to define the default constructor for the class

A BudgetItem class with the following instance variables:

* expenseName - default value "unknown"

* expenseAmount - default value 0

Is this answer correct below for the following statement

Answer - public BudgetItem()

{

this .expenseName = "unknown"

this.expenseAmount = 0;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public BudgetItem(){

this .expenseName = "unknown"

this.expenseAmount = 0;

}

The above answer is perfectly alright

Please find another version

public BudgetItem(){

expenseName = "unknown"

expenseAmount = 0;

}

Add a comment
Know the answer?
Add Answer to:
Given the following class scenarios write the statements to define the default constructor for the class...
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
  • Can you tell me if this code is correct A shoppingCart class with the following instance...

    Can you tell me if this code is correct A shoppingCart class with the following instance variables: * cardNumber - default value "unknown" * securityCode - default value "000" Here is my answer for the following above public ShoppingCart() { this.cardNumber = "unknown"; this.securityCode = 000; }

  • also write accessor and mutator methods for the class. please Given the CarRecord class definition below...

    also write accessor and mutator methods for the class. please Given the CarRecord class definition below define the following: 1) A default constructor that initializes yearMade to 2006 and vehicleldNum to 1000. 2) An overloaded constructor that initializes yearMade and vehicleldNum to values passed as parameters. public class CarRecord { private int yearMade; private int vehicleldNum; }

  • use C++ Based on the class declaration below, write out the declaration of its default constructor....

    use C++ Based on the class declaration below, write out the declaration of its default constructor. class BankAccount { public: BankAccount(); // Sets balance to o BankAccount(double initial_balance); // Sets balance to initial_balance // Member functions omitted private: double balance;

  • Consider the following Account class and main function: class Account: acct_num=1000 #Constructor for Account class (default...

    Consider the following Account class and main function: class Account: acct_num=1000 #Constructor for Account class (default values for balance #and annual interest rate are 100 and e, respectively). #INITIALIZER METHOD HEADER GOES HERE #MISSING CODE def getId(self): return self._id def getBalance(self): #MISSING CODE def getAnnualInterestRate(self): return self.___annualInterestRate def setBalance(self, balance): self. balance - balance def setAnnualInterestRate(self,rate): #MISSING CODE def getMonthlyInterestRate(self): return self. annualInterestRate/12 def getMonthlyInterest (self): #MISSING CODE def withdraw(self, amount): #MISSING CODE det getAnnualInterestRate(self): return self. annualInterestRate def setBalance(self,...

  • Create a BoxFigure class that inherits RectangleFigure class BoxFigure Class should contain:- Height instance field- Default...

    Create a BoxFigure class that inherits RectangleFigure class BoxFigure Class should contain:- Height instance field- Default constructor -- that calls the default super class constructor and sets the default height to 0- Overloaded constructor with three parameters (length, width and height) – that calls the two parameterized super class constructor passing in length and width passed and sets the height to passed height.- setDimension method with three parameters (length, width, height) – call the super class setDimension and pass in...

  • need basic default constructor , and shoed an example too s0. write the class Battery and...

    need basic default constructor , and shoed an example too s0. write the class Battery and it has s1. a data for the battery capacity (that is similar to myBalance of the BankAccount class.) s2. a parameterized constructor: public Battery(double amount) s3. a drain mutator s4. a change mutator s5. a getRemainingCapacity accessor Need to run this tester - public class BatteryTester{ public static void main(String[] args) { Battery autoBattery = new Battery(2000); //call default constructor System.out.println("1. battery capacity is...

  • Java - Object Oriented Programming Declare a class named Customer that has two private fields? Write...

    Java - Object Oriented Programming Declare a class named Customer that has two private fields? Write a set method to make sure that if age > 125 years or less than 0 then it is set to 0 (default value) What does it indicate when declaring a class's instance variables with private access modifier? What is the role of a constructor? The data part of by an object's instance variables is known as? Do all methods have to always return...

  • 21.8 LAB: Artwork label (modules) python Define the Artist class in Artist.py with a constructor to...

    21.8 LAB: Artwork label (modules) python Define the Artist class in Artist.py with a constructor to initialize an artist's information. The constructor should by default initialize the artist's name to "None" and the years of birth and death to 0. Define the Artwork class in Artwork.py with a constructor to initialize an artwork's information. The constructor should by default initialize the title to "None", the year created to 0, and the artist to use the Artist default constructor parameter values....

  • JAVA QUESTION 16 Write and submit the java source for the following class specification: The name...

    JAVA QUESTION 16 Write and submit the java source for the following class specification: The name of the class is Question_16 Class Question_16 has 3 instance variables: name of type String, age of type int and height of type double. Class Question_16 has the following methods: print - outputs the data values stored in the instance variables with the appropriate label setName - method to set the name setAge - method to set the age setHeight - method to set...

  • 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...

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