0

我一直在开发一个程序,该程序要求用户输入电路的值,并计算给定时间的电荷。我已经取得了一些进展,但是当我的一个数组拒绝返回值并且 eclipse 中提到的原因是:

  • *此行有多个标记
  • Ass1 类型中的方法 genQArray(int[], int, double[], int, int, int, int) 不适用于参数 (int[], int, double, int, int, int, int)
  • Ass1 类型中的方法 genQArray(int[], int, double[], int, int, int, int) 不适用于参数 (int[], int, int)*

老实说,我现在不知道问题出在哪里,我想找到解决方案,所以我可以继续研究这个程序。任何帮助都将不胜感激。

这是我的代码,虽然它尚未完成:

import java.util.* ;
public class Ass1 {

    static int VIX ; // Traversing Voltage Component in Component Value Array 
    static int CIX ; 
    static int LIX ; 
    static int RIX ; 

    public static void main (String args[]) { 
        double compArr  = getCircuitComp() ; 
        boolean outerLoopFlag ; 
        boolean innerLoopFlag ; 
        int i ; 
        int n ;
        int timeArr[] = new int[n] ; 
        int qArray[] = new int[n] ;
        Scanner input = new Scanner (System.in) ;
        while ( outerLoopFlag = true) { 

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

            } 
            else { 
                    } 
            innerLoopFlag = true ; 
            while ( innerLoopFlag = true){ 
                System.out.print("Run a simulation?") ; 
                String answer2 = input.nextLine() ; 
                char ans2 = answer.charAt(0) ; 
                if (ans2 == 'y'){
                System.out.print("Enter a maximum time :") ; 
                double tMax = input.nextDouble(); 
                System.out.print("Enter a time step:") ; 
                double tStep = input.nextDouble();
                timeArr[n]= genTimeArray(tMax,tStep,n);  
                qArray[n] = genQArray( timeArr , n , compArr,  VIX ,  CIX ,  RIX ,  LIX) ;  
                displayQFunction(timeArr,qArray,n);

                }

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

                }


            }   



    }

}

    public static int getCircuitComp() {
        Scanner input = new Scanner (System.in) ; 
        boolean flag = true ; 
        double compArr [] = new double[4]; 
        while (  flag = true ) { 
            System.out.print("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.print("Bad Value" + compArr[VIX] ) ;
            }

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

            }

        }
            flag = true ; 
            while(flag) { 
                System.out.print("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.print("Bad Value :"+ compArr[CIX]);
                }


            }
                flag = true ; 
                while(flag){ 
                    System.out.print("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.print("Bad Value :" + compArr[LIX]) ; 

                    }
                }
                return (int) (compArr[CIX] + compArr[LIX] + compArr[RIX] + compArr[VIX]) ;  
            }


        public static int genTimeArray( double tMax , double tStep , int n ) { 
             int t[] = new int[n] ;
             n = 1 ; 
             t[0] = 0 ; 
             t[n] = (int) (t[n-1] + tStep) ; 
             n = n + 1 ; 

            return t[n] ;

        } 
        public static int genQArray( int timeArr[] , int n , double compArr [], int VIX , int CIX , int RIX , int LIX ) {
            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] ;


        }

    } 

在此先感谢您的帮助 !!

标记

4

1 回答 1

0

您需要将compArr变量声明从

double compArr  = getCircuitComp() ; 

double[] compArr  = getCircuitComp() ;

正确匹配方法的参数genQArray。这将涉及返回double[]fromgetCircuitComp()而不是int类型。

public static double[] getCircuitComp() {

在此方法中,您可能打算返回变量:

double compArr [] = new double[4]; 

另请注意,您的变量:

static int VIX ; 
static int CIX ; 
static int LIX ; 
static int RIX ; 

例如,将全部默认为0so,compArr[VIX]并将compArr[CIX]指向数组中索引 0 处的相同值compArr。要修复,您可以指定值:

static int VIX = 0; 
static int CIX = 1; 
...
于 2012-11-09T01:13:08.553 回答