我正在写日记程序。
在日记类中,我制作了一个名为“ addStudent”的方法,但是我不知道为什么它在我的主体中不可见? 编辑我添加了代码,对不起一个代码块,而不是3个代码,但是lombok导入导致格式化问题
EDIT2我删除了剩余的问题
public class Main {
public static void main(String[] args) {
}
}
import lombok.AllArgsConstructor;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
@AllArgsConstructor
@Data
public class Diary {
List<Student> listOfStudents = new ArrayList<>();
public static void addStudent(Student... students){
Student student = new Student(Student.askAboutGrades(), Student.askAboutIndexNumber(), Student.askAboutName(), Student.askAboutSurname());
}
}
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
@AllArgsConstructor
@Data
public class Student {
List<Double> grades = new ArrayList<>();
String indexNumber;
String name;
String surname;
public static String askAboutName() {
System.out.println("Type the name");
Scanner scanner = new Scanner(System.in);
String name = scanner.nextLine();
while
(!(name.matches("[a-zA-Z]+"))) {
System.out.println("incorrect name, try again");
name = scanner.nextLine();
}
System.out.println("Name seems good");
return name;
}
public static String askAboutSurname() {
System.out.println("Type the surname");
Scanner scanner = new Scanner(System.in);
String surname = scanner.nextLine();
while (!(surname.matches("[a-zA-Z]+"))) {
System.out.println("incorrect surname, try again");
surname = scanner.nextLine();
}
System.out.println("surname seems good");
return surname;
}
public static String askAboutIndexNumber() {
System.out.println("Type the index number (6 digits!)");
Scanner scanner = new Scanner(System.in);
String indexNumber = scanner.nextLine();
while (!indexNumber.matches("\\d{6}")) {
System.out.println("incorrect index number, try again");
indexNumber = scanner.nextLine();
}
System.out.println("index seems good");
return indexNumber;
}
public static List<Double> askAboutGrades() {
System.out.println("Type the grades,separated by comma (\",\")");//todo check if works and set limiter from 2 to 5.5
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
String[] arrayOfGrades = input.split(",");
List<String> listOfGrades = new ArrayList<>(Arrays.asList(arrayOfGrades));
List<Double> listOfGradesDouble = new ArrayList<>();
String temp;
for (int i = 0; i < listOfGrades.size(); i++) {
temp = listOfGrades.get(i);
listOfGradesDouble.add(Double.parseDouble(temp));
}
return listOfGradesDouble;
}
}
GitHub: https : //github.com/Karol011/SDA/tree/master/zadania/src/main/java/Kolekcje/ListyKolekcje/Diary
以下工作对我来说很好,只需将JLabel添加到JPanel并将JPanel添加到JPopupMenu
JPanel panelLabel = new JPanel();
JLabel lblSomeText = new JLabel("Some text"); lblSomeText.setFont(menuItem.getFont()); lblSomeText.setForeground(menuItem.getForeground()); panelLabel.add(lblSomeText); popupMenu.add(panelLabel);
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。