我的问题是,想输入两个由空格分隔的数字,得到这两个数,然后计算这两个数,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的初学者。