编辑代码

import java.util.Scanner;
 
public class Main{
    public static void main(String args[]) {
        @SuppressWarnings("resource")
		Scanner in = new Scanner(System.in);
        Ticket a = new WalkupTicket(in.nextInt());
        System.out.println(a.toString());
        Ticket b = new AdvanceTicket(in.nextInt(), in.nextInt());
        System.out.println(b.toString());
        Ticket c = new StudentAdvanceTicket(in.nextInt(), in.nextInt(), in.nextInt());
        System.out.println(c.toString());
    }
}
	public abstract int getPrice();
 
	public String toString()
	{
		return "Number:"+this.number+",Price:"+this.getPrice();
	}
}
class WalkupTicket extends Ticket {
	public WalkupTicket(int number)
	{
		super(number);
	}
	public int getPrice()
	{
		return 50;
	}
}
class AdvanceTicket extends Ticket {
	private int leadTime;
	public AdvanceTicket(int number,int leadTime)
	{
		super(number);
		this.leadTime=leadTime;
	}
	public int getLeadTime()
	{
		return this.leadTime;
	}
	public int getPrice()
	{
		if(this.leadTime>10)
			return 30;
		else
			return 40;
	}
}
class StudentAdvanceTicket extends AdvanceTicket {
	private int height;
	public StudentAdvanceTicket(int number,int leadTime,int height)
	{
		super(number,leadTime);
		this.height=height;
	}
	public int getPrice()
	{
		if(this.height>120&&this.getLeadTime()>10)
			return 20;
		else if(this.height>120&&this.getLeadTime()<=10)
			return 30;
		else if(this.height<120&&this.getLeadTime()>10)
			return 10;
		else if(this.height<120&&this.getLeadTime()<=10)
			return 15;
		return 0;
	}
}