Modify the following script to add another attribute and a method that fits (is consistent with) the object

Modify the following script to add another attribute and a method that fits (is consistent with) the object the class is modeling, or suggest a different version of the code. Ensure the main method demonstrates the correct functionality of the additions:

import java.util.Scanner;
public class WK1SargentZ {
static Scanner scan = new Scanner(System.in);

public static class piggyBank {
public double numDollars;
public double balance;
public double total;

public piggyBank(double numDollars, double balance, double total) {
this.numDollars = numDollars;
this.balance = balance;
this.total = total;
}
//Method for calculating and gathering input
public void deposit() {
System.out.println(“What is your current piggy’s balance?”);
this.balance = scan.nextDouble();
System.out.println(“How much would you like to deposit?”);
this.numDollars = scan.nextDouble();

//formula for total
this.total = balance + numDollars;
System.out.println(“You have deposited $”+numDollars+ ” into your piggy bank. ”
+ “Your current balance is $”+total+”. Happy Saving!”);

}
}

public static void main(String[] args) {
piggyBank Piggybank = new piggyBank(0,0,0);
Piggybank.deposit();

}

}

Complete Answer:

Get Instant Help in Homework Asap
Get Instant Help in Homework Asap
Calculate your paper price
Pages (550 words)
Approximate price: -
Open chat
1
Hello 👋
Thank you for choosing our assignment help service!
How can I help you?