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

Create a Coin.java class that includes the following: Takes in a coin name as pa

ID: 3599110 • Letter: C

Question

Create a Coin.java class that includes the following:

            Takes in a coin name as part of the constructor and stores it in a private string

            Has a method that returns the coins name

            Has an abstract getvalue method

Create four children classes of Coin.java with the names Penny, Nickle, Dime, and Quarter that includes the following:

            A constructor that passes the coins name to the parent

            A private variable that defines the value of the coin

            A method that returns the coins name via the parent class

            And any other methods that should be required.

Create a Pocket class that includes the following:

            An ArrayList of type coin to manage coins.(You MUST use an ARRAYLIST)

            A method that allows a coin to be added

            A method that allows a coin to be removed

            A method that returns a count of the coins in your arraylist by coin type.

            A method that returns a total value of all the coins in your arraylist   

Create a NoSuchCoin class that will act as your custom exception (see pg.551 in book).

Create a PocketMain class that includes the following :

            Creates an object of type pocket to be used below

            A main method that prompts the user with a menu of options to include:

                        Add a coin (must specify type)

                        Remove a coin (must specify type)

                        Display a coin count

                        Display a total value in the pocket

                        An ability to exit the program

            This method must handle poor user input somehow using your custom exception

YOU MUST COMMENT YOUR CODE SO I KNOW WHAT IS HAPPNEING!!!

Explanation / Answer

Note: Its some what big program.I have to complete Main class and Exception class. I will develop it for sure.Thank YOu

_____________

package org.students;

public abstract class Coin {

private String name;

public Coin(String name) {

super();

this.name = name;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

}

__________________

package org.students;

public class Dime extends Coin {

private double value;

public Dime(String name, double value) {

super(name);

this.value = value;

}

public double getValue() {

return value;

}

public void setValue(double value) {

this.value = value;

}

}

__________________

package org.students;

public class Nickle extends Coin {

private double value;

public Nickle(String name, double value) {

super(name);

this.value = value;

}

public double getValue() {

return value;

}

public void setValue(double value) {

this.value = value;

}

}

___________________

package org.students;

public class Penny extends Coin{

private double value;

public Penny(String name, double value) {

super(name);

this.value = value;

}

public double getValue() {

return value;

}

public void setValue(double value) {

this.value = value;

}

}

___________________

package org.students;

public class Quarter extends Coin {

private double value;

public Quarter(String name, double value) {

super(name);

this.value = value;

}

public double getValue() {

return value;

}

public void setValue(double value) {

this.value = value;

}

}

___________________

package org.students;

import java.util.ArrayList;

public class Pocket {

ArrayList<Coin> arl;

public Pocket() {

super();

this.arl = new ArrayList<Coin>();

}

public void addCoin(Coin c) {

arl.add(c);

}

public void removeCoin(Coin c) {

arl.remove(c);

}

public int countCoins(Coin c) {

int count = 0;

for (int i = 0; i < arl.size(); i++) {

if (c.getName().equals(arl.get(i).getName())) {

count++;

}

}

return count;

}

public double calTotalValue() {

double totVal = 0;

for (int i = 0; i < arl.size(); i++) {

if (arl.get(i) instanceof Dime) {

Dime d = (Dime) arl.get(i);

totVal += d.getValue();

} else if (arl.get(i) instanceof Nickle) {

Nickle n = (Nickle) arl.get(i);

totVal += n.getValue();

} else if (arl.get(i) instanceof Penny) {

Penny p = (Penny) arl.get(i);

totVal += p.getValue();

} else if (arl.get(i) instanceof Quarter) {

Quarter q = (Quarter) arl.get(i);

totVal += q.getValue();

}

}

return totVal;

}

}

_________________

package org.students;

import java.util.Scanner;

public class PocketMain {

public static void main(String[] args) {

Pocket p = new Pocket();

/*

* Creating an Scanner class object which is used to get the inputs

* entered by the user

*/

Scanner sc = new Scanner(System.in);

System.out.println("1.Add a coin (must specify type)");

System.out.println("2.Remove a coin (must specify type)");

System.out.println("3.Display a coin count");

System.out.println("4.Display a total value in the pocket");

System.out.println("5.Exit");

System.out.print("Enter Choice:");

int choice = sc.nextInt();

switch (choice) {

case 1: {

}

case 2: {

}

case 3: {

}

case 4: {

}

case 5: {

}

default: {

}

}

}

}

_____________________