I am trying to create a simple java project Student Management System

I have a problem in compiling 2 java files I can't seem to connect them both. Those 2 java files are under the same folder
No description
No description
No description
No description
No description
11 Replies
JavaBot
JavaBot2d ago
This post has been reserved for your question.
Hey @wrain2055! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Larry_springboot
Use this. Or getters as specified
wrain2055
wrain2055OP2d ago
I did try to use it but is it correct?
No description
Larry_springboot
Can you upload the whole class
Kyo-chan
Kyo-chan2d ago
Syntax highlighting colors show very clearly that you have one too many }
wrain2055
wrain2055OP2d ago
public class Student {
private final String name;
private final int age;
private final int id;

//constructor for Student
public Student (String name, int age, int id){
this.name = name;
this.age = age;
this.id = id;
}
}


// Getter method to get the student's name
public String getName(){ //getName is a method to get the student's name
return name; //return the student's name
}

//setter method to set the student's name
public void setName (String name ){
this.name = name; //set the new name
}

public int getAge(){
return age;
}

public void setAge (int age ) {
this.age = age;
}
public int getId(){
return id;
}
public void setId(int id){
this.id = id;
}

// toString() method for custom object representation
@Override
public String toString() {
return "ID: " + id + ", Name: " + name + ", Age: " + age;
}
public class Student {
private final String name;
private final int age;
private final int id;

//constructor for Student
public Student (String name, int age, int id){
this.name = name;
this.age = age;
this.id = id;
}
}


// Getter method to get the student's name
public String getName(){ //getName is a method to get the student's name
return name; //return the student's name
}

//setter method to set the student's name
public void setName (String name ){
this.name = name; //set the new name
}

public int getAge(){
return age;
}

public void setAge (int age ) {
this.age = age;
}
public int getId(){
return id;
}
public void setId(int id){
this.id = id;
}

// toString() method for custom object representation
@Override
public String toString() {
return "ID: " + id + ", Name: " + name + ", Age: " + age;
}
Larry_springboot
Your issue is final keyword How can you use final yet you have setters Totally contradictory ideas
wrain2055
wrain2055OP2d ago
public class Student {
private String name;
private int age;
private int id;

//constructor for Student
public Student (String name, int age, int id){
this.name = name;
this.age = age;
this.id = id;
}



// Getter method to get the student's name
public String getName(){ //getName is a method to get the student's name
return name; //return the student's name
}

//setter method to set the student's name
public void setName (String name ){
this.name = name; //set the new name
}

public int getAge(){
return age; //return the student's age
}

public void setAge (int age ){
this.age = age;
}
public int getId(){
return id;
}
public void setId(int id){
this.id = id;
}

// toString() method for custom object representation
@Override
public String toString() {
return "ID: " + id + ", Name: " + name + ", Age: " + age;
}
}
public class Student {
private String name;
private int age;
private int id;

//constructor for Student
public Student (String name, int age, int id){
this.name = name;
this.age = age;
this.id = id;
}



// Getter method to get the student's name
public String getName(){ //getName is a method to get the student's name
return name; //return the student's name
}

//setter method to set the student's name
public void setName (String name ){
this.name = name; //set the new name
}

public int getAge(){
return age; //return the student's age
}

public void setAge (int age ){
this.age = age;
}
public int getId(){
return id;
}
public void setId(int id){
this.id = id;
}

// toString() method for custom object representation
@Override
public String toString() {
return "ID: " + id + ", Name: " + name + ", Age: " + age;
}
}
I removed the final modifier and removed the bracket at line 13 and moved it at line 45 and all of the errors went away
JavaBot
JavaBot21h ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
wrain2055
wrain2055OP21h ago
I see thank you now I know appreciate your help guys!
JavaBot
JavaBot16h ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts. 💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server