• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help with code

 
dariusz rusiecki
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx for that dudes, i fixed the int problem, im having a problem with the grade part now.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
dariusz rusiecki
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well i think there might be something wrong with char studentGrade part.
 
C. Nimo
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
You have a method called setStudentGrade(char grade)
Your problem is that you just call setStudentGrade() with no
argument in the parenthesis.
Nimo.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic