我已经为此工作了几个小时了,我无法得到它,所以它需要扫描仪输入(int addoneeurocoins=integer.parseint(keyboard.nextline());以此类推)用于pursemk1和pursemk2。任何人都知道如何解决它,我绝望了。
import java.util.Scanner;
public class PurseDemoMk2
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int addOneEuroCoins = Integer.parseInt(keyboard.nextLine());
int addFiftyCentCoins = Integer.parseInt(keyboard.nextLine());
int addTenCentCoins = Integer.parseInt(keyboard.nextLine());
int addOneCentCoins = Integer.parseInt(keyboard.nextLine());
//Purse Object1
Purse purseMk1 = new Purse();
purseMk1.addOneEuroCoins();
System.out.println("Expected: 2.00 euro, Found: " + String.format("%.2f", purseMk1.getTotal()));
purseMk1.addFiftyCentCoins();
System.out.println("Expected: 3.00 euro, Found: " + String.format("%.2f", purseMk1.getTotal()));
purseMk1.addTenCentCoins();
System.out.println("Expected: 3.20 euro, Found: " + String.format("%.2f", purseMk1.getTotal()));
purseMk1.addOneCentCoins();
System.out.println("Expected: 3.22 euro, Found: " + String.format("%.2f", purseMk1.getTotal()));
System.out.println(purseMk1);
//Purse Object2
Purse purseMk2 = new Purse();
purseMk2.addOneEuroCoins();
System.out.println("Expected: 2.00 euro, Found: " + String.format("%.2f", purseMk2.getTotal()));
purseMk2.addFiftyCentCoins();
System.out.println("Expected: 3.00 euro, Found: " + String.format("%.2f", purseMk2.getTotal()));
purseMk2.addTenCentCoins();
System.out.println("Expected: 3.20 euro, Found: " + String.format("%.2f", purseMk2.getTotal()));
purseMk2.addOneCentCoins();
System.out.println("Expected: 3.22 euro, Found: " + String.format("%.2f", purseMk2.getTotal()));
System.out.println(purseMk2);
}
}
暂无答案!
目前还没有任何答案,快来回答吧!