Question: Why I can't run this coding? I think I got problem at main method, but don't know how to fix public class Student { private String name; // the student’s full name private String id; // the student ID private int credits; // the amount of credits for study taken so far // Create a new student with a given name and ID number. public Student(String fullName, String studentID) { name = fullName; id = studentID; credits = 0; // set credits to be 0 } // Return the full name of this student. public String getName() { return name;// returns the name } // Set a new name for this student. public void setName(String n) { name = n;// set n as name of Studentt } // Return the student ID of this student. public String getId() { return id;// return the id of the student } //Add some credit points to the student’s accumulated credits. public void addCreditPoints(int points) { credits = credits + points;// add to existing credits } /* * Check the number of credit points this student has accumulated. * * If it is less than 132, then print “Not yet graduated”, otherwise print * “Graduated”. * */ public void checkCredits() { if (credits < 132)// credit points less than 132 System.out.println("Not yet graduated"); else// otherwise System.out.println("Graduated"); } //Print the student’s name and ID number to the output terminal. public void print() { System.out.println("Name: "+name+", ID: "+id); } public static void main(String [] args) { Student s=new Student("Anis","1234"); s.addCreditPoints(100); s.printGraduationStatus(); s.addCreditPoints(34); s.printGraduationStatus(); s.print(); } }
Question: Why I can't run this coding? I think I got problem at main method, but don't know how to fix
public class Student
{
private String name; // the student’s full name
private String id; // the student ID
private int credits; // the amount of credits for study taken so far
// Create a new student with a given name and ID number.
public Student(String fullName, String studentID) {
name = fullName;
id = studentID;
credits = 0; // set credits to be 0
}
// Return the full name of this student.
public String getName() {
return name;// returns the name
}
// Set a new name for this student.
public void setName(String n) {
name = n;// set n as name of Studentt
}
// Return the student ID of this student.
public String getId() {
return id;// return the id of the student
}
//Add some credit points to the student’s accumulated credits.
public void addCreditPoints(int points) {
credits = credits + points;// add to existing credits
}
/*
* Check the number of credit points this student has accumulated.
*
* If it is less than 132, then print “Not yet graduated”, otherwise print
* “Graduated”.
*
*/
public void checkCredits() {
if (credits < 132)// credit points less than 132
System.out.println("Not yet graduated");
else// otherwise
System.out.println("Graduated");
}
//Print the student’s name and ID number to the output terminal.
public void print() {
System.out.println("Name: "+name+", ID: "+id);
}
public static void main(String [] args) {
Student s=new Student("Anis","1234");
s.addCreditPoints(100);
s.printGraduationStatus();
s.addCreditPoints(34);
s.printGraduationStatus();
s.print();
}
}
Step by step
Solved in 2 steps