import java.util.Scanner;public class subway { private int price; private int staStation; private int endStation; private int money; private int number; public void subway(){} public void price1(){ int number1=endStation-staStation; if(number1<=5){ price=3; } else if(number1<=8){ price=4; } else{ price=5; } } public void shuru(){ Scanner scanner =new Scanner(System.in); System.out.println("请输入起始站"); staStation=scanner.nextInt(); System.out.println("请输入终点站"); endStation=scanner.nextInt(); System.out.println("请输入票数"); number=scanner.nextInt(); } public void shuru1(){ Scanner scanner =new Scanner(System.in); int tatPrice1=number*price; System.out.println("您需要支付"+tatPrice1+"元"); System.out.println("请支付"); money=scanner.nextInt(); } public void pay(){ int tatPrice=number*price; if(money<tatPrice){ System.out.println("您支付的金额不足"); } else if(money==tatPrice){ System.out.println("正在帮您打印车票"); } else{ int money1=money-tatPrice; System.out.println("正在帮您打印车票并找您"+money1+"元"); } } public static void main(String[] args) { subway s=new subway(); s.shuru(); s.shuru1(); s.price1(); s.pay(); }}
1 回答
已采纳
MinRam
TA贡献87条经验 获得超24个赞
int tatPrice1=number*price; // 这时的price 并未赋值(构造函数并未给price赋初值),所以默认为0 System.out.println("您需要支付"+tatPrice1+"元"); // tatPricel = number * 0 = 0
添加回答
举报
0/150
提交
取消