//define name, age, receive from keyboard, cycle judgment name and age and output the corresponding statement
//defining the Person class Public classPerson {String name; //name intAge//Age /*** Used to loop receive user input and then determine age*/ //Displaying information methods Public voidShow () {Scanner input=NewScanner (system.in);//scanner input from keyboardSystem.out.println ("Please enter your name:"); Name=Input.next (); //1. Cycle while(!name.equals ("n") {System.out.println ("Please enter your Age:"); Age=Input.nextint (); //2. Making Judgments if(age>=18&&age<=60) {System.out.println ("Admission 20 Yuan"); }Else{System.out.println ("Free Admission"); } System.out.println ("Please enter your name:"); Name=Input.next (); } System.out.println ("The program is over!" "); } //Object Public Static voidMain (string[] args) {//create an object of the person class /*** Instantiation process of class*/ Person Person=NewPerson (); //Calling Methodsperson.show (); }
}
Class and object Instance 2