import java.util.Scanner;public class station { private int staStation; private int endStation; private int price; private int money; private int number; public void station(){} public void shuru_station(){ 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 price(){ int changdu=endStation-staStation; if(changdu<=5){ price=3; } else if(changdu<=8){ price=4; } else{ price=5; } } public void shuru_price(){ Scanner scanner = new Scanner(System.in); System.out.println("您需要支付"+price*number+"元"); System.out.println("请支付"); money=scanner.nextInt(); } public void compare(){ int money1=price*number; int i=0; for(;i<=3;i++){ int a=3-i; int b=money-money1; Scanner scanner = new Scanner(System.in); System.out.println("您需要支付"+price*number+"元"); System.out.println("请支付"); money=scanner.nextInt(); if(money<money1){ System.out.println("您支付的金额不足,请重新支付"); System.out.println("您还有"+a+"次机会支付"); } else if(money==money1){ System.out.println("正在为您打印车票"); break; } else { System.out.println("正在为您打印车票,并找您"+b+"元"); break; } } } public static void main(String[] args) { station s=new station(); s.shuru_station(); s.price(); s.compare(); }}
1 回答
已采纳
尧叔
TA贡献77条经验 获得超201个赞
代码写的很难懂。java里面命名统一是驼峰式,不提倡下划线和中英结合,并且循环那块知识你很薄弱。
为什么为负,你算b的时候money还没输入。写的太复杂,自己看了一脸懵逼。
不过作为初学者需要鼓励。加油。
添加回答
举报
0/150
提交
取消