/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package StudentTest; import Premium.PremiumStudent; import java.util.Scanner; /** * * @author Administrator */ public class TestStudent { /** * @param args the command line arguments */ public static void main(String[] args) { int choice; Scanner scan = new Scanner(System.in); TestStudent a = new TestStudent(); do { System.out.println("-----MENU-----"); System.out.println("1.addStudent"); System.out.println("2.passStudents"); System.out.println("3.EXIT"); System.out.println("Your choice: "); choice = scan.nextInt(); switch (choice) { case 1: a.addStudent(); break; case 2: a.passStudents(); break; case 3: System.out.println("TKS !!!"); break; default: System.out.println("Please re-enter MENU !!!"); } } while (choice != 3); } PremiumStudent[] pre; int maxStudent; int nextStudent; Scanner scan = new Scanner(System.in); public TestStudent() { maxStudent = 3; nextStudent = 0; pre = new PremiumStudent[maxStudent]; scan.useDelimiter("\n"); } public void addStudent() { if (nextStudent < maxStudent) { pre[nextStudent] = new PremiumStudent(); pre[nextStudent].input(); nextStudent++; } else { System.out.println("FULL !!!"); } } public void passStudents() { if (nextStudent > 0) { boolean found = false; for (int i = 0; i < nextStudent; i++) { if (pre.endMark > 15 && pre.mathMark > 12) { System.out.println("----passStudents----"); System.out.println("Rollno: " + pre.rollno); System.out.println("Name: " + pre.name); System.out.println("endMark: " + pre.endMark); System.out.println("mathMark: " + pre.mathMark); found = true; } } if (!found) { System.out.println("No student to find !!!!"); } } else { System.out.println("please enter Student !!!!"); } } } ------------------------------------------------------------------------------------------------- /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package Standard; /** * * @author Administrator */ public abstract class Student { public String rollno; public String name; public abstract void input(); } --------------------------------------------------------------------------------------------------- /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package Standard; import java.util.Scanner; /** * * @author Administrator */ public class StandardStudent extends Student { public int endMark; Scanner scan = new Scanner(System.in); @override public void input() { System.out.println("Enter Rollno: "); rollno = scan.next(); System.out.println("Enter Name: "); name = scan.next(); System.out.println("Enter endMark: "); endMark = scan.nextInt(); //try-catch try{ if(endMark<0 || endMark>30) throw new Exception("0 < endMark < 30"); }catch (Exception e){ e.printStackTrace(); } } } --------------------------------------------------------------------------------------------------- /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package Premium; import Standard.StandardStudent; import java.util.Scanner; /** * * @author Administrator */ public class PremiumStudent extends StandardStudent { public int mathMark; Scanner scan = new Scanner(System.in); @override public void input() { super.input(); System.out.println("Nhap mathMark: "); mathMark = scan.nextInt(); try{ if(mathMark <0 || mathMark > 30) throw new Exception("0 < mathMark <30"); }catch (Exception e){ e.printStackTrace(); } } }
First off, this is JAVA code, not javascript. You're in the wrong forum. Second, did you have a question? Or did you just want to spam the forum with code without CODE-tags surrounding them? Learn to forum, please.
As I used to have as a signature here, Java is to JavaScript as Ham is to Hamburger. ... and yeah, without an actual question what was the point of this thread?