//定义类
package com.jredu.ch.Package001;
public class LvYou {
public String name;
public int age;
public void menpiao(){
if (age>18) {
System.out.println(name+"的年龄为"+age+",门票价格为20");
}else {
System.out.println(name+"的年龄为"+age+",门票免费");
}
}
public LvYou(String name,int age){
this.name = name;
this.age = age;
}
}
//函数体
package com.jredu.ch05;
import java.util.Scanner;
import com.jredu.ch.Package001.LvYou;
public class LiuYiFan20160802_LvYou {
public static void main(String[] args) {
String name;
int age;
Scanner input = new Scanner(System.in);
do {
System.out.println("请输入你的姓名");
name = input.next();
if (name.equals("n")) {
System.out.println("退出程序");
break;
}else {
System.out.println("请输入你的年龄");
age = input.nextInt();
LvYou peaple = new LvYou(name,age);
peaple.menpiao();
}
} while (name!="n");
input.close();
}
}
//输入年龄后判断门票的价格