I\'m having trouble with wrting this program the objective is to I. Your “GoldDi
ID: 671508 • Letter: I
Question
I'm having trouble with wrting this program the objective is to
I. Your “GoldDigger” Class
Create a class with these instance variables:
The name of the coin
The current price of gold, per ounce
The selling price of the coin
The shipping and handling charges, per coin
The sales tax rate
The amount of gold in the coin, in milligrams
Your class will have a constructor to initialize the instance variables, accessor (i.e. “get”) methods to return the values of the instance variables, and a mutator (i.e. “set”) method that updates the price of an ounce of gold.
Your class will have 2 additional methods:
A method that computes and returns the number of coins one would have to purchase in order to own one full ounce of gold
A method that computes and returns the premium (the extra amount you would pay) when buying one ounce’s worth of coins (total cost of the number of coins computed by the above method, including S & H and sales tax) versus buying an ounce of gold.
Sales tax must be paid on the entire order for the coins, including the S & H, but not when buying the gold outright.
II. The Test Class
Now create a test class (aka: “client code”) that uses the class you created above. In the main method you will
create an object
call the accessor methods to get the data and print it
get and print the number of coins (method 1., above)
get and print the premium (method 2., above)
modify the price of an ounce of gold
get and print the updated price of gold
get and print the new premium
III. Additional Specifications
All numeric instance variables must be type double
All output is to be done in the test class. None of the GoldDigger class methods does any output
The test class must call the accessor methods to get the data stored in the instance variables, and must call separate methods to compute and return the number of coins and the premium
Make sure all output is neatly presented and clearly labeled
Do not be concerned with the number of decimal places printed – we will soon learn how to control that. Although your program must work for any valid data, use this data in the run you hand in:
Name of the coin: $50 Gold Buffalo
Price of gold, per ounce: 1242.30
Selling price of the coin: 9.95
Shipping and handling charges: 4.95
Sales tax rate: 7.5%
Amount of gold in the coin, in mg: 14.0
Updated price of gold: 1655.50
Explanation / Answer
// GoldDigger.java
public class GoldDigger{
String name;
double priceGold;
double priceCoin;
double charges;
double tax;
double amount;
GoldDigger(String n, double pc, double pg, double c, double t, double a){
name = n;
priceCoin = pc;
priceGold = pg;
charges = c;
tax = t;
amount = a;
}
String getName(){
return name;
}
double getPriceCoin(){
return priceCoin;
}
double getPriceGold(){
return priceGold;
}
double getCharges(){
return charges;
}
double getTax(){
return tax;
}
double getAmount(){
return amount;
}
void setPriceGold(double pg){
priceGold = pg;
}
double numberOfCoins(){
return 28349.5 / amount;
}
double premium(){
return (priceCoin + charges) * tax * numberOfCoins() / 100.0 - priceGold;
}
}
// Goldtest.java
public class Goldtest{
public static void main(String args[]){
GoldDigger coin = new GoldDigger("$50 Gold Buffalo", 9.95, 1242.30, 4.95, 7.5, 14.0);
System.out.println("Number of coins needed: " + coin.numberOfCoins());
System.out.println("Total premium paid: " + coin.premium());
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.