I could use some help with making sure that I am on the right path of the assignment's directions(assignment is below). I have also began a rough outline of what I interpreted the instructions (see code below) as. I would deeply appreciate if you could answer this question:
Am I on the right path of and am I interpreting the instructions correctly or no?
Also if I am, is there any coding suggestions that you could make or
If I am wrong, could you please point me in the right direction?
ASSIGNMENT
Quote
* Implement a class Coin that represents any coin.
* The class should store the name and the value of the coin
* provide appropriate methods to retrieve these two attributes
* Write a toString method that returns a string representation of the current value and name of the object.
* In addition, you should be able to clone objects of this class
* also to compare any two Coin objects.
* provide an implementation of the equals method that is compatible with the method equals of the class Object.
*
* You must also create a test program that test your class as $1.00, $0.50, $0.25, $0.10, $0.05, and $0.01 coins.
* Please make sure you are using GIT and you submit your compressed folder.
* Make sure you do a final git add and git submit when you are completely done with your program.
*/
MY ROUGH CODE
/**
* Implement a class Coin that represents any coin.
* The class should store the name and the value of the coin
* provide appropriate methods to retrieve these two attributes
* Write a toString method that returns a string representation of the current value and name of the object.
* In addition, you should be able to clone objects of this class
* also to compare any two Coin objects.
* provide an implementation of the equals method that is compatible with the method equals of the class Object.
*
* You must also create a test program that test your class as $1.00, $0.50, $0.25, $0.10, $0.05, and $0.01 coins.
* Please make sure you are using GIT and you submit your compressed folder.
* Make sure you do a final git add and git submit when you are completely done with your program.
*/
package programmingassignmentunit5;
import java.util.InputMismatchException;
import java.util.Scanner;
/**
* @date 3/6/2013
* @author k3y
*/
class ProgrammingAssignmentUnit5 {
private static Scanner console = new Scanner(System.in);
private static int userChoice;
private static String nameCoin;
private static boolean acceptableInput = false;
private static String menu =
"$0.01 - Penny (1)\n"
+ "$0.05 - Nickel (2)\n"
+ "$0.10 - Dime (3)\n"
+ "$0.25 - Quarter (4)\n"
+ "$0.50 - Half Dollar (5)\n"
+ "$1.00 - Gold Dollar (6)\n"
+ "Please enter the (value) that specifies your coin";
/**
* This method will:
* 1. print menu of coin name
* 2. return the correct name for the selected option
* @return name of coin
*/
private static String getCoinName() {
nameCoin = null;
System.out.println(menu);
do{
try{
userChoice = console.nextInt();
}
catch(InputMismatchException | NumberFormatException e){
System.err.println(e.toString());
}
catch(Exception e){
System.err.println(e.toString());
}
finally{
switch(userChoice){
case 1:
nameCoin = "Penny";
break;
case 2:
nameCoin = "Nickel";
break;
case 3:
nameCoin = "Dime";
break;
case 4:
nameCoin = "Quarter";
break;
case 5:
nameCoin = "Half Dollar";
break;
case 6:
nameCoin = "Gold Dollar";
break;
default:
System.err.println("Invalid Option");
break;
}
}
}while(!(acceptableInput));
return nameCoin;
}
private static double getCoinValue() {
/* */
}
static class Coin{
public String nameOfCoin;
public double valueOfCoin;
private Coin(String nameOfCoin, double valueOfCoin) {
String coinName = nameOfCoin;
double coinValue = valueOfCoin;
}
}
public static void main(String[] args) {
String nameOfCoin = getCoinName();
double valueOfCoin = getCoinValue();
Coin coinObject = new Coin(nameOfCoin, valueOfCoin);
}
}
Thank You
This post has been edited by k3y: 06 March 2013 - 09:34 AM

New Topic/Question
Reply




MultiQuote










|