도움이 필요한 코드가 있습니다. 나는 AP CS 학생이며 입문자이기 때문에 저를 판단하지 마십시오.생성자 만들기
// name:
//
// program: CoinsTester
//
// purpose:
public class CoinsTester {
public static void main(String[] args) {
//create a new Coins object named money and pass it the amount of cents as a parameter
//***** STUDENTS NEED TO COMPLETE ******
Coins();
Coins money = new Coins();
// call the correct method in the Coins class to find your answer
//***** STUDENTS NEED TO COMPLETE ******
money.calculate();
}
}
// name:
//
// program: CoinsTester
//
// purpose: This class accepts a certain number of monetary change.
// The output is a list of the number of quarters, dimes, nickels,
// and pennies that will make that amount of change with the least
// number of coins possible. This is a skeleton that will be finished
// by the students
public class Coins {
//private variable to store the only attribute of a "Coins" object - how many cents the
// user wants to find change for.
private int myChange;
//constructor that accepts an initial value for the private data member
public Coins(int change) {
myChange = change;
}
// the method calculate will
// 1. use modular and regular division to determine the quantity of each type of coin
// 2. prints the quantity of the coins needed to make the entered amount
public void calculate(){
int quarters=25, dimes=10, nickels=5, pennies=1;
int temp1, temp2, temp3, temp4;
int remainquar1, remaindime2, remainnick3, remainpenn4;
//variable declarations to hold the values needed for different coin types
// make sure you use descriptive identifiers!
//***** STUDENTS NEED TO COMPLETE ******
// calculations for the various coin types
//***** STUDENTS NEED TO COMPLETE ******
// output statements, formatted as shown on specs
//***** STUDENTS NEED TO COMPLETE ******
}
}
여기 내 잘못 지정된 형식의 코드에 대해 사과드립니다. 그래서 나는 그것을 실행할 때 동전 돈 = 새로운 동전()이 코드의 생성자를 찾을 수 없다고 말합니다. 나는 적절한 물건을 만드는 데 도움이 필요하다. 여기서 "CoinsTester"개체를 만들어야한다는 것은 객체에 연결된 생성자가 없다는 것을 말해줍니다. 나는 지금 당장 해결책을 찾을 수 없다. 누군가가 CoinsTester 클래스의 생성자를 만드는 방법에 대한 팁을 주시겠습니까?
어떻게 다시 선언하겠습니까? CoinsTester 또는 동전에서만? "Public Coins() { myChange = 0; }" – allenlistar
공용 클래스 동전에 공용 Coins() 생성자를 선언합니다. 그런 다음 CoinsTester의 Main 메서드에서 동전 돈 = 새로운 Coins()를 사용하면됩니다. 선. – miguelarcilla