根据下面的结果编写一个java程序
根据上面信息可以编写:
package ClassroomPractice;
import java.util.Scanner;
class Person {
// private String name;
// private int age;
// private int price;
public void price(String name, int age) {
// this.name = name;
// this.age = age;
if (age > 12) {
System.out.println(name + "的年龄为:" + age + ",门票的价格为:20元");
} else {
System.out.println(name + "的年龄为:" + age + ",门票免费");
}
}
}
public class TestClass {
public static void main(String[] args) {
String name;
int age;
String s = "n";
Person a = new Person();
Scanner reader = new Scanner(System.in);
System.out.print("请输入姓名:");
name = reader.nextLine();
// while (!(name == "n")) {
while (!name.equals(s)) {
System.out.print("请输入年龄:");
age = Integer.parseInt(reader.nextLine());
// Person a = new Person();
a.price(name, age);
System.out.println("");
System.out.print("请输入姓名:");
name = reader.nextLine();
}
System.out.println("退出程序");
reader.close();
}
}