Java Eclipse Class Comparing Marks And Displaying Who Failed -
in code want compare 4 test students , display failed. need in failed class. topper class fine.
import java.io.ioexception; import java.util.arraylist; import java.util.scanner; public class studentclass { static arraylist<student> list = new arraylist<student>(); static void student() { student topper = list.get(0); for(int i=1;i<list.size();++i){ if(topper.marks<list.get(i).marks){ topper = list.get(i); } } system.out.println("tooper : "+topper.name); } static void failed1(){ if(list.get(i)<=35 ){ } } // system.out.println("this student failed" +); public static void main(string[] args) { // todo auto-generated method stub student s = new student(); s.name = "test 1"; s.roolno = 1; s.marks = 30.5f; list.add(s); student x = new student(); x.name = "test 2"; x.roolno = 2; x.marks = 32.5f; list.add(x); student y = new student(); y.name = "test 3"; y.roolno = 3; y.marks = 80.5f; list.add(y); student z = new student(); z.name = "test 4"; z.roolno = 4; z.marks = 90.5f; list.add(z); printmainmenu(); } private static void printmainmenu() { system.out.println("** main menu **"); system.out.println("1.topper"); system.out.println("2. student failed"); system.out.println("3.exit"); system.out.println("\nenter choice"); scanner in = new scanner(system.in); int ch = in.nextint(); switch (ch) { case 1: student(); break; case 2: failed1(); break; case 3: system.exit(0); default: system.out.println("enter vaild press enter continue"); try { system.in.read(); clear(); printmainmenu(); } catch (ioexception e) { e.setstacktrace(null); } break; } } private static void clear() { // todo auto-generated method stub } private static void failed() { // todo auto-generated method stub } } // private static void entering(string string) { // todo auto-generated method stub
there couple ways can checks. simplest of course manual check
arraylist<student> failedstudents = new arraylist<student>(); (student student : studentlist) { if (student.getmark() < passmark ) { failedstudents.add(student); } }
you can implement priorityqueue
comparator
class orders student
objects marks.
Comments
Post a Comment