View Single Post
  #1 (permalink)  
Old 12-13-2007, 07:45 AM
apfroggy0408 apfroggy0408 is offline
Member
 
Join Date: Dec 2007
Posts: 26
apfroggy0408 is on a distinguished road
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.

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.

Code:
computePayment(double,double,int,double) in Interest cannot be applied to ()
Thanks for all help.

Last edited by apfroggy0408 : 12-13-2007 at 08:14 AM.
Reply With Quote
Sponsored Links