java - 为什么我的输出没有显示我的输入?
问题描述
我不确定需要做什么,以便“采购摘要”的输出显示“汽油类型”。任何帮助表示赞赏。
更新:完整代码。“字符串类型 = input.nextLine();” 在运行时,汽油类型似乎没有在购买摘要中注册。我不确定其中有什么问题。
class PetrolPurchase
{
private String station;
private double quant;
private String type;
private double price;
private int discount;
public String getstation () {return station;}
public double getquant () {return quant;}
public String gettype () {return type;}
public double getprice () {return price;}
public int getdiscount () {return discount;}
public void setstation (String otherstation) {station = otherstation;}
public void setquant (double otherquant) {quant = otherquant;}
public void settype (String othertype) {type = othertype;}
public void setprice (double otherprice) {price = otherprice;}
public void setdiscount (int otherdiscount) {discount = otherdiscount;}
}
class PurchaseSummary
{ public static void main (String [ ] args)
{
Scanner input = new Scanner (System.in);
PetrolPurchase pp = new PetrolPurchase ();
System.out.printf ("Enter Station:");
String station = input.nextLine();
pp.setstation (station);
System.out.printf("Enter Quantity (Liter):");
double quant = input.nextDouble();
pp.setquant (quant);
System.out.printf ("Enter Petrol Type:");
String type = input.nextLine();
pp.settype (type);
input.nextLine();
System.out.printf ("Enter the Petrol Price:");
double price = input.nextDouble();
pp.setprice (price);
System.out.printf("Enter the discount (no decimal):");
int discount = input.nextInt();
pp.setdiscount (discount);
double truecost = quant * price;
double dcost = discount*0.01*truecost;
double pay = truecost - dcost;
System.out.printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%n");
System.out.printf("Purchase Summary:%n");
System.out.printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%n");
System.out.printf ("Station: %s%n", station);
System.out.printf ("Total Petrol Liter: %s%n", pp.getquant ());
System.out.printf ("Petrol Type: %s%n", pp.gettype());
System.out.printf ("Price Per Liter: = %.2f%n", pp.getprice ());
System.out.printf ("Actual Cost = %.2f%n", truecost);
System.out.printf ("Discounted Amount %s", discount);
System.out.printf ("%% is: %-8.5s", dcost);
System.out.printf ("%nAmount for Payment = %.2f%n", pay);
解决方案
尝试把input.nextLine();
之前type=input.nextLine();
推荐阅读
- html - 即使通过 CSS/CSS3 滚动,是否可以将具有绝对位置的元素“固定”到其父容器的底部?
- c# - 影子主键
- r - 无法在R中将字符转换为数字
- powershell - 启动进程 powershell 找不到指定的
- python - 无法在 anaconda 下加载 pyspark
- http - 发送 Guzzle 请求以逐项列出 api
- python - Python Pandas - 在多列左侧加入,在最终数据框中添加空白
- python - Python matplotlib - 添加趋势线,制作子图并保存为.pdf
- javascript - 我有 3 个按钮,每个按钮都有一个 JavaScript 函数,只有一个可以工作
- python - 在 Python 中将 dict 转换为 json 时转义双引号