import javax.swing.*;
import BreezySwing.*;

public class PaymentDDJ extends GBFrame {

   //Declare variables for the window objects.// 
   private JLabel       purchasedprice;
   private JLabel       name1;
   private JLabel       downpayment;
   private JLabel       interestrate;
   private JTextField   nameField;
   private JTextField   purchasedpriceField;
   private JTextField   downpaymentField;
   private JTextField   interestrateField;
   private JButton      enter;
   private JTextArea    balance;
   //Define the other instance variables.//
   private double downpayment1, interestrate1, monthlypay1, purchasedprice1;

     public PaymentDDJ();

   String header = Format.justify('l', "NAME", 12) +
                   Format.justify('r', "MONTH", 15) +
                   Format.justify('r', "CURRENT BALANCE OWED", 15) +
                   Format.justify('r', "INTEREST OWED", 15) +
                   Format.justify('r', "PRINCIPAL OWED", 15) + 
                   Format.justify('r', "TOTAL MONTHLY PAYMENT", 15) +
                   Format.justify('r', "REMAINING BALANCE", 15) + "\n";

   // Instantiate the window objects.//
   name = addLabel               ("Name"              ,1,1,1,1);
   purchasedprice = addLabel     ("Purchased price $" ,2,1,1,1);
   nameField = addTextField           (""                  ,1,1,1,1);
   purchasedpriceField = addTextField ("0"                 ,1,1,1,1);
   enter = addButton             ("Enter"             ,1,1,1,1);
   balance = addTextArea         (header              ,1,1,1,1);                       

   //Inputs.//
   output.setEnabled(false);
   nameField.requestFocus();

   downpayment1 = 0;
   interestrate1 = 0;
   monthlypay1 = 0;
   purchasedprice = 0;

   public void buttonClicked (JButton buttonObj){
     if (buttonObj == enter){
       processInputs();
       nameField.requestFocus();
     }else{
       enter.setEnabled(false);
       totalsButton.setEnabled(false);

       displayDashes();
       displayNumbers (downpayment, interestrate, monthlypay, purchasedprice, balance);
     }
   }

   private void processInputs(){

     String name;
     int purchasedprice, downpayment, interestrate, monthlypay, balance;

     name = nameField.getText();
     purchasedprice = purchasedpriceField.getNumber();

     downpayment = purchasedprice * 0.10;
     interestrate = purchasedprice * 0.5;
     monthlypay = ((purchasedprice * 0.5) - downpayment);
     balance = purchasedprice - downpayment - interestrate - monthlypay;

     displayNumbers (name, purchasedprice, downpayment, interestrate, monthlypay, balance);

     private void displayNumbers (String name, int purchasedprice, int downpayment, int interestrate, int monthlypay, int balance){
       String numberLine = Format.justify ('l', name, 12) +
                           Format.justify ('l', purchasedprice, 15, 2) +
                           Format.justify ('l', downpayment, 15, 2) +
                           Format.justify ('l', interestrate, 15, 2) +
                           Format.justify ('l', monthlypay, 15, 2) +
                           Format.justify ('l', balance, 15, 2);
        balance.append (numberLine + "\n");
     }
     private void displayDashes(){
        String dashLine = Format.justify ('l', " ", 12) +
                          Format.justify ('l'," ---------", 15, 2) +
                          Format.justify ('l', " ---------", 15, 2) +
                          Format.justify ('l'," ---------", 15, 2) +
                          Format.justify ('l', " ---------", 15, 2) +
                          Format.justify ('l', " ---------", 15, 2);
        balance.append (dashLine + "\n");
     }

     public static void main (String[] args){
       PaymentDDJ theGUI = new PaymentDDJ();
       theGUI.setSize (350,225);
       theGUI.setVisible (true);
     }
   }

The question is:
The Tidbit Computer Store has a credit plan for computer purchases. There is a 10 percent down payment and an annual interest raye of 12 percent. Monthly payments are 5 percent of the listed purchase price minus the down payment. Write a program that takes the purchase price as input. The program should display a table, with apprioriate headers, of a payment schedule for the lifetime of the loan. Each row of the table should contain the following items:

The month number(beginning with 1)
The current totak balanced owed
The interest owed for that month
The amount of principal owed for that month
The payment for that month
The balance remaining after payment
The amount of interest for a month is equal to balance * rate/12. The amount of principal for a month is equal to the monthly payment minus the interest

"The complier keep saying <indentifier> expected."
What corrections should i make to the program to make it compile

Recommended Answers

All 3 Replies

use code tags, and can you actually copy the section of the stack trace. if it is repeated, 1 instance is enough.

" The complier keep saying <indentifier> expected."

This seems like a compilation error, although you will not get a stacktrace, the java compiler would definitely have pin pointed where this error was found ???
Also the next time paste your code inside code tags like this :-

[code=java] // Your code here

[/code]

public PaymentDDJ();

This is wrong, you need to provide a method body to the constructor. Also this is wrong :

String header = Format.justify('l', "NAME", 12) +
Format.justify('r', "MONTH", 15) +
Format.justify('r', "CURRENT BALANCE OWED", 15) +
Format.justify('r', "INTEREST OWED", 15) +
Format.justify('r', "PRINCIPAL OWED", 15) +
Format.justify('r', "TOTAL MONTHLY PAYMENT", 15) +
Format.justify('r', "REMAINING BALANCE", 15) + "\n";

// Instantiate the window objects.//
name = addLabel ("Name" ,1,1,1,1);
purchasedprice = addLabel ("Purchased price $" ,2,1,1,1);
nameField = addTextField ("" ,1,1,1,1);
purchasedpriceField = addTextField ("0" ,1,1,1,1);
enter = addButton ("Enter" ,1,1,1,1);
balance = addTextArea (header ,1,1,1,1);

You cannot have these statements outside a method body, they need to be inside some method.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.