Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m using BlueJ and the code is in Java. This lab requires you to create three

ID: 3747895 • Letter: I

Question

I'm using BlueJ and the code is in Java.

This lab requires you to create three classes, Purse, Coin, and Purse Tester. The Purse class manages a set of Coin objects in an array of Coin that has a max size of 10. The Purse Tester class contains main0 and is the controlling class of the application. Coin: The Coin class has two instance ficlds (name: String, value: double). Provide get and set methods for each field. Two constructors for a Coin should be provided including a no-arg constructor which defaults name-"PENNY" and value-0.01, and a Coin constructor that accepts in a name and a value. Purse: The Purse class maintains a collection of Coin objects using a Coin[l of max size of 10. A class constant MAX should be included that has a valuc of 10. Recall that a class constant is defined as static final. An error message should be provided if an attempt is made to add more entries into the array than MAX. A data field called coinCnt should maintain the current number of elements in the array. The following methods should be provided for Purse +Purse() //initializes the coin[] a size of MAX +add(e: Coin) ivoid //adds a coin object to the list +sum () :double //returns the total value of all of the coins in the 1ist +maxValue ) :double Wreturns the value of the coin with the highest value tmaxcoin (0 :Coin //returns the Coin object that has the max value tremove (name: String)void /removes a Coin from the list based on name Print O ivoid 7/prints list Hints: When removing a coin you need to find the last coin in the list and "move it" to the location that you of the coin that you wish to delete and then reduce the value of size by one: coins:data DIME 0.10 NICKEL 0.05 PENNY 0.01 PENNY D.01 QUARTER 0.25 DIME 0-10 The Puraetester has enain method that shoutd do the toslowing items in this order. e Pzint your name and lab number . create Purse 9 yPUre . Load myPurse with the coins An coins.data .Print the contentsl lot myPusn . Print mycoininaxvalve . Print nane and valpe of ax coin . remove a penny * Add two dines . Print the contenta or nyPa * Print progran ternanatäon message pload your source Files Coanova your generated output as allext ortextile. Thss should be placed in Puxse.java and PurseTester java. Upload Assignment 2 Dropbox. Include your name, lab #, and date at the top of your

Explanation / Answer

public class Coin {
private String name;
private double value;
//Default constructor
public Coin() {
name="PENNY";
value=0.01;
}
//Parameterized Constructor
public Coin(String name, double value) {
this.name = name;
this.value = value;
}
//Getter and setter for private field

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public double getValue() {
return value;
}

public void setValue(double value) {
this.value = value;
}
  
//override toString() method

@Override
public String toString() {
return "Coin{" + "name=" + name + ", value=" + value + '}';
}
  
}

public class Purse {
Coin[] coins;
private static final int MAX=10;
private int coinCnt=0;
  
//Method to intialize array
public void Purse(){
coins=new Coin[MAX];
}
//Method to add coin
public boolean add(Coin c){
if(coinCnt>=10)
return false;
else
{
coins[coinCnt]=c;
coinCnt++;
return true;
}
  
}
//method to calculate sum of value
public double sum(){
double sum=0;
for(Coin c:coins){
sum=sum+c.getValue();
}
return sum;
}
//return maximum value
public double maxValue(){
double mx=0;
for(int i=0;i<coinCnt;i++){
if(mx<coins[i].getValue())
mx=coins[i].getValue();
}
return mx;
}
//return Coin which hasmaximum value
public Coin maxCoin(){
Coin mx=coins[0];
for(int i=0;i<coinCnt;i++){
if(mx.getValue()<coins[i].getValue())
mx=coins[i];
}
return mx;
}
//method to remove coin
public boolean remove(String name){
int ind=-1;
for(int i=0;i<coinCnt;i++){
if(coins[i].getName().equals(name))
ind=i;
}
if(ind>=0){
coinCnt--;
coins[ind]=coins[coinCnt];
return true;
}
return false;
}
//Print content
public void print(){
for(Coin c:coins)
System.out.println(c);
}
}

public class PurseTester {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Coin[] coin_data={new Coin("DIME",0.10),
new Coin("NICKEL",0.05),
new Coin("PENNY",0.01),
new Coin("PENNY",0.01),
new Coin("QUARTER",0.25),
new Coin("DIME",0.11)
};
//Please edit here
String name="Tony Stark";
int lab_number=1;
System.out.println("Hi ..I am "+name+" & Lab Number is"+lab_number);
  
//Object of Purse class
Purse mypurse=new Purse();
//load mypurse
mypurse.Purse();
for(Coin c:coin_data)
mypurse.add(c);
//print content of my purse
mypurse.print();
System.out.println("The max value is :"+mypurse.maxValue());
//Name and value of coin containing max value
System.out.println("The max Containing Coin is :"+mypurse.maxCoin());
System.out.println("Removing PENNY ?:"+mypurse.remove("PENNY"));
//Add 2 dim
mypurse.add(new Coin("DIME",0.11));
mypurse.add(new Coin("DIME",0.11));
//Print content
mypurse.print();
System.out.println("Program is going to terminate with exit number same as your lab number");
System.exit(lab_number);
}
  
}