Question: the java program must read the files through the cmd argument list not through system.in. Two classes are given: Coin and Wallet. Write an application

the java program must read the files through the cmd argument list not through system.in. 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.

The txt files are here

Coin.txt

public class Coin{

private int value; public Coin(){//non-parameter constructor value=25; } public Coin(int value){//parameterized constructor setValue(value); }

public int getValue(){ return value; } public void setValue(int value){ if(value == 1 || value==5 || value==10 || value==25) this.value = value; else this.value=1; }

public String getName(){ String name="Penny"; switch(value){ case 5: name="Nickle"; break; case 10: name="Dime"; break; case 25: name="Quarter"; break; } return name; } }

coins.txt

10 5 10 1 25 5 1 25 25 25 10

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; }

}

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 Databases Questions!