先週コンピューター サイエンスを始めたばかりで、Coins というワークシートを受け取りました。このワークシートでは、1 組のコインに 4 セント硬貨、10 セント硬貨、5 セント硬貨、1 セント硬貨がいくつ含まれているかを調べなければなりませんでした。私は多くの問題を抱えており、そのエラーが発生しています。これが私のコードです
package Coins;
public class Coins
{
private int change;
// two contructors
Change() //default constructor
{
change = 94;
}
Change( int c )
{
change = c;
}
// accessor method - change
public int getChange()
{
return Change;
}
// mutator method - change
public void setChange( int anotherChange)
{
change = anotherChange;
}
public void askUserForChange()
{
Scanner keyIn;
keyIn = new Scanner(System.in);
System.out.print("Please enter the amount of change: ");
String input = keyIn.nextLine();
int nChange = Integer.parseInt (input);
setChange(nChange);
// change = nChange
printChangex();
}
// action method - take accessor figure out coins -> output
// calculating the coins needed for the change
public void printChangeRange(int start, int end)
{
for(int c = start; c <= end; c++
{
setChange(c);
printChangex();
}
}
public void printChangex()
{
int c = change;
int quarter = c / 25;
System.out.println("quarter = " + quarter);
int a = c%25;
int dime = a / 10;
System.out.println("dime = " + dime);
int b = a%10;
int nickel = b / 5;
System.out.println("nickel = " + nickel);
int c = b%5;
int penny = c / 1;
System.out.println("penny = " + penny);
}
// instance variables - replace the example below with your own
private int x;
public Coins()
{
// initialise instance variables
x = 0;
}
public int sampleMethod(int y)
{
// put your code here
return x + y;
}
}