如果客户支付的金额低于票价

huangapple go评论68阅读模式
英文:

If the customer pays less than the ticket price

问题

import java.util.Scanner;

public class Flow {

    static Scanner input = new Scanner(System.in);
    static int age;
    static double ticketpricetax = 0.15 * 100 + 10;
    public static double remainigamount = ticketpricetax;
    public static double howmuchpay = 10;

    public static void main(String[] args) {

        System.out.println("年龄");
        int age = input.nextInt();
        if (age > 12 || age <= 50) {
            System.out.println("票价为 ");
            System.out.println(ticketpricetax);
            System.out.println("请支付您的票款");
        }
        input.nextInt();
        if (ticketpricetax > howmuchpay) {
            System.out.println("支付的金额少于票价");
        } else if (ticketpricetax > howmuchpay) {
            System.out.println("支付的金额大于票价");
        } else {
            System.out.println("欢迎光临");
        }
    }
}
英文:

Help me here i tried make success , program but theres a mistakes here can?
any one solve it and send it ,
If the customer pays less than the ticket price, I want to print the money less than the ticket price and print the rest to pay, or if the customer pays more than the ticket price, the rest of the money is printed to the customer, and finally if he pays the ticket amount, you print welcome

    import java.util.Scanner;

 public class Flow {

	static Scanner input = new Scanner(System.in);
	static int age;
	static double ticketpricetax = 0.15 * 100 + 10;
	public static double remainigamount = ticketpricetax;
	public static double howmuchpay = 10;

	public static void main(String[] args) {

		System.out.println(&quot;Age&quot;);
		int age = input.nextInt();
		if (age &gt; 12 || age &lt;= 50) {
			System.out.println(&quot;ticket price is &quot;);
			System.out.println(ticketpricetax);
			System.out.println(&quot;Please pay your ticket&quot;);
		}
		input.nextInt();
		if (ticketpricetax &gt; howmuchpay) {
			System.out.println(&quot;the money less than ticket price&quot;);
		} else if (ticketpricetax &gt; howmuchpay) {
			System.out.println(&quot;the money is greater than ticket price&quot;);
		} else {
			System.out.println(&quot;welcome&quot;);
		}
	}
}

答案1

得分: 1

你的价格输入未存储在任何变量中,应为双精度浮点型而不是整型,然后你正在比较ticketpricetax和howmuchpay与它们的初始化值,howmuchpay未更新为输入值。此外,你正在进行错误的检查并且缺少一些语句。以下是更正后的代码:

import java.util.Scanner;

public class Flow {
    static Scanner input = new Scanner(System.in);
    static int age;
    static double ticketpricetax = 0.15 * 100 + 10;
    public static double howmuchpay = 10;

    public static void main(String[] args) {
        System.out.println("年龄");
        int age = input.nextInt();
        if (age > 12 || age <= 50) {
            System.out.println("票价是 ");
            System.out.println(ticketpricetax);
            System.out.println("请支付您的票款");
        }
        howmuchpay = input.nextDouble();
        if (ticketpricetax > howmuchpay) {
            System.out.println("金额少于票价");
            System.out.println("剩余需要支付的金额 = " + (ticketpricetax - howmuchpay)); 
        } else if (ticketpricetax < howmuchpay) {
            System.out.println("金额大于票价");
            System.out.println("剩余的金额 = " + (howmuchpay - ticketpricetax));
        } else {
            System.out.println("欢迎");
        }
    }
}

请注意,我已根据你的要求,仅翻译代码部分,其余内容保持不变。

英文:

Your price input is not stored in any variable and it should be double not int, and then you are comparing ticketpricetax and howmuchpay with their initialized values,howmuchpay is not updated with input. In addition you're making an incorrect check and missing some statements.
Here is the correction :

import java.util.Scanner;
public class Flow {

static Scanner input = new Scanner(System.in);
static int age;
static double ticketpricetax = 0.15 * 100 + 10;
public static double howmuchpay = 10;

public static void main(String[] args) {

    System.out.println(&quot;Age&quot;);
    int age = input.nextInt();
    if (age &gt; 12 || age &lt;= 50) {
        System.out.println(&quot;ticket price is &quot;);
        System.out.println(ticketpricetax);
        System.out.println(&quot;Please pay your ticket&quot;);
    }
    howmuchpay = input.nextDouble();
    if (ticketpricetax &gt; howmuchpay) {
        System.out.println(&quot;the money less than ticket price&quot;);
        System.out.println(&quot;rest of the money to pay = &quot;+(ticketpricetax-howmuchpay)); 
    } else if (ticketpricetax &lt; howmuchpay) {
        System.out.println(&quot;the money is greater than ticket price&quot;);
        System.out.println(&quot;rest of the money = &quot;+(howmuchpay-ticketpricetax));
    } else {
        System.out.println(&quot;welcome&quot;);
    }
}
}

huangapple
  • 本文由 发表于 2020年9月25日 17:40:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/64061650.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定