|
|
|
| Am I sending you the right signals? |
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||||
|
|||||
|
Java headache problem
I am having problems with this program any help would be much appreciated:
Write a program named SellStocks that calculates the value of a stock sale. The user will be asked to enter the stock price, the number of shares to be sold, and the commission rate. The program will calculate the value of the shares by multiplying the stock price by the number of shares. It will also calculate the commission (the value of the shares multiplied by the commission rate) and the net proceeds (the value of the shares minus the commission). The following example shows what the user will see on the output command prompt. This program calculates the net proceeds from a sale of stock. Enter stock price: 10.125 Enter number of shares: .11 Value of shares: $111.38 Enter commission rate (as a percentage): 1.5 Commission: $1.67 Net proceeds: $109.71 I would post my program for you to decipher but at last compilation it had 31 errors so it is best to just treat it as a blank slate :0 |
|
#2
|
||||
|
||||
|
Re: Java headache problem
Well... dern. You want it in Java? Ya sure about that?
I could do it in seconds in C, C++, or PHP... ![]() So, I'll just say "Could I see the source code please?" and hope I can spot the error(s) there. ![]() |
|
#3
|
|||||
|
|||||
|
Re: Java headache problem
feast your eyes on 31 errors of pure Java!
File 1: public class SellStock { public SellStock() { price = 0; numbers = 0; value = 0; commission = 0; rate = 0; proceeds = 0; } public void addPrice(double count) { price = price + count; } public void addNumbers(int count) { numbers = numbers + count; } public void addRate(double count) { rate = rate + count; } public void addValue() { value = price * numbers } public void addCommission (double rate) { commission = value * (rate/100); } public double getProceeds() { return value - commission; } } File 2: public class SellStockTest { public static void main(String[] args) { SellStock iSellStock = new SellStock(); iSellStock.addPrice(10.125); iSellStock.addNumbers(11); iSellStock.addCommission(1.5); double totalValue = iSellStock.getProceeds(); System.out.print("This program calculates the net proceeds from a sale of stock to be:"); System.out.println(getProceeds); } } Last edited by MisterX : 30-03-2005 at 11:01. |
|
#4
|
||||
|
||||
|
Re: Java headache problem
Quote:
![]() I'll say the same thing: source code would be tres easier for us. |
|
#5
|
|||||
|
|||||
|
Re: Java headache problem
Quote:
It is also a good idea to learn from your mistakes, so you do not make the same mistakes again.. If you post the code, I am sure someone would be able to spot the errors within just a small amount of time. EDIT: I see you posted the code while I was typing. |
|
#6
|
||||
|
||||
|
Re: Java headache problem
Quote:
Next, missing a semicolon on in the addValue() function. Finally, getProceeds in println is a function so getProceeds() I'll check for logic errors next, but those are the syntax. Hope that helps. Going on to some logic / style issues. Firstly, dont always name variables count. Good practices mean using descriptive variables, also in Java, set and get are the terms used in code, not usually add. The program was meant to take input from a terminal window according to the description, are you just testing the class itself before implementing a user input? Last edited by dm0ney : 30-03-2005 at 11:03. |
|
#7
|
|||||
|
|||||
|
Re: Java headache problem
Quote:
|
|
#8
|
|||||
|
|||||
|
Re: Java headache problem
Quote:
Hope its better |
|
#9
|
||||
|
||||
|
Re: Java headache problem
Code:
public class SellStockTest
{
public static void main(String[] args)
{
//Declares, Instantiates new SellStock class
SellStock iSellStock = new SellStock();
//Price of stock
iSellStock.addPrice(10.125);
//Number of stock
iSellStock.addNumbers(11);
//Calculate Value of Stock!
iSellStock.addValue();
//Add commission owed from stock sales, Calculates
iSellStock.addCommission(1.5);
//Not sure what you wanted here?
double totalValue = iSellStock.getProceeds();
//Print out statements
System.out.print("This program calculates the net proceeds from a sale of stock to be:");
//This could either be as follows or you could printout totalValue since you declared it above.
System.out.println(iSellStock.getProceeds());
}
This is an edited version of the last class. You never calculated the value of the stock, so it would output zero. I added your function call to calculate Value (addValue()) and to my knowledge it works in that implementation. Might I suggest using setValue, setXXXX, getXXXX for variables. The addXXXX gets confusing. Also change the counts to something even iXXXX where X is the variable and set price = iPrice. Hope that helps, Good Luck. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Strange Encoder Problem | AIBob | Electrical | 3 | 20-02-2005 22:20 |
| Programming Problem: Extremely Frustrating | chantilly_team | Programming | 19 | 12-02-2005 23:00 |
| Java Books | Yan Wang | Programming | 1 | 27-12-2002 16:26 |
| The problem with scouting... | archiver | 2001 | 10 | 23-06-2002 23:49 |
| Major problem with chipphua motors | aka Scott White | Motors | 18 | 19-03-2002 19:44 |