Results 1 to 4 of 4
  1. #1
    apfroggy0408 is offline Member
    Join Date
    Dec 2007
    Posts
    26
    Rep Power
    0

    Default Half a semester into java

    I'm currently taking the APCS course at my school, and we've done some work with classes and such. I'm getting an error and I don't know how to resolve it. here's the code.

    Java Code:
    /**
     * @(#)WatchInterest.java
     *
     *
     * @author 
     * @version 1.00 2007/12/11
     */
    
    import java.util.*;
    public class WatchInterest {
    
        public static void main(String args[]) 
        {
        	Scanner input = new Scanner(System.in);
        	
        	int choice;
        	double principal;
        	double yearlyInterest;
        	int paybackYears;
        	double monthlyPmt;
        	
        	System.out.println("Select on of the following options");
        	System.out.println();
        	System.out.println("[1]	Monthly Loan Payment Computation");
        	System.out.println("[2]	Amortization Schedule");
        	System.out.println("[3]	Credit Card Pay-Off Schedule");
        	System.out.println();
        	System.out.println("Enter your choice: ");
        	choice = input.nextInt();
        	System.out.println();
        	
        	switch (choice)
        	{
        		case 1:
        			System.out.println("Enter Loan Amount: ");
        			principal = input.nextDouble();
        			System.out.println("Enter Annual Percent: ");
        			yearlyInterest = input.nextDouble();
        			System.out.println("Enter Years to Pay Back: ");
        			paybackYears = input.nextInt();
        			Interest loan1 = new Interest(principal, yearlyInterest, paybackYears,0);
        		 ---> loan1.computePayment();
        			break;
        		
        		case 2:
        			System.out.println("Enter principle balance: ");
        			principal = input.nextDouble();
        			System.out.println("Enter annual percent: ");
        			yearlyInterest = input.nextDouble();
        			System.out.println("Enter monthly payment: ");
        			monthlyPmt = input.nextDouble();
        			Interest loan2 = new Interest(principal, yearlyInterest, 0, monthlyPmt);
        			loan2.amortization();
        			break;
        			
        		case 3:
        			System.out.println("Enter credit card balance: ");
        			principal = input.nextDouble();
        			System.out.println("Enter annual percent: ");
        			yearlyInterest = input.nextDouble();
        			Interest loan3 = new Interest(principal, yearlyInterest, 0, 0);
        			loan3.creditCard();
        			break;
        			}
        			System.out.println();
        	}
        }
    class Interest
    {
    	private double principal;
    	private double percent;
    	private int years;
    	private double monthlyPmt;
    	private int months;
    	private int pmtNr;
    	private double monthlyRate;
    	private double interestPmt;
    	private double principalPmt;
    	private double totalPmt;
    	private double totalInt;
    	
    	public Interest(double la, double yi, int py, double mp)
    		//do not alter anythign in the constructor
    	{
    		principal = la;
    		percent = yi;
    		years = py;
    		monthlyPmt = mp;
    		monthlyRate = percent/1200;
    		months = years * 12;
    		pmtNr = 0;
    	}
    	
    	private double round(double x)
    	{
    		return (double) Math.round(100*x) / 100;
    	}
    	
    	public void computePayment(double la, double yi, int py, double mp)
    	{
    		System.out.println();
    		System.out.println("Monthly Loan Payment Computation");
    		System.out.println();
    		
    		totalPmt = ((yi*Math.pow((1+yi),mp))/(Math.pow((1+yi),mp)-1))*la;
    		
    		
    		
    		System.out.println("Loan Amount: " + principal);
    		System.out.println("Yearly Interest: " +percent);
    		System.out.println("Payback Years: " +years);
    		System.out.println("Monthly Payment: " +monthlyPmt);
    		System.out.println("Total Payments: " +totalPmt);
    		System.out.println("Total Interest: " +totalInt);
    	}
    	
    	public void amortization()
    	{
    		System.out.println();
    		System.out.println("Amortization Schedule");
    		System.out.println();
    		System.out.println("Loan Amount: " + principal);
    		System.out.println("Yearly Interest: " + percent);
    		System.out.println("Monthly Payment: " +monthlyPmt);
    		
    		do
    		{
    				System.out.println(pmtNr+"     \t"+monthlyPmt+"     \t"+interestPmt+"     \t"+principalPmt+"     \t"+principal);
    		}	
    			while (principal > 0);
    			
    			System.out.println("Payback Months: " +pmtNr);
    			System.out.println("Total Pyaments: " +totalPmt);
    			System.out.println("Total Interest: " +totalInt);
    		
    		}
    	
    	
    	public void creditCard()
    	{
    		System.out.println();
    		System.out.println("Credit Card Pay-Off Schedule");
    		System.out.println();
    		System.out.println("Yearly Interest: " +percent);
    		
    		do
    		{
    			System.out.println(pmtNr+"     \t"+monthlyPmt+"     \t"+interestPmt+"     \t"+principalPmt+"     \t"+principal);
    		}
    		while (principal > 0 );
    		
    		System.out.println("Payback Months: " +pmtNr);
    		System.out.println("Total Pyaments: " +totalPmt);
    		System.out.println("Total Interest: " +totalInt);
    	}
    	}
    The problem is occuring in the first switch case and the exact error is.

    Java Code:
    computePayment(double,double,int,double) in Interest cannot be applied to ()
    Thanks for all help.
    Last edited by apfroggy0408; 12-13-2007 at 07:14 AM.

  2. #2
    ahmadmz is offline Member
    Join Date
    Dec 2007
    Posts
    1
    Rep Power
    0

    Default

    Hi, well the method computePayment requires 4 arguments and you are calling it with none.

  3. #3
    apfroggy0408 is offline Member
    Join Date
    Dec 2007
    Posts
    26
    Rep Power
    0

    Default

    I'm not sure what you mean, but the problem was was that i was using the wrong variables.

  4. #4
    felixtfelix is offline Member
    Join Date
    Dec 2007
    Location
    Mumbai, India
    Posts
    37
    Rep Power
    0

    Default

    well. u have a method computePayment(double la, double yi, int py, double mp)in the Interest Class for which we have to send four parameters means four values as an arguments. But when you are calling the same method in the first switch statement u use the statement loan1.computePayment(). there we are not sending any parameters.

    You can fix in two ways
    1. Remove the parameters in the method definition inside the Interest class for all the methods.
    2. Pass four parameters when you call the particular method in each of the switch class.

Similar Threads

  1. JAVA Architect Position - Robert Half Technology
    By pegitha in forum Jobs Offered
    Replies: 0
    Last Post: 05-18-2007, 09:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •