aspose file tools*
The moose likes Beginning Java and the fly likes please help --creating class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "please help --creating class" Watch "please help --creating class" New topic
Author

please help --creating class

Monic Sherm
Greenhorn

Joined: Sep 30, 2005
Posts: 13
I am trying to run this program. Part of the program is supposed to be user input # of credit hour and the total fees. It compiles and runs but will not output the fee.


[ September 30, 2005: Message edited by: Mark Spritzler ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Well, the only code that could possible print anything out

//System.out.println ("Student Bill:" , TotClassFee() );

is commented out. So nothing will print.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Also to help out is Sun's coding standards. Your code is fine, but would look nicer following those standards.

A couple of them

method names start with a lowercase letter as in

isOk() or myMethodThatRuns.

Here is the link to Sun's Java Coding standards document.

Good Luck

Mark
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 985

Maybe because you have it commented out?


Please ignore post, I have no idea what I am talking about.
Monic Sherm
Greenhorn

Joined: Sep 30, 2005
Posts: 13
I'm sorry . I meant to remove that line. The code will not compile with that line included. So I still need help
Monic Sherm
Greenhorn

Joined: Sep 30, 2005
Posts: 13
I forgot to say Thanks in advance for your help
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

The commented-out line is calling a method named TotClassFee() that doesn't exist. You mean to print the variable TotClassFee, I imagine (no parentheses).

But you surely don't want the getTotClassFee() method to print anything at all, right? That's the main program's job. It needs to capture the value returned from calling that function into a variable of its own, and then print that variable. Make sense?


[Jess in Action][AskingGoodQuestions]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
As everyone has pointed out, the computer will only do what you tell it to do. So you need to have a System.out.println() call in order to print something out. As Ernest says, this line probably belongs in your main() method, not in the getTotClassFee() method.

Layne


Java API Documentation
The Java Tutorial
Raghuveer Kumarakrishnan
Ranch Hand

Joined: Mar 13, 2005
Posts: 32
//System.out.println ("Student Bill:" , TotClassFee() );

In addition to that your print statement has a "," instead of a "+"


Replace that line with this:
System.out.println ("Student Bill:" + TotClassFee);


Raghu<br />SCJP 1.4<br />SCWCD 1.4<br />SCBCD 1.3
Kenneth Albertson
Ranch Hand

Joined: Sep 18, 2005
Posts: 59
Monic, there are some problems with the logic of your program, and you will have to sort them out before it will do what you want.

The program code you have shown us reads the number of credit hours from the user, BUT it doesn't pass that information to the myStudentBill object, so the object won't be updated, and even when you do work out how to print out the fees value, it won't be correct.

Also, once you update the credit hours in the object, how will the TotClassFee field get updated? The class has two methods to do this (StudentBill() and ClassFee() - you don't need both of these) but they will only execute if instructed to do so. A good way to do this would be to give the class a setCreditHours() method, which would:
  • Be passed the new credit hours value
  • Update the credit hours field
  • Calculate and update the TotClassFee field
  •  
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: please help --creating class