System.out.println
Ok i'm having trouble with a method that shows how much a student still owes to a summercamp. The camp fee is 100. I have an arraylist student.
You will see that i want the system.out.println to print that the 'student owes 100 - whatever he has paid so far'. Understand?
But i'm not really sure how to do this...could you help please thanks
/**
* This method will show the coursefee still outstanding for a student.
*/
publicvoid feeOutstanding(String name)
{
for (Student aStudent : students)
{
if((name == aStudent.getName()))
{
if((aStudent.getCourseFee < 100))
{
System.out.println((name +" still owes " + 100 -- aStudent.getCourseFee()));
}
else
{
System.out.println("There is no outstanding fee");
[1264 byte] By [
Capsuda] at [2007-11-26 14:51:24]

System.out.println((name + " still owes " + 100 -- aStudent.getCourseFee()));
You have an extra pair of parentheses around the parameters for some reason, those aren't needed.
You can't use -- there, if you want to print out "--" you have to make a string out of it and concatenate it properly.
System.out.println(name + " still owes " + 100 + " -- " + aStudent.getCourseFee());
public void feeOutstanding(String name)
{
for (Student aStudent : students)
{
if(name.equals(aStudent.getName())) // use equals instead of ==
{
if(aStudent.getCourseFee() < 100) // missed some parentheses
{
System.out.println(name + " still owes " + (100 - aStudent.getCourseFee()));
}
else
{
// bla bla bla
}
}
}
}
Ted.
> You see i don't actually want to print out the --.
> What i want is for it actually to do the sum for me
> if you understand. so i want it to do 100 minus
> whatever they have paid already. eg. if they have
> paid 60 already, it will print out 'name still owes
> 40'
>
> Get me?
Then whats wrong with Ted's reply #4?
~Tim