# Program compiled/ran as required - FAILED project WHY??????????

• June 22nd, 2010, 03:56 AM
MISSAJ
Program compiled/ran as required - FAILED project WHY??????????
Hey People! I am Miss AJ, I'm 3 classes away from my masters in info systems and got my 1st f

( I really hope I did this correctly - let me know if I did something wrong, partaining to how to post on here.)

Wrote a program for class, got a failing grade, although it compiled and ran as it was supposed to. I need to know what's wrong because the addition to this program is do for my final in 2 weeks.

I have seen the program that received a perfect score but I still do not understand what exactly is wrong with mine. You've seen the requirments on here under CashForMetals. I'll post the requirements, then the code my partner and I wrote (that got us an 18 out of 30) and the requirements for the addition just so you'd know what is expected of me next. If I can understand what i did wrong,

Program Requirements -

Project 1 – Cash for Metals
Given the economic conditions, businesses have sprouted offering money for unwanted jewelry, antiques and collectibles to people in need of cash. The service makes exchanging goods for cash easy and discrete.
You have been tasked by “Cash for Metals” to write a program which will help calculate the amount they will pay customers for their precious metals. Customers mail an envelope filled of metals to Cash for Metals, who create a proposal for purchasing of the metals from the customer. Below are the program requirements:
Read the entire assignment before proceeding to coding – be sure to follow the implementation notes!
1. First, some introductory lines are printed welcoming the user to the program:
*** ***
*** Welcome to Cash for Metals Calculator!!! ***
*** ***

2. The program will begin asking for information about the customer and the metals they have submitted as follows.
a. Customer’s Name (String)
b. Weight of Gold (double)
c. Weight of Silver (double)

3. Processing of Data
a. Create a unique 8 digit number (int) to identify the customer (use the Math random function)
b. The following conversion rates will be used for calculation of the amount of money offered for each metal the customer has submitted and a total amount

Gold \$400.50/ounce
Silver \$6.25/ounce

c. Asses a 10% handling fee

4. Display the data
a. Display the customer’s ID
b. Display the customer’s name
c. Display the amount of money to be offered for each metal
d. Display the handling fee
e. Display the net amount of money to be offered to the customer

5. Ask the user if they wish to enter another customer – assume the user will enter either “Yes” or “No” (use the equalsIgnoreCase when checking the user’s response). If yes, you should start inputting values again (step 2). If no, continue to step 6.

6. Display a summary of the user’s input for all customers as follows:
a. Total weight for each metal from all customers
b. Total dollar amount of money to be offered for each metal for all customers
c. Grand total for all metals for all customers

Display Values
Note that different values must displayed in different ways. Here are some examples
Display Item Format Examples
Metal Weight Round to 2 decimals, one digit left of decimal 325.40
0.56
Dollar Amount Dollar sign, round to 2 decimals, one digit left of decimal \$200.34
\$45.50
\$0.35
Implementation notes
• The file you submit must be named CashforMetals.java – no exceptions!
• Your output must match the sample output!
• You may assume all values are entered in ounces and no weight conversion is required
• All constants must be declared as final variables in all upper case
• You need to minimize the amount of code you duplicate! In most situations, if you find yourself writing the exact same conditions, or the exact same conditional statement, or the exact same loop, a second, third, fourth, or fifth time, you are probably duplicating code you don't need to duplicate.

1. Reasonable data validation must be implemented for all values entered by the user. Processing should not continue until valid data has been entered
2. Create a method to handle the requirements of 3a
3. Create a method to handle the requirements of 3b

THE PROGRAM/CODE WE WROTE
Code :

```//Importing Java Class Scanner   package Project1;   //import java classes Start   import java.util.Scanner;   import java.util.*;   //import java classes Ends     public class CashforMetals   {   private static double goldrate = 400.50;   private static double silverrate = 6.25;   private double goldoffer;   private double silveroffer;   private double handlingfee;   private static double gold;   private static double silver;   private static double grandtotalgoldounces;   private static double grandtotalsilverounces;   private static double grandtotaloffer;   private static double finaltotal; 　   //Method to generate Random number for customer starts   public void random_number()   {   System.out.println("Customer ID is:" + (int)(Math.random()*100000000));   }   //Method to generate Random number for customer ends   //Method for gold conversion rate Starts   public double Gold_Offer()   {   return goldoffer = goldrate * gold ; //Gold offer   }   //Method for gold conversion rate Ends   //Method for silver conversion rate Starts   public double SilverOffer()   {   return silveroffer = silverrate * silver;   }   //Method for silver conversion rate Ends     public static void main(String[] args) //Main Method Starts   {   //Variable declaration Starts   String name;   String answer;   int random_number;   String EnterAnotherCustomer ="";   //Variable declaration Ends   // Welcome Banner Start   System.out.println("*** ***");   System.out.println("*** Welcome to Cash for Metals Calculator!!! ***");   System.out.println("*** ***");   // Welcome Banner End   Scanner input = new Scanner( System.in );   do //DO WHILE Loop begins   {   //Prompting user for information Starts   System.out.println("Enter your name:");   name = input.next();   System.out.println("Enter the weight of the Gold in ounces: ");   gold = input.nextDouble();   System.out.println("Enter the weight of the Silver in ounces: ");   silver = input.nextDouble();   //Prompting user for information Ends   //Calling Random Number Method Starts   CashforMetals chasformetalsObject = new CashforMetals();   chasformetalsObject.random_number();   //Calling Random Number Method Ends   //Calling Method for Goldoffer Starts   CashforMetals goldoff = new CashforMetals();   goldoff.Gold_Offer();   //Calling Method for Goldoffer Ends   //Calling Method for Silveroffer Starts   CashforMetals silveroff = new CashforMetals();   silveroff.SilverOffer();   //Calling Method for Silveroffer Ends   //Displaying the customer data begins   System.out.printf("The name is %s\n", name);   System.out.printf("The weight input for gold was %.2f\n", gold);   System.out.printf("The weight input for silver was %.2f\n", silver);   System.out.printf("The Offer for Gold is \$ %.2f\n", goldoff.goldoffer);   System.out.printf("The Offer for the Silver is \$ %.2f\n", silveroff.silveroffer);   System.out.printf("The Offer to the customer, minus the handling fee is \$ %.2f\n", ((goldoff.goldoffer + silveroff.silveroffer) - ((goldoff.goldoffer + silveroff.silveroffer) * .1)));   //Displaying the customer data ends     //Calculating total for all metals Begins   grandtotalgoldounces = grandtotalgoldounces + gold;   grandtotalsilverounces = grandtotalsilverounces + silver;   grandtotaloffer = (grandtotalgoldounces * goldrate) + (grandtotalsilverounces * silverrate);   finaltotal = grandtotaloffer - (grandtotaloffer * 0.1);   ////Calculating total for all metals Ends     System.out.print("Enter YES to enter another Customer\n ");   EnterAnotherCustomer = input.next();   }while(EnterAnotherCustomer.trim().equalsIgnoreCase("YES")); //DO WHILE Loop Ends   //Displaying the Summary total weith metal and offer for all customers Begins   System.out.printf("The Total weight for gold was %.2f\n", grandtotalgoldounces);   System.out.printf("The Total weight for silver was %.2f\n", grandtotalsilverounces);   System.out.printf("The Total offer for all Metals is %.2f\n", finaltotal);   //Displaying the Summary total weith metal and offer for all customers Ends   }////Main Method Ends     }//Class CashforMetals Ends```

THIS IS THE OUTPUT WE RECEIVED

run:
*** ***
*** Welcome to Cash for Metals Calculator!!! ***
*** ***
Dan
Enter the weight of the Gold in ounces:
1.14
Enter the weight of the Silver in ounces:
3.67
Customer ID is:87102244
The name is Dan
The weight input for gold was 1.14
The weight input for silver was 3.67
The Offer for Gold is \$456.57
The Offer for the Silver is \$22.94
The Offer to the customer, minus the handling fee is \$431.56
Enter YES to enter another Customer
yes
Sosa
Enter the weight of the Gold in ounces:
25.1
Enter the weight of the Silver in ounces:
109
Customer ID is:22946702
The name is Sosa
The weight input for gold was 25.10
The weight input for silver was 109.00
The Offer for Gold is \$10052.55
The Offer for the Silver is \$681.25
The Offer to the customer, minus the handling fee is \$9660.42
Enter YES to enter another Customer
no
The Total weight in ounces for gold was 26.24
The Total weight in ounces for silver was 112.67
The Total offer for all Metals is \$10091.98
BUILD SUCCESSFUL (total time: 30 seconds)

THE ADDITION TO THIS PROJECT - THAT I AM AFRAID TO BEGIN BECAUSE EVIDENTLY I HAVE NO CLUE WHAT I'M DOING

Project 2 – Cash for Metals
Cash for Metals is now expanding their business to allow for both Personal and Commercial customers. Also, they are offering their customers interest if they keep their money with Cash for Metals much like a bank. Furthermore, some customers are repeat customers and Cash for Metals needs a way to keep track of multiple transactions for a customer.
Read the entire assignment before proceeding to coding – be sure to follow the implementation notes!
First, some introductory lines and a menu of options are printed welcoming the user to the program:
*** ***
*** Welcome to Cash for Metals Calculator!!! ***
*** ***
1. Create Personal Customer
2. Create Commercial Customer
3. Record Transaction
4. Make Withdrawal
5. Display Customer
6. Display Customer Summary
7. Display Grand Summary
8. Exit

1. Create Personal Customer
a. The constructor will take 1 String – the name of the Customer. The constructor should set the customer name and generate the Customer ID (long).
b. Write a get method for the customer Name (String).
c. Write get/set methods for address (String), home phone (String) and work phone (String).
d. Write a get method for the Customer ID(long) and Account
2. Create Commercial Customer
a. The constructor will take 1 String – the name of the Customer. The constructor should set the customer name and generate the Customer ID (long).
b. Write a get method for the customer Name (String).
c. Write get/set methods for address (String), contact person (String), and contact person phone (String).
d. Write a get method for the Customer ID (long) and Account
e. Commercial customers get 3% more for their transactions above the standard price
3. Accounts
a. Create an Account for each customer. An account will have an account number (long), balance (double), date opened (Calendar) using the current date/time and interest rate (double).
b. Accounts have a default balance of 0 (balances cannot be less then 0) and a rate of 3%
c. Get methods should be created for each attribute
d. Accounts have two methods: makeDeposit (returns void) and makeWithdrawal (returns actual amount withdrawn from the account)
e. Note the account should be created when the Customer is created.

4. Record Transaction
a. Ask for the customer ID
b. If the customer ID is not found, state the ID could not be found and restart the menu
c. The transaction constructor will take no parameters, but will generate a Transaction ID (long) and will set the date/time of the transaction (Calendar) using the current date/time
d. Write get/set methods for Weight of Gold (double), Weight of Silver (double)
e. Write a get method for total value of the transaction (double)
f. Part of the transaction recording should include making a deposit into the Customer’s account for the appropriate amount
g. The transaction should be added to the Customer

5. Make Withdrawal
a. Ask for the customer ID
b. If the customer ID is not found, state the ID could not be found and restart the menu
c. Ask for the amount to be withdrawn from the account.
d. Withdraw the money from the account – the amount to be withdrawn must be greater then 0

6. Display Customer
a. Display the customer’s name
b. Display the customer’s ID
c. Display the details of their account
d. Display the details of each transaction

7. Display Customer Summary
a. Display the total number of customers
b. Display the sum total value of all accounts

8. Display Grand Summary
a. Display information for all customers

Reference
Display Values
Note that different values must displayed in different ways. Here are some examples
Display Item Format Examples
Metal Weight Round to 2 decimals, one digit left of decimal 325.40
0.56
Dollar Amount Dollar sign, round to 2 decimals, one digit left of decimal \$200.34
\$45.50
\$0.35
Metal Values
Gold \$400.50/ounce
Silver \$6.25/ounce
Implementation notes
• The files you submit will be (but don’t have to be exactly): CashForMetalsClient.java, Customer.java, PersonalCustomer.java, CommericalCustomer.java, Transaction.java, Account.java
• Customers will have one account, but can have multiple transactions
• You must use inheritance to relate Customer, PersonalCustomer and CommericalCustomer classes. Review the attributes of each and be sure there are no duplicates across classes.
• You should write toString methods overriding the Object toString for the following classes: Customer, PersonalCustomer, CommercialCustomer, Account and Transaction
• You have been provided a number of classes to use. It is not recommended to modify the code provided to you.
• Your output must match the sample output!
• You may assume all values are entered in ounces and no weight conversion is required
• All constants must be declared as final variables in all upper case
• You need to minimize the amount of code you duplicate! In most situations, if you find yourself writing the exact same conditions, or the exact same conditional statement, or the exact same loop, a second, third, fourth, or fifth time, you are probably duplicating code you don't need to duplicate.

THANKS FOR ALL YOUR TIME AND FOR YOUR ASSISTANCE AND WILLINGNESS TO HELPwhy?????
• June 22nd, 2010, 04:05 AM
Jelula
Re: Program compiled/ran as required - FAILED project WHY??????????
You might want to edit your post to make it more readable, if you're having trouble with the [code ] [ /code] function it's easier just to click "Go Advanced" select your code and then press the # button.
• June 22nd, 2010, 07:08 AM
Norm
Re: Program compiled/ran as required - FAILED project WHY??????????
Quote:

Did the prof give any reasons or coments on why?

You've posted what looks like the full assignment. Not all of us like wading thru so much text trying to figure out what your problem is.
Can you ask specific questions that you are having problems with?
• June 22nd, 2010, 08:09 AM
Norm
Re: Program compiled/ran as required - FAILED project WHY??????????
Quote:

//Calling Method for Goldoffer Starts
Comments like these are redundant. The code shows that you are calling the method. Another example of that kind of comment:
i = i + 1; // add 1 to i
The comment should say WHY you are calling the method or adding 1 to i.
• June 22nd, 2010, 09:15 AM
copeg
Re: Program compiled/ran as required - FAILED project WHY??????????
Just briefly going over some of the requirements, the following two requirements may not have been met:
Quote:

All constants must be declared as final variables in all upper case
Quote:

Reasonable data validation must be implemented for all values entered by the user. Processing should not continue until valid data has been entered
There may be other requirements not explicitely stated in the assignment but things you should show you've learned in the class, such as using an object oriented approach (which may allow for extension and modification later on), adding javadoc commenting, or following java code convensions (see Code Conventions for the Java Programming Language). The best person to ask however, is your teacher or teaching assistant.
• June 23rd, 2010, 04:15 AM
Faz
Re: Program compiled/ran as required - FAILED project WHY??????????
OK your code is very hard to read the code tags work by putting them before the start of your code and closing them at the end not on every line.

But from the looks of things I would agree with Norm on the commenting I personally am very bad when it comes to this for my own projects but if it's for college I make sure the comments are relevant as some teachers will give marks for comments and if the code doesn't work they at least see your thought process(which is often more important then the code itself)

But more importantly everything is in one class from what I can see. Generally speaking you want to write classes that do the work as sperate to ones that take in input from the user.

Theres other things like what copeg mentioned. However there is only so much help we can give. Have you talked to your lecturer/tutor about why you got a fail? If you are 2 weeks from the end of your course and you've never talked to your lecturer you could be in a spot of bother(I've seen this happen). But basically I would recommend that if you have a class soon talk to the lecturer or if not send them an e-mail and ask for a meeting to discuss where you are.
• June 23rd, 2010, 06:57 AM
JavaPF
Re: Program compiled/ran as required - FAILED project WHY??????????
I have edited your original post to include the single code tag around the code.
• June 23rd, 2010, 03:35 PM
Charlie
Re: Program compiled/ran as required - FAILED project WHY??????????
I know it's been said before but: Make it more readable. :P

I just added this to my netbeans and even tho the IDE itself gives me a rather good
view of code, I'm still having problems reading it properly due to comments everywhere
and the code, emptyline, code, emptyline, code... sort of layout. Make it a practice to always:
* Indent new code when you bracket a new segment, e.g:
Code :

```public void methodName(){ blabla++; <---- indented }```
*Make more room when something new is happening, its usually where you also want comments.
and dont use them double spacing between lines, it just looks really hard to read, not to mention
it makes the code twice as long.

Having a "short" application isn't a bad thing. In fact the less code used for a certain task, the better.

//End of wall-of-text
I'm gonna start plowing through this now just to get a bit of practice anyways. So PM me if you see this anytime soon and we can work through it together.