Announcement

Collapse
No announcement yet.

Cannot get Java Program to compile

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cannot get Java Program to compile

    I'm scratching my head on this one..can't figure out what I'm doing wrong.

    Code:
    import java.io.*;
    import java.text.NumberFormat;// Number format
    import java.util.Locale;//sets location of currency
    
    
    class mortgagewk5 //name of program
    {
    public static void main(String[]arguments) throws IOException
    {
    	NumberFormat nformat = NumberFormat.getCurrencyInstance(Locale.US); //currency format
    	BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    
    	LoanOptionsWk5[] Loans = new LoanOptionsWk5[3];//array setup for loans
    
    	Loans[0] = new LoanOptionsWk5 (200000, 7, .0525);//first loan @ 200000 over 7 years at 5.25 intrest
    	Loans[1] = new LoanOptionsWk5 (200000, 15, .0550);//second loan @ 20000 over 15 years at 5.5 interest
    	Loans[2] = new LoanOptionsWk5 (200000, 30, .0575);//third loan @ 20000 over 30 years at 5.75 interest
    
    	 //print out of initial header information: output array data to screen, currency is formatted, and percentages are shown.
    	  System.out.println();
    	  System.out.println("\tMortgage Calculator");
    	  System.out.println();
    	  System.out.println("Loan Amount = $" + nformat.format(Loans[0].getloan()));
    	  System.out.println("Years\t\t|   " + Loans[0].gettime() + "\t\t" + Loans[1].gettime() + "\t\t" + Loans[2].gettime());
    	  System.out.println("Interest Rate\t|   " + Loans[0].getinterest()*100 + "%" + "\t" + Loans[1].getinterest()*100 + "%" + "\t\t" + Loans[2].getinterest()*100 + "%");
    	  System.out.println("Monthly Payment\t|   " + nformat.format(Loans[0].getmonthlypay()) + "\t" + nformat.format(Loans[1].getmonthlypay()) + "\t" + nformat.format(Loans[2].getmonthlypay()));
    	  System.out.println("_____________________________________________________________________");
    
    		//determine max months to determine number of monthly transactions to run
    		int months = Loans[0].getmonths();
    		for (int i=0; i < Loans.length; i++) {
    		        if(Loans[i].getmonths() > months){
    		            months = Loans[i].getmonths();   // new maximum
    		        }
    		}
    
    		//declare variables
    		double intpay;
    		double balpay;
    		double loanbal = 0;
    
    		//execute monthly transactions
    		for(int i = 0; i < months+1; i++){
    			System.out.println("Month " + (i+1));
    
    			//execute each loan option for month
    			for (int c=0; c < Loans.length; c++){
    
    				//declare variables
    				double loan = Loans[c].getloan();
    				int time = Loans[c].gettime();
    				double intrate = Loans[c].getinterest();
    
    				//calculate mortgage information
    				intpay = Loans[c].getbalance() * (Loans[c].getinterest()/12); //this is the interested paid each month
    				balpay = Loans[c].getmonthlyPay() - intpay; //this is the amount paid towards principal each month
    				loanbal = Loans[c].getbalance() - balpay; //this is the new loan balance after payment
    
    				//print out monthly transactional information
    				if (intpay > 0){
    					if (loanbal > 0){
    					  	System.out.println("\t" + time + " year loan - interest $" + nformat.format(intpay) + " Remaining balance $" + nformat.format(loanbal));
    					} else {
    					  	System.out.println("\t" + time + " year loan - interest $" + nformat.format(intpay) + " Remaining balance $0.00");
    					}
    				}else{
    				  	System.out.println("\t" + time + " Loan Completed");
    				}
    
    				//set new loan balance for purposes of figuring monthly transactions
    				Loans[c] = new LoanOptionsWk5(loan, time, intrate, loanbal);
    			}
    
    			System.out.println();
    
    			//conditional check to allow pause in output at intervals until key press
    			if ((i % 10) == 0){
    				System.out.print("Press any key...");
    				try{
    					input.readLine();
    		            	}
    				catch (Exception e){
    					e.printStackTrace();
    				}
    			}
    		}
    	 }
    	}
    This what I'm getting from Textpad:
    C:\Documents and Settings\Scott\Desktop\Mortgagewk5.java:19: cannot find symbol
    symbol : class LoanOptionsWk5
    location: class mortgagewk5
    LoanOptionsWk5[] Loans = new LoanOptionsWk5[3];//array setup for loans
    ^
    C:\Documents and Settings\Scott\Desktop\Mortgagewk5.java:19: cannot find symbol
    symbol : class LoanOptionsWk5
    location: class mortgagewk5
    LoanOptionsWk5[] Loans = new LoanOptionsWk5[3];//array setup for loans
    ^
    C:\Documents and Settings\Scott\Desktop\Mortgagewk5.java:21: cannot find symbol
    symbol : class LoanOptionsWk5
    location: class mortgagewk5
    Loans[0] = new LoanOptionsWk5 (200000, 7, .0525);//first loan @ 200000 over 7 years at 5.25 intrest
    ^
    C:\Documents and Settings\Scott\Desktop\Mortgagewk5.java:22: cannot find symbol
    symbol : class LoanOptionsWk5
    location: class mortgagewk5
    Loans[1] = new LoanOptionsWk5 (200000, 15, .0550);//second loan @ 20000 over 15 years at 5.5 interest
    ^
    C:\Documents and Settings\Scott\Desktop\Mortgagewk5.java:23: cannot find symbol
    symbol : class LoanOptionsWk5
    location: class mortgagewk5
    Loans[2] = new LoanOptionsWk5 (200000, 30, .0575);//third loan @ 20000 over 30 years at 5.75 interest
    ^
    C:\Documents and Settings\Scott\Desktop\Mortgagewk5.java:77: cannot find symbol
    symbol : class LoanOptionsWk5
    location: class mortgagewk5
    Loans[c] = new LoanOptionsWk5(loan, time, intrate, loanbal);
    ^
    6 errors

    Heres my array to make the program work
    Code:
    class loanoptionswk5{
    
    	//declare variables
    	int aamount;
    	int atime;
    	int amonths;
    	double aloanblance;
    	double aintrate;
    
    
    	//constructor for array and intiziation of variables
    	loanoptionswk5(int amount,int time,double loanblance,double intrate) {
    	aamount = amount;
    	atime = time;
    	aloanblance = loanblance;
    	aintrate = intrate;
    	}
    
    	//Method of solving mortgages
    	double getmonthlypay(){
    	double rate = aintrate / 12; //calculated monthly interest rate
    	double payment = (aamount * rate) / (1 - (Math.pow(rate+1,-(atime*12)))); //monthly payment
    	return payment;
    	}
    	int getmonths(){
    	amonths = atime * 12;
    	return amonths;
    	}
    	double getinterest(){
    	return aintrate;
    	}
    	int getloan(){
    	return aamount;
    	}
    	int gettime(){
    	return atime;
    	}
    	double getblance(){
    	return aloanblance;
    }
    }
    Any hints?
    Why is it called tourist season, if we can't shoot at them?

  • #2
    Java is case sensitive to class/physical file name.
    Juu nin to iro


    English doesn't borrow from other languages. It follows them down dark alleys, knocks them over, and goes through their pockets for loose grammar.

    Comment


    • #3
      Yup. Also, what are you programming in, Dave? Have you tried Eclipse? I love it.
      Gigabyte P35-DS3L with a Q6600, 2GB Kingston HyperX (after *3* bad pairs of Crucial Ballistix 1066), Galaxy 8800GT 512MB, SB X-Fi, some drives, and a Dell 2005fpw. Running WinXP.

      Comment


      • #4
        I'm still having problems after fixing the case of the file names/classes:

        here we go:

        Program:

        Code:
        import java.io.*;
        import java.text.NumberFormat;// Number format
        import java.util.Locale;//sets location of currency
        
        
        class Mortgagewk5 //name of program
        {
        public static void main(String[]arguments) throws IOException
        {
        	NumberFormat nformat = NumberFormat.getCurrencyInstance(Locale.US); //currency format
        	BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        
        	LoanOptionsWk5[] Loans = new LoanOptionsWk5[3];//array setup for loans
        
        	Loans[0] = new LoanOptionsWk5 (200000, 7, .0525);//first loan @ 200000 over 7 years at 5.25 intrest
        	Loans[1] = new LoanOptionsWk5 (200000, 15, .0550);//second loan @ 20000 over 15 years at 5.5 interest
        	Loans[2] = new LoanOptionsWk5 (200000, 30, .0575);//third loan @ 20000 over 30 years at 5.75 interest
        
        	 //print out of initial header information: output array data to screen, currency is formatted, and percentages are shown.
        	  System.out.println();
        	  System.out.println("\tMortgage Calculator");
        	  System.out.println();
        	  System.out.println("Loan Amount = $" + nformat.format(Loans[0].getloan()));
        	  System.out.println("Years\t\t|   " + Loans[0].gettime() + "\t\t" + Loans[1].gettime() + "\t\t" + Loans[2].gettime());
        	  System.out.println("Interest Rate\t|   " + Loans[0].getinterest()*100 + "%" + "\t" + Loans[1].getinterest()*100 + "%" + "\t\t" + Loans[2].getinterest()*100 + "%");
        	  System.out.println("Monthly Payment\t|   " + nformat.format(Loans[0].getmonthlypay()) + "\t" + nformat.format(Loans[1].getmonthlypay()) + "\t" + nformat.format(Loans[2].getmonthlypay()));
        	  System.out.println("__________________________________________________  ___________________");
        
        		//determine max months to determine number of monthly transactions to run
        		int months = Loans[0].getmonths();
        		for (int i=0; i < Loans.length; i++) {
        		        if(Loans[i].getmonths() > months){
        		            months = Loans[i].getmonths();   // new maximum
        		        }
        		}
        
        		//declare variables
        		double intpay;
        		double balpay;
        		double loanbal = 0;
        
        		//execute monthly transactions
        		for(int i = 0; i < months+1; i++){
        			System.out.println("Month " + (i+1));
        
        			//execute each loan option for month
        			for (int c=0; c < Loans.length; c++){
        
        				//declare variables
        				double loan = Loans[c].getloan();
        				int time = Loans[c].gettime();
        				double intrate = Loans[c].getinterest();
        
        				//calculate mortgage information
        				intpay = Loans[c].getbalance() * (Loans[c].getinterest()/12); //this is the interested paid each month
        				balpay = Loans[c].getmonthlyPay() - intpay; //this is the amount paid towards principal each month
        				loanbal = Loans[c].getbalance() - balpay; //this is the new loan balance after payment
        
        				//print out monthly transactional information
        				if (intpay > 0){
        					if (loanbal > 0){
        					  	System.out.println("\t" + time + " year loan - interest $" + nformat.format(intpay) + " Remaining balance $" + nformat.format(loanbal));
        					} else {
        					  	System.out.println("\t" + time + " year loan - interest $" + nformat.format(intpay) + " Remaining balance $0.00");
        					}
        				}else{
        				  	System.out.println("\t" + time + " Loan Completed");
        				}
        
        				//set new loan balance for purposes of figuring monthly transactions
        				Loans[c] = new LoanOptionsWk5(loan, time, intrate, loanbal);
        			}
        
        			System.out.println();
        
        			//conditional check to allow pause in output at intervals until key press
        			if ((i % 10) == 0){
        				System.out.print("Press any key...");
        				try{
        					input.readLine();
        		            	}
        				catch (Exception e){
        					e.printStackTrace();
        				}
        			}
        		}
        	 }
        	}
        Heres the loan options class:
        Code:
        class LoanOptionsWk5{
        
        	//declare variables
        	double aamount;
        	int atime;
        	int amonths;
        	double aloanblance;
        	double aintrate;
        
        
        	//constructor for array and intiziation of variables
        	LoanOptionsWk5(int amount,int time,double loanblance,double intrate) {
        	aamount = amount;
        	atime = time;
        	aloanblance = loanblance;
        	aintrate = intrate;
        	}
        
        	//Method of solving mortgages
        	double getmonthlypay(){
        	double rate = aintrate / 12; //calculated monthly interest rate
        	double payment = (aamount * rate) / (1 - (Math.pow(rate+1,-(atime*12)))); //monthly payment
        	return payment;
        	}
        	int getmonths(){
        		amonths = atime * 12;
        	return amonths;
        	}
        	double getinterest(){
        	return aintrate;
        	}
        	double getloan(){
        	return aamount;
        	}
        	int gettime(){
        	return atime;
        	}
        	double getblance(){
        	return aloanblance;
        }
        }
        The Errors I'm getting:

        Code:
        C:\Documents and Settings\Scott\Desktop\Mortgagewk5.java:15: cannot find symbol
        symbol  : constructor LoanOptionsWk5(int,int,double)
        location: class LoanOptionsWk5
        	Loans[0] = new LoanOptionsWk5 (200000, 7, .0525);//first loan @ 200000 over 7 years at 5.25 intrest
                           ^
        C:\Documents and Settings\Scott\Desktop\Mortgagewk5.java:16: cannot find symbol
        symbol  : constructor LoanOptionsWk5(int,int,double)
        location: class LoanOptionsWk5
        	Loans[1] = new LoanOptionsWk5 (200000, 15, .0550);//second loan @ 20000 over 15 years at 5.5 interest
                           ^
        C:\Documents and Settings\Scott\Desktop\Mortgagewk5.java:17: cannot find symbol
        symbol  : constructor LoanOptionsWk5(int,int,double)
        location: class LoanOptionsWk5
        	Loans[2] = new LoanOptionsWk5 (200000, 30, .0575);//third loan @ 20000 over 30 years at 5.75 interest
                           ^
        C:\Documents and Settings\Scott\Desktop\Mortgagewk5.java:55: cannot find symbol
        symbol  : method getbalance()
        location: class LoanOptionsWk5
        				intpay = Loans[c].getbalance() * (Loans[c].getinterest()/12); //this is the interested paid each month
                                                      ^
        C:\Documents and Settings\Scott\Desktop\Mortgagewk5.java:56: cannot find symbol
        symbol  : method getmonthlyPay()
        location: class LoanOptionsWk5
        				balpay = Loans[c].getmonthlyPay() - intpay; //this is the amount paid towards principal each month
                                                      ^
        C:\Documents and Settings\Scott\Desktop\Mortgagewk5.java:57: cannot find symbol
        symbol  : method getbalance()
        location: class LoanOptionsWk5
        				loanbal = Loans[c].getbalance() - balpay; //this is the new loan balance after payment
                                                       ^
        C:\Documents and Settings\Scott\Desktop\Mortgagewk5.java:71: cannot find symbol
        symbol  : constructor LoanOptionsWk5(double,int,double,double)
        location: class LoanOptionsWk5
        				Loans[c] = new LoanOptionsWk5(loan, time, intrate, loanbal);
                                                   ^
        7 errors
        
        Tool completed with exit code 1
        ughhhh
        Why is it called tourist season, if we can't shoot at them?

        Comment


        • #5
          Is it because your constructor takes 4 arguments and you call it with only 3?

          Sorry if this is wrong, been a while since I wrote any java.
          Chuck
          秋音的爸爸

          Comment


          • #6
            Originally posted by cjolley
            Is it because your constructor takes 4 arguments and you call it with only 3?

            Sorry if this is wrong, been a while since I wrote any java.
            I'm thinking that too. The method signature of the constructor takes 4 arguments (int,int,double,double) and the new statement only includes 3 (int,int,double). You cannot skip an argument in Java and hope the JRE to fill it for you.

            The compiler errors a bit down is because the names do not match with those in the LoanOptionsWk5 class. Use cut and paste or a good IDE to avoid that kind of problems. Eclipse and Netbeans are two good IDEs.

            /L
            AMD Athlon64 X2 4200+
            Asus A8N-E
            Corsair TWINX2048-3200C2
            Asus Extreme GeForce N7800GT
            Seagate Barracuda 7200.8 250GB
            Lian-Li PC60
            Windows XP Pro 64bit

            Comment

            Working...
            X