私のメインクラスには、次のコードがあります。
Polynomial P = new Polynomial(polynomial);
別のクラスには、次のコードがあります。
public class Polynomial {
private int[] polynomial;
public Polynomial(int[] polynomial) {
this.polynomial = polynomial;
}
}
コンストラクタ Polynomial(int[]) が定義されていないのはなぜですか?
ちなみに...メインクラスの多項式は次を指しています:
int [] polynomial = new int[count];
これは完全なメイン クラスです:
import javax.swing.JOptionPane;
import java.util.Scanner;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
String input = JOptionPane.showInputDialog(null, "This is the Polynomial Cal" +
"culator Menu. Please ente" +
"r your menu selection:\n (1) Enter c" +
"oefficients of polynomial P(x). \n (2) Enter co" +
"efficients of polynomial Q(x). \n (3) Sum polynomi" +
"als P(x) and Q(x). \n (4) Multiply polynomials P(x) and Q(" +
"x). \n (5) Quit.", "Polynomial Menu",JOptionPane.PLAIN_MESSAGE);
Scanner inputScanner =new Scanner(input); //Scanner for Menu
int userChoice = inputScanner.nextInt(); //Menu Choice
if(userChoice>=1 && userChoice<=5) //User Input Catch
{
switch(userChoice)
{
case 1: String coefficientInput= JOptionPane.showInputDialog(null, "Please enter th" +
"e coefficients of the terms in the polynom" +
"ial.(Ax^n, Bx^(n-1)...Yx,Z) \n Only ent" +
"er the values of the coeffien" +
"ts i.e (A + B - C + D) ");
Scanner countScanner = new Scanner(coefficientInput); //Scanner for count
int coefficient= countScanner.nextInt();
int count=1;
while(countScanner.hasNextInt())
{
count++;
countScanner.nextInt();
}
int [] polynomial = new int[count]; //Size of Array=Count
Scanner coefficientScanner = new Scanner(coefficientInput);
int term = 0;
System.out.println(count);
int i=0;
while(coefficientScanner.hasNextInt()) //Initialisation of array
{
term=coefficientScanner.nextInt();
polynomial[i]=term;
i++;
}
Polynomial P = new Polynomial(polynomial);
}
}
else
{
JOptionPane.showMessageDialog(null, "No option selected. Please try again.","Input Error",JOptionPane.ERROR_MESSAGE);
}
}
}
多項式でエラーが発生 P =new Polynomial(多項式)