Hello -
I am a student who bis mid-semester in an OOP course, with zero programming experience. I am trying to understand the concepts but this stuff is tough....I have an increased level of respect for all of the developers out there!
Here is my question..in the code i am posting below. I am trying to set and then get some user entered info..but when i run the program the values for Gold and silver are not storing...because my default statment for two 0 entries is displaying.
When i comment out the code, or change the math so that 0 doesnt trigger the code..i can see that the "customer" stores and the unique ID prints fabulously.
Can anyone explain what I am missing?
import java.util.Scanner;
public class CashForMetalsClient
{
static String more;
static String c;
static double g, s, goldtw, silvertw, valueg, values, tvsilver, tvgold, sum, wsum, fee, net;
static final double GOLD = 400.50;
static final double SILVER = 6.25;
public static final Scanner input = new Scanner( System.in);
public static void Conversion()
{
valueg = (Customer.getGoldWeight()) * (GOLD);
values = (Customer.getSilverWeight()) * (SILVER);
sum = valueg + values;
fee = (sum)*.10;
net = (sum - fee);
tvgold = (goldtw) * (GOLD);
tvsilver = (silvertw) * (SILVER);
System.out.printf("\nCurrent Cash offer for gold weight entered:$%.2f\n",valueg);
System.out.printf("Current Cash offer for silver weight entered:$%.2f\n",values);
System.out.printf("The total amount offered for all metals, before deduction of handling fee is:$%.2f\n\n",sum);
System.out.printf("The handling fee for this transaction is:$%.2f\n",fee);
System.out.printf("The Net amount of cash "+Customer.getCustomer()+" will recieve for this transaction is:$%.2f\n\n",net);
}
public static void main (String [] args)
{
System.out.println("***\t\t\t\t\t\t\t***");
System.out.println("***\tWelcome to Cash for Metals Calculator!!!\t***");
System.out.println("***\t\t\t\t\t\t\t***\n");
do
{
System.out.print("Please enter Customer Name: ");
c = input.next();
Customer.setCustomer(c);
System.out.print("Enter weight of GOLD (in ounces) you would like to sell: ");
g =input.nextDouble();
Customer.setGoldWeight(g);
if (goldw < 0)
{
System.out.println("***You have entered an invalid weight.***");
System.out.printf("\nPlease enter a 0(zero) if you have no gold to sell.");
System.out.print("\nEnter weight of GOLD (in ounces) you would like to sell: ");
g =input.nextDouble();
Customer.setGoldWeight(g);
goldtw += Customer.getGoldWeight();
}
else
{
goldtw += Customer.getGoldWeight();
}
System.out.print("Enter weight of SILVER (in ounces) you would like to sell: ");
s =input.nextDouble();
Customer.setSilverWeight(s);
if (Customer.getSilverWeight() < 0)
{
System.out.println("***You have entered an invalid weight.***");
System.out.printf("\nPlease enter a 0(zero) if you have no silver to sell.");
System.out.print("\nEnter weight of SILVER (in ounces) you would like to sell: ");
s =input.nextDouble();
Customer.setSilverWeight(s);
silvertw += Customer.getSilverWeight();
}
else
{
silvertw += Customer.getSilverWeight();
}
wsum = (Customer.getSilverWeight())+ (Customer.getGoldWeight());
if (wsum >= 1)
{
System.out.println();
System.out.println("Unique Customer ID: "+Customer.getID());
System.out.println("Customer Name: "+Customer.getCustomer());
CashforMetals.Conversion();
System.out.print("Would you like to enter another customer(Yes/No)? ");
more = input.next();
System.out.println();
}
else
{
System.out.println("TRANSACTION CANCELLED---You have indicated you have no metal to sell.\n");
System.out.print("Would you like to enter another customer(Yes/No)? ");
more = input.next();
System.out.println();
}
}
while (more.equalsIgnoreCase("yes"));
System.out.println("*****************************************************");
System.out.println("\tSession Totals - Transaction Summary\t");
System.out.println("*****************************************************");
System.out.println("Total Gold Weight this session: "+goldtw);
System.out.println("Total Silver Weight Silver this session: "+silvertw);
System.out.printf("Total Cash offered for Gold this session:$%.2f",tvgold);
System.out.printf("\nToal Cash offered for Silver this session: $%.2f",tvsilver);
System.out.printf("\nGrand Total Cash offered for metals this session: $%.2f",tvgold+tvsilver);
}
}