View Single Post
  #6   Spotlight this post!  
Unread 30-03-2005, 10:58
dm0ney's Avatar
dm0ney dm0ney is offline
Will Code For Food (Food Optional)
AKA: Deepak Mishra
None #0217 (The ThunderChickens)
Team Role: Alumni
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Shelby Twp., MI
Posts: 48
dm0ney will become famous soon enough
Send a message via AIM to dm0ney
Re: Java headache problem

Quote:
Originally Posted by MisterX
feast your eyes on 31 errors of pure Java!

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;
}
}

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);
}
}
SellStock should not be a public class, only class. You cannot have two public classes declared in the same file.

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?
__________________

Alumni
Team #217, The ThunderChickens



Student, Class of 2009
California Institute of Technology



Last edited by dm0ney : 30-03-2005 at 11:03.