gpt4 book ai didi

java - 数组错误(处理多个数组),找不到解决方案

转载 作者:行者123 更新时间:2023-12-02 07:27:43 26 4
gpt4 key购买 nike

我已经尝试用我的 java 代码修复这个解决方案几个小时了。我在 eclipse 上遇到错误:

“Ass1 类型未定义方法 displayQFunction(int[], int[], int)”

我尝试过更改值,尝试更改所有内容,但此错误阻碍了我取得进展。

这是我的代码:

import java.util.* ;
public class Ass1 {


static int VIX = 0 ; // Traversing Voltage Component in Component Value Array
static int CIX = 1 ; // Traversing Capacitor
static int LIX = 2; // Traversing Inductor
static int RIX = 3; // Traversing Resistor

public static void main (String args[]) {
System.out.println("ITI 1120 Fall 2012 , Assignment 3 , Question 3") ;
System.out.println("Name : Khalid Awil , Student # 6763004") ;

double[] compArr = getCircuitComp() ;

System.out.println("-----------------------------------------------------") ;
System.out.println("");
System.out.println("Voltage Source V = " + compArr[VIX]+ "volts") ;
System.out.println("Capacitor C = " + compArr[CIX]+ "farads");
System.out.println("Inductor L = " + compArr[LIX] + " henrys") ;
System.out.println("Resistor R =" + compArr[RIX] + "ohms") ;
System.out.println("-----------------------------------------------------") ;

boolean outerLoopFlag ;
boolean innerLoopFlag ;
int i ;
int n = 1 ;
int qArray[] = new int[n] ;
int timeArr[] = new int [n] ;
System.out.println("-----------------------------------------------------") ;
Scanner input = new Scanner (System.in) ;
while ( outerLoopFlag = true) {

System.out.println("Reset Component Values (y/n) ?") ;
String answer = input.nextLine() ;
char ans = answer.charAt(0) ;
if ( ans == 'y') {
getCircuitComp() ;

}
else {
}
innerLoopFlag = true ;
while ( innerLoopFlag = true){
System.out.print("Run a simulation?") ;
String answer2 = input.nextLine() ;
char ans2 = answer2.charAt(0) ;
if (ans2 == 'y'){

System.out.println("Enter a maximum time :") ;
double tMax = input.nextDouble();
System.out.println("Enter a time step:") ;
double tStep = input.nextDouble();
timeArr[n]= genTimeArray(tMax,tStep,n);
qArray[n] = genQArray( timeArr , n , compArr) ;
displayQFunction(timeArr,qArray,n );

}
else{
innerLoopFlag = false ;
}
System.out.println("-----------------------------------------------------") ;

while (innerLoopFlag = false) {
System.out.println("Do you want to quit (y/n)?") ;
String answer3 = input.nextLine() ;
char ans3 = answer3.charAt(0) ;
if ( ans3 =='y' ){
System.exit(0);
}
else{}

}


}



}

}
////////////////////////////
///*getCircuitComp Method //

public static double[] getCircuitComp() {
Scanner input = new Scanner (System.in) ;
boolean flag = true ;
double compArr [] = new double[4];
do{
System.out.println("Enter a value V ( 4 to 15):") ;
compArr[VIX] = input.nextDouble() ;
if ((compArr[VIX] >= 4.0) && (compArr[VIX] <= 15.0)){
flag = false ;
}
else{
System.out.println("Bad Value" + compArr[VIX] ) ;
}

} while ( flag );
flag = true ;
while (flag) {
System.out.println("Enter a value for R ( 5 to 10) :") ;
compArr[RIX] = input.nextDouble();
if((compArr[RIX] >= 5.0) && (compArr[RIX] <= 10.0)){
flag = false;
}
else{
System.out.println("Bad Value:"+ compArr[RIX]) ;

}

}
flag = true ;
while(flag) {
System.out.println("Enter a value for C( 1e-9 to 1e-7 ): ") ;
compArr[CIX] = input.nextDouble();
if (( compArr[CIX] >= Math.pow(10, -9)) && (compArr[CIX] <= Math.pow(10, -7))){
flag = false ;
}
else{
System.out.println("Bad Value :"+ compArr[CIX]);
}


}
flag = true ;
while(flag){
System.out.println("Enter a value for L(1e-3 to 1e-1) ");
compArr[LIX] = input.nextDouble();
if(compArr[LIX]>= Math.pow(10,-3) && compArr[LIX] <= Math.pow(10, -1)){
flag = false ;
}
else{
System.out.println("Bad Value :" + compArr[LIX]) ;

}
}
return compArr ;
}


////////////////////////////
///*getTimeArray Method //
public static int genTimeArray( double tMax , double tStep , int n ) {

int t[] = new int[n] ;
n = 1 ;
t[0] = 0 ;
if(t[n] < tMax){
t[n] = (int) (t[n-1] + tStep) ;
n = n + 1 ;
}
return t[n] ;

}
public static int genQArray( int timeArr[] , int n , double compArr [] ) {
double q[] = new double[n] ;
n = 1 ;
double s = (compArr[VIX])*(compArr[CIX]) ;
double t = Math.exp((-compArr[RIX])/(2*compArr[LIX]));
double c = (1)/((compArr[LIX])*(compArr[CIX])) ;
double v = Math.pow((compArr[RIX])/(2*(compArr[LIX])),2) ;
double r = (timeArr[n])*(Math.sqrt(c-v)) ;
q[n] = (s)*(t)*(Math.cos(r)) ;

return (int) q[n] ;
}
////////////////////////////
///*displayQFunction Method //
public static void displayQFunction(int[] timeArr , int[] qArray ,int n ){

n = 1 ;
System.out.println( timeArr[n] + qArray[n]) ;




}
}

感谢您的帮助! ,

标记

最佳答案

The method displayQFunction(int[], int[], int) is undefined for the type Ass1

这是一个拼写错误:在声明方法时,您将 Function 拼写为 Fuction

改变

public static void  displayQFuction(int[] timeArr , int[] qArray ,int n  ){ 

public static void  displayQFunction(int[] timeArr , int[] qArray ,int n  ){ 

关于java - 数组错误(处理多个数组),找不到解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13318563/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com