下面是我的节目,我需要将年级定在“A”级,其分数在60至90之间,应为“B”,其余学生的年级为“C”。 如何在java8溪流中利用私人经营者实施这一方案。 我试图过滤有90个以上标志的学生,并试图使用固定校对方法确定年级。 但我正发现错误。 请帮助我解决这一问题。 ......
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
class Student { String name; String subject; Double marks; String grade;
Student(String name, String subject, Double marks){
this.name=name;
this.subject=subject;
this.marks=marks;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Double getMarks() {
return marks;
}
public void setMarks(Double marks) {
this.marks = marks;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getGrade() {
return grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
@Override
public String toString() {
return "Student [name=" + name + ", subject=" + subject + ", marks=" + marks + ", grade=" + grade + "]";
}
}
public class MyProject{ public static void main(String[] args) {
List <Student> studentList = new ArrayList < > ();
studentList.add(new Student("Ram", "maths",85.5));
studentList.add(new Student("Pranav", "maths",90.5));
studentList.add(new Student("Vibin", "maths",92.0));
studentList.add(new Student("Nikhil", "maths",60.0));
studentList.add(new Student("Sushil", "science",60.0));
List<Student> mystudents= studentList.stream().filter(i->i.getMarks()>=90) .map(i>i.setGrade("A")) .toList(); System.out.println(mystudents);
}};