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]
# 1

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());

hunter9000a at 2007-7-8 8:39:35 > top of Java-index,Java Essentials,New To Java...
# 2
System.out.println(name + " still owes " + ( 100 - aStudent.getCourseFee()));
mlka at 2007-7-8 8:39:35 > top of Java-index,Java Essentials,New To Java...
# 3
> if((name == aStudent.getName()))Use equals() for comparing Strings.
aniseeda at 2007-7-8 8:39:35 > top of Java-index,Java Essentials,New To Java...
# 4

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.

ted_trippina at 2007-7-8 8:39:35 > top of Java-index,Java Essentials,New To Java...
# 5
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?
Capsuda at 2007-7-8 8:39:35 > top of Java-index,Java Essentials,New To Java...
# 6
You know the "Understand" and "Get me" come off as rather rude.See my post above, only one minus sign, and put the sum in parentheses.
mlka at 2007-7-8 8:39:35 > top of Java-index,Java Essentials,New To Java...
# 7

> 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

SomeoneElsea at 2007-7-8 8:39:35 > top of Java-index,Java Essentials,New To Java...
# 8
Ok got it thanks alot
Capsuda at 2007-7-8 8:39:35 > top of Java-index,Java Essentials,New To Java...
# 9
There was nothing wrong with ted's its just he posted it while i was still posting mine.Sorry i didn't mean to come off rude. Thanks for your help guys.i'm just learning.
Capsuda at 2007-7-8 8:39:35 > top of Java-index,Java Essentials,New To Java...