Question: How would you build a JAVA Code with a class called Wallet using the specifications given in the form of a UML class diagram? The

How would you build a JAVA Code with a class calledWallet using the specifications given in the form of a UML class diagram?

Wallet - hundreds : int -fifties: int - twenties: int -tens: int


The three constructors set the instance variables to the desired values:

  • The default no-args constructor should set all the values to zero.
  • The constructor taking a Wallet parameter is a copy constructor.
  • The third constructor is the full constructor for the class. Its parameters should be listed in the natural order 100, 50, 20, ... If any of its argument is less than zeo, the constructor should change the negative value to zero.

Most of the other methods are self-explanatory, except for

  1. The getTotalWallet method, which simply return the total dollar value of this wallet.
  2. The combineWallets, which takes a wallet object as a parameter and returns a new wallet whose instance variables are the sum of the corresponding variables in this (the calling object) and the Wallet object passed as an argument. If the argument is null, the method should return the calling object.
  3. The toString method must, as usual, be formatted EXACTLY as follows:

Wallet[$100: 0, $50: 1, $20: 2, $10: 3, $5: 4, $1: 5]

with the different bill counts adjusted as appropriate.

  1. The equals method is the simplified equals method discussed in the reading materials.

Please make sure you respect the class, methods, and attribute names. Failure to do so will result in validation tests failure.

Wallet - hundreds : int -fifties: int - twenties: int -tens: int -fives: int -ones: int + Wallet (hundred: int, fifty: int, twenty: int, ten: int, five: int, one: int) + Wallet (w: Wallet) + Wallet() +getHundreds (): int +getFifties(): int +getTwenties () : int +getTens(): int + getFives () : int + getOnes () : int +setHundreds (hundreds : int): void + setFifties (fifties: int) : void +setTwenties (twenties: int): void +setTens (tens: int): void + setFives (fives: int): void + setOnes (ones: int): void +getTotalWallet () : int + combineWallets (w: Wallet): Wallet +toString(): String + equals (w: Wallet): boolean

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!