package com.qingdaoligong.jierui; public class MiaoShu { // 定义类 String name; int age; double height; double weight; String sex; String ideas; public void zhaohu(){ //定义方法 System.out.println("大家好!"); } public void base(){ //定义方法 System.out.print("我叫"+name); System.out.println("今年"+age+"岁"); System.out.println("我是一个身高"+height+"体重"+weight+"的"+sex); } public MiaoShu(String name,int age,double height,double weight,String sex){//构造参数函数 this.name=name; this.age=age; this.height=height; this.weight=weight; this.sex=sex; } public void idea(){ } public void idea(String ideas) { System.out.println(name+"的工作理念:"+ideas); } }
package com.qingdaoligong.jierui; public class JingQu { // 定义类 String name; int age; public void ticket(String name,int age){ //定义方法 if(age>0&&age<=5){ System.out.println(name+"的年龄为"+age+":门票免费"); }else{ System.out.println(name+"的年龄为"+age+":门票价格为:20元"); } } public JingQu(){ //构造无参数函数 } public JingQu(String name,int age){ //构造有参数函数 this.name=name; this.age=age; } }
package com.qingdaoligong.jierui; import java.util.Scanner; public class Youke { public static void main(String[] args) { int maxtic = 10000; Scanner input = new Scanner(System.in);
JinQu tourise=new JinQu(); for (int i = maxtic; i > 0; i--) { System.out.println("输入名字"); String name = input.next(); if (name.equals("n")) { System.out.println("退出程序"); break; } System.out.println("输入年龄"); int age = input.nextInt(); tourise.ticket(name,age); System.out.println("还剩余" + (i - 1) + "张门票"); } input.close(); } }