1 package details; 2 3 import java.util.Scanner; 4 5 public class Candidtates { 6 private String name,qualification ,status; 7 private int age; 8 9 public void getCandiatesDetails() { 10 Scanner sc=new Scanner(System.in); 11 System.out.println("Enter your name:"); 12 name=sc.next(); 13 System.out.println("Enter your qualification:"); 14 qualification =sc.next(); 15 System.out.println("Enter your age"); 16 age=sc.nextInt(); 17 18 AgeValidation obj=new AgeValidation(); 19 obj.validateAge(); 20 21 } 22 //正则内部类 23 private class AgeValidation { 24 public void validateAge() { 25 if(age>=21 && age<=25) { 26 status="selected"; 27 } 28 else { 29 status="rejected"; 30 31 } 32 } 33 } 34 public void printCandiatesDetails() { 35 System.out.println("Name:"+name); 36 System.out.println("qualification"+qualification); 37 System.out.println("age"+age); 38 System.out.println("Selection status"+status); 39 } 40 41 42 public static void main(String[] args) { 43 Candidtates candidate =new Candidtates(); 44 candidate.getCandiatesDetails(); 45 candidate.printCandiatesDetails(); 46 47 48 } 49 }