*
The moose likes Beginning Java and the fly likes Need help with code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need help with code" Watch "Need help with code" New topic
Author

Need help with code

dariusz rusiecki
Greenhorn

Joined: Apr 26, 2004
Posts: 4
can someone help me with this code
This first class file compiles fine with no errors
/**
* JavaProgram: StudentProfile.java
* @author Dariusz
* @version 19/03/04
*/
public class StudentProfile {

public String studentName;
private int studentID;
private char studentGrade;
public static int courseNumber;
public StudentProfile()
{
}
public void setStudentGrade(char grade)
{
studentGrade = grade;
}
public void setStudentID(int id)
{
studentID = id;
}
public char getGrade()
{
return studentGrade;
}
public int getId()
{
return studentID;
}
}
This second class file i get a compile error on the System.out.println line, is there anything wrong with this class file can someone help me.
/**
* JavaProgram: StudentTest.java
* @author Dariusz
* @version 19/03/04
*/
public class StudentTest {

StudentProfile student1 = new StudentProfile();

public StudentTest()

{
student1.studentName = "John Doe";
student1.setStudentID("3456");
student1.setStudentGrade();
System.out.println(student1.studentName() + student1.getStudentID() + student1.getStudentGrade());
}
}
Tiffany Rich
Greenhorn

Joined: Apr 22, 2004
Posts: 4
I am new to this stuff so this may not be correct but on your studentId you have as type int. And in your 2nd class you have quotations around the id number like you are passing it as a string. Try taking the quotations off from around your id number.
Sarojini Venky
Greenhorn

Joined: Apr 26, 2004
Posts: 3
Hi,
There are 3 problems in the code as far as I can make out.
1.As pointed out the setStudentId() is supposed to recieve an int parameter, & you're passing a String.
2.The setStudentGrade() method has been defined as recieving a char, but you aren't passing any parameter at point of invocation.
3.You haven't defined a setName() method, but you are calling it.
4. Since you are using the method in System.out.println(), I assume you would want the method to return a value.
Hope this helps you.
dariusz rusiecki
Greenhorn

Joined: Apr 26, 2004
Posts: 4
thanx for that dudes, i fixed the int problem, im having a problem with the grade part now.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
dariusz,
Could you be more descriptive of what you mean by, "im having a problem with the grade part now"?
Are you looking for help in resolving this problem? Specifically, what problem are you having? Compiler error? If so, what is it specifically? Runtime error? If so, what is it specifically? Is something not doing what you expected? What did you expect it to do? What does it seem to be doing?


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
dariusz rusiecki
Greenhorn

Joined: Apr 26, 2004
Posts: 4
well i think there might be something wrong with char studentGrade part.
C. Nimo
Ranch Hand

Joined: Mar 23, 2004
Posts: 82
Hi.
You have a method called setStudentGrade(char grade)
Your problem is that you just call setStudentGrade() with no
argument in the parenthesis.
Nimo.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help with code
 
Similar Threads
printing out all my instances...toString() method..
org.hibernate.MappingException: table refers to an unmapped class
how to get back bean value in javascript
Confused...returning certain types
Inheritance error?