java 计算空格_获取 - 在java中,获取由空格分隔的两个数据并计算_java_酷徒编程知识库...

我的问题是,想输入两个由空格分隔的数字,得到这两个数,然后计算这两个数,10 *20 =200.

我的GETTER和SETTER类import java.util.*;

public class LabExer2

{

private String itemName;

private double itemPrice;

private int itemQuantity;

private double amountDue;

public void setItemName(String newItemName)

{

itemName = newItemName;

}

public String getItemName()

{

return itemName;

}

public void setTotalCost(int quantity, double price)

{

itemQuantity = quantity;

itemPrice = price;

amountDue = itemQuantity * itemPrice;

}

public double getTotalCost()

{

return amountDue;

}

public void readInput()

{

Scanner s = new Scanner(System.in);

System.out.println("Enter the name of the item you are purchasing.");

itemName = s.nextLine();

System.out.println("Enter the quantity and price separated by a space.");

//itemQuantity = s.nextInt();

//itemPrice = s.nextDouble();

}

public void writeInput()

{

System.out.println("You are purchasing" + itemQuantity +"" + itemName +"(s) at" + itemPrice +" each.");

System.out.println("Amount due is" + getTotalCost());

}

}

public class MainLabExer2

{

public static void main(String[]args)

{

LabExer2 le = new LabExer2();

//still not finished because I can't figure out the process in the other class.

}

}

我想要的输出:

输入要购买的物料的名称,

pencil

输入用空格分隔的数量和价格,

3 15.50

购买3支铅笔,每支价格为15.50.

金额为46.50

不知道使用什么东西,我是java的初学者。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值