Question

STORAGE WARS - Create a class with the name and variables/attributes listed below. Create a default...

STORAGE WARS - Create a class with the name and variables/attributes listed below. Create a default Constructor with no parameters that assigns default values for each variable. Then, create an overloaded Constructor (with one parameter for each variable). Finally, create a method that returns the total number of items in the storage container. NOTE: this method must not print anything. (50 points) Make sure to clearly label the variables/attributes, Constructors and Methods and to indicate which language you are answering in. Piggybank – quarters, dimes, nickels, pennies

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

class Piggybank {
   private int quarters;
   private int dimes;
   private int nickels;
   private int pennies;
   /**
   * default constructor
   */
   public Piggybank(){
      
   }
   /**
   * @param aQuarters
   * @param aDimes
   * @param aNickels
   * @param aPennies
   * initializes the values
   */
   public Piggybank(int aQuarters, int aDimes, int aNickels, int aPennies) {
       super();
       quarters = aQuarters;
       dimes = aDimes;
       nickels = aNickels;
       pennies = aPennies;
   }
  
   /**
   * @return returns the total size
   */
   public int totalSize(){
      
       return quarters+dimes+nickels+pennies;
   }
  
}

public class TestPiggybank {
   public static void main(String[] args) {
       Piggybank p = new Piggybank(10,5,3,12);
       System.out.println(p.totalSize());
   }
}

Add a comment
Know the answer?
Add Answer to:
STORAGE WARS - Create a class with the name and variables/attributes listed below. Create a default...
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
  • Write a Java class that implements the concept of Coins, assuming the following attributes (variables): number...

    Write a Java class that implements the concept of Coins, assuming the following attributes (variables): number of quarters, number of dimes, number of nickels, and number of pennies. Include two constructors (non-argument constructor that assigns 1 to each coin, and another constructor that takes necessary arguments to create an object), needed getter and setter methods, method toString (to print coins objects in a meaningful way), and method equals (to compare two coins objects based on number of coins). Also include...

  • implement a class called PiggyBank that will be used to represent a collection of coins. Functionality...

    implement a class called PiggyBank that will be used to represent a collection of coins. Functionality will be added to the class so that coins can be added to the bank and output operations can be performed. A driver program is provided to test the methods. class PiggyBank The PiggyBank class definition and symbolic constants should be placed at the top of the driver program source code file while the method implementation should be done after the closing curly brace...

  • implement a class called PiggyBank that will be used to represent a collection of coins. Functionality...

    implement a class called PiggyBank that will be used to represent a collection of coins. Functionality will be added to the class so that coins can be added to the bank and output operations can be performed. A driver program is provided to test the methods. class PiggyBank The PiggyBank class definition and symbolic constants should be placed at the top of the driver program source code file while the method implementation should be done after the closing curly brace...

  • Programming in C# Create a Money class that has as data members dollars and cents. Include...

    Programming in C# Create a Money class that has as data members dollars and cents. Include IncrementMoney and DecrementMoney instance methods. Include constructors that enable the Money class to be instantiated with a single value representing the full dollar/cent amount as well as a constructor that enables you to create an instance of the class by sending two separate integer values representing the dollar and cent amounts. Include an instance method that returns as a string the number of dollars,...

  • FOR C++ PLEASE Create a class called "box" that has the following attributes (variables): length, width,...

    FOR C++ PLEASE Create a class called "box" that has the following attributes (variables): length, width, height (in inches), weight (in pounds), address (1 line), city, state, zip code. These variables must be private. Create setter and getter functions for each of these variables. Also create two constructors for the box class, one default constructor that takes no parameters and sets everything to default values, and one which takes parameters for all of the above. Create a calcShippingPrice function that...

  • Diego’s Bike Lab Lab Objectives • Be able to create both default and non-default constructors •...

    Diego’s Bike Lab Lab Objectives • Be able to create both default and non-default constructors • Be able to create accessor and mutator methods • Be able to create toString methods • Be able to refer to both global and local variables with the same name Introduction Until now, you have just simply been able to refer to any variable by its name. This works for our purposes, but what happens when there are multiple variables with the same name?...

  • Write a class called Book. Here are the relevant attributes: title author yearPublished            bookPriceInCAD Provide...

    Write a class called Book. Here are the relevant attributes: title author yearPublished            bookPriceInCAD Provide a constructor that takes parameters to initialize all the instance variables. The constructor calls the mutator (set) methods to initialize the instance variables. Provide an accessor (get) and mutator (set) for each instance variable. The mutators all validate their parameters appropriately and use them only if valid. If the passed parameter was invalid an IllegalArgumentException will be thrown with a proper error message A...

  • Create the header file named “Complex.h” that contains the following class: The class Complex represents a...

    Create the header file named “Complex.h” that contains the following class: The class Complex represents a complex number which is a number of the form a + bi where a and b are real numbers and i2 = −1. The class should contain: Private double field named real. Private double field named imaginary. Public default constructor that assigns 1 to real and 0 to imaginary. Public overloaded constructor that takes a double as a parameter named real. It assigns real...

  • Programming Logic and Design, comprehensive, 8 edition. Chapter 11, PE 5a Create a class named Trip...

    Programming Logic and Design, comprehensive, 8 edition. Chapter 11, PE 5a Create a class named Trip that includes four string variables; destination (for example, "air"), departure date (for example, "12/15/2015"), and trip's purpose (for example, "business") Include tow overloaded constructors. The default constructor sets each field to "XXX". The nondefault constructor accepts four parameters- one for each field. include two overloaded display() methods. The parameterless version displays all the Trip details. The second version accepts a string that represents a...

  • Exercise #3: Create the “MathTest” class. It will have two class variables: 1) a question and...

    Exercise #3: Create the “MathTest” class. It will have two class variables: 1) a question and 2) the answer to that question. Exercise #4: Please create an accessor and mutator method for both of those variables, without which we would not be able to see or change the question or the answer. Exercise #5: There should be a constructor method. We will also have a “ToString” method, which will print the question followed by its answer. The constructor method has...

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