Question
White java program. import java.text.*; class Coin { int year; double value; String denom; Coin(int year, double value, String denom) { this.year = year; this.value
White java program.
import java.text.*;
class Coin
{
int year;
double value;
String denom;
Coin(int year, double value, String denom)
{
this.year = year;
this.value = value;
this.denom = denom;
}
int getYear()
{
return year;
}
double getValue()
{
return value;
}
String getDenom()
{
return denom;
}
public String toString()
{
NumberFormat fmt = NumberFormat.getCurrencyInstance();
return denom + " " + year + " worth " + fmt.format(value);
}
}
collection; String filename; CoinCollection(String filena">
import java.util.*;
class CoinCollection
{
ArrayList collection;
String filename;
CoinCollection(String filename)
{
}
void add(int year, double value, String denom)
{
}
public String toString()
{
return "";
}
}
import java.util.*;
class CoinCollectionMain
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
String filename = "myCoins.txt";
CoinCollection collection = new CoinCollection(filename);
int option;
do
{
System.out.println("Menu ----");
System.out.println("1-Print collection");
System.out.println("2-Add coin");
System.out.println("3-Load from text file");
System.out.println("4-Save to text file");
System.out.println("5-Load from binary file");
System.out.println("6-Save to binary file");
System.out.println("0-Exit");
System.out.print("Your option: ");
option = scan.nextInt();
scan.nextLine();
if (option==1)
;// add here one line of code to print the collection
else if (option==2)
{
System.out.print("Year: ");
int year = scan.nextInt();
System.out.print("Value: ");
double value = scan.nextDouble();
scan.nextLine();
System.out.print("Denomination: ");
String denom = scan.nextLine();
;// add here the code to add this coin to the collection
}
else if (option==3)
;// add here one line to call a method for loading from text file
else if (option==4)
;// add here one line to call a method for saving to text file
else if (option==5)
{
;// add here the lines of code to call a method for loading
// from binary file, and handle the exception if a problem arises
}
else if (option==6)
;// add here one line to call a method for saving to binary file
} while (option != 0);
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started