Question: Two classes are given: Coin and Wallet. Write an application named MyWallet.java that reads all coins from a data file named coins.txt. The first line
Two classes are given: Coin and Wallet. Write an application named MyWallet.java that reads all coins from a data file named coins.txt. The first line in the data file contains the number of coins (N) in the file, followed by N lines containing N numbers each represents a coin. You need to create a coin object from each number then create a Wallet object. At the end of your application, display number of coins and subtotal for each type, and total value in the wallet.
Below are the two files given. The files can not be changed. The program is throuth WholeLearning and the files are accessed through the command argument list. There is no coin class provided.
Wallet.txt
public class Wallet{
private Coin[] coins;
public Wallet(Coin[] coins){ setCoins(coins); }
public Coin[] getCoins(){ return coins; } public void setCoins(Coin[] coins){ this.coins = coins; } public int totalValue(){ int total=0; for(int i=0; i total += coins[i].getValue(); return total; }
}
Coins.txt
10 5 10 1 25 5 1 25 25 25 10
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
