Новая ошибка возникла из-за отсутствия основного метода. Вы можете компилировать программы без основного, но вы не можете запустить программу без основного. Вы создаете метод main с помощью "public static final void main (String [] args)". Судя по тому, что у вас есть до сих пор, я бы рискнул предположить, что в вашей основной части вы должны запросить пользователя для ввода переменных вашего экземпляра (например, forName, surName и т. Д.)
исал этот класс для хранения и распечатки данных ученика для задания. ниже мой код вместе с ошибкой, которую я получаю, когда пытаюсь скомпилировать мой код.
это мой код:
import java.util.*;
public class Student
{
private String forName;
private String surName;
private String studentID;
private String degreeScheme;
//This is the Constructor of the class Student
public forName(String name) {
this.name = forName;
}
//Assign the surname of the student
public void stuSurname (String stuSurname){
surName = stuSurname;
}
//Assign the student ID to the student
public void stuID (String stuID){
studentID = stuID;
}
//Assign the Degree of the Student
public void stuDegree (String stuDegree){
degreeScheme = stuDegree;
}
//Print the student details
public void printStudent(){
System.out.println("Forname:"+ name);
System.out.println("Surename:"+
stuSurname);
System.out.println("Student ID:"+ stuID);
System.out.println("Degree Scheme:"+
stuDegree);
}
}
Это ошибка, которую я получаю:
TheRealFawcett:lab8 javac
Student.java
Student.java:11: error: invalid method
declaration; return type required
public forName(String name) {
^
Редактировать: я не исправил ошибку в предыдущем сообщении, однако теперь у меня новая ошибка.
TheRealFawcett:lab8 therealfawcett$ java Student
Error: Main method not found in class Student, please define the main
method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
TheRealFawcett:lab8 therealfawcett$