943,831 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 3896
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 23rd, 2007
0

Java Error

Expand Post »
Hi need help and explanation to fix the following error in my java program. I can not get the program to show a gui pop-up window. I have to turn this end by 12midnight EST.

Just looked at this code, when you see that dos window and no GUI it is because you have no main () method.
A JAVA program needs a main () method to run the error I see indicates you have none. ( )

here is my complete code;

/*
*
*
* Author P. Manus
* Week 3: Computer Programming I POS/407
* Programmer: Paul Manus
* Date: July 22, 2007
* Filename: MortCalcuWk3.java
* Purpose: Complete Change Request #5 in Service Request SR-mf-
* 003. Insert comments in the program to document the program.
* Attach a design flow chart to the source code of the program.
* This project accepts three user inputs
* using GUI principle,term, and interest then calculates and
* return the monthly payment for the mortgage loan.
*
*/


//Import java packages
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.lang.*;
import java.text.NumberFormat;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;


public class MortCalcuWk3 extends JFrame implements ActionListener
{
// Labels
JLabel AmountLabel = new JLabel( "Mortgage Amount " );
JLabel PaymentLabel = new JLabel( "Monthly Payment: " );
JLabel InterestLabel = new JLabel( "Interest Rate %: " );
JLabel TermofLoanLabel = new JLabel( "TermofLoan of Loan: " );

// Text Fields
JTextField mortgageAmount = new JTextField(7);
JTextField MonthlyPayment = new JTextField(7);
JTextField InterestRate = new JTextField(7);
JTextField TermofLoan = new JTextField(7);


// Buttons
JButton Loan1 = new JButton( "7 years at 5.35%" );
JButton Loan2 = new JButton( "15 years at 5.50%" );
JButton Loan3 = new JButton( "30 years at 5.75%" );
JButton ExitButton = new JButton( "Exit" );
JButton ClearButton = new JButton( "Clear" );
JButton CalculateButton = new JButton( "Calculate" );
JButton SaveButton = new JButton( "Save" );
JButton ChartButton = new JButton( "Show Chart" );

// Text Area and Scroll
JTextArea MortgageTable = new JTextArea(25,40);
JScrollPane scroll = new JScrollPane(MortgageTable);

//MortCalcWk3()Method
{
//Frame, Panel, and Layout set up
setSize(600, 400);
setLocation(0, 0);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane = new JPanel();
pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));

//Setup container and contents
Container grid = getContentPane();
grid.setLayout(new GridLayout(4,0,5,5));
pane.add(grid);
pane.add(scroll);
grid.add(AmountLabel);
grid.add(mortgageAmount);
grid.add(InterestLabel);
grid.add(InterestRate);
grid.add(TermofLoanLabel);
grid.add(TermofLoan);
grid.add(PaymentLabel);
grid.add(MonthlyPayment);
grid.add(Loan1);
grid.add(Loan2);
grid.add(Loan3);
grid.add(SaveButton);
grid.add(CalculateButton);
grid.add(ClearButton);
grid.add(ExitButton);
grid.add(ChartButton);
MonthlyPayment.setEditable(false);
setContentPane(pane);
setVisible(true);

//Adds Action Listeners
ExitButton.addActionListener(this);
ClearButton.addActionListener(this);
Loan1.addActionListener(this);
Loan2.addActionListener(this);
Loan3.addActionListener(this);
mortgageAmount.addActionListener(this);
InterestRate.addActionListener(this);
TermofLoan.addActionListener(this);
MonthlyPayment.addActionListener(this);
CalculateButton.addActionListener(this);


} //End MortCalcuWk3 method


public void actionPerformed(ActionEvent e)
{
Object command = e.getSource();
if
(
command == ExitButton)
System.exit(0);

int loanTermofLoan = 0;

if (command == Loan1)
{
loanTermofLoan = 0; //Sets 1st value of Array
TermofLoan.setText("0");
InterestRate.setText("0");
}

if (command == Loan2) //Activates the 2nd Loan Button
{
loanTermofLoan = 1; //Sets 2nd value of Array
TermofLoan.setText("0");
InterestRate.setText("0");
}

if (command == Loan3) //Activates the 3rd Loan Button
{
loanTermofLoan = 2; // Sets 3rd value of Array
TermofLoan.setText("0");
InterestRate.setText("0");
}

if (command == CalculateButton ) //Activates the Calculate Button for manual entries
{
loanTermofLoan = 3; // Sets 4rd value of Array
}

double t1 = Double.parseDouble(TermofLoan.getText());
double r1 = Double.parseDouble(InterestRate.getText());
double [][] loans = { {7, 5.35}, {15, 5.50}, {30, 5.75}, {t1, r1} };

double mortgage = 0; // Declares and Initializes mortgage
mortgage = Double.parseDouble(mortgageAmount.getText());
double interestRate = loans [loanTermofLoan][1];
double intRate = (interestRate / 100) / 12;
double loanTermofLoanMonths = loans [loanTermofLoan] [0];
int months = (int)loanTermofLoanMonths * 12;
double interestRateMonthly = (intRate / 12);
double payment = mortgage * intRate / (1 - (Math.pow(1/(1 + intRate), months)));
double remainingLoanBalance = mortgage;
double MonthlyPaymentInterest = 0;
double MonthlyPaymentPrincipal = 0;

// Number formatter to format output in table
NumberFormat CurrencyFormatter = NumberFormat.getCurrencyInstance (Locale.US);
MonthlyPayment.setText(CurrencyFormatter.format(payment));
MortgageTable.setText("Month\tPrincipal\tInterest\tEnding Balance\n" + // Formats TextArea Header
"----------\t------------\t-------------\t----------------------\n"); // Formats TextArea Header cont.

for (;months > 0 ; months -- )
{
//Append loop for mortgage detail in the text area
MonthlyPaymentInterest = (remainingLoanBalance * intRate);//Monthly Payment Toward Interest
MonthlyPaymentPrincipal = (payment - MonthlyPaymentInterest);//Monthly Payment Toward Principal
remainingLoanBalance = (remainingLoanBalance - MonthlyPaymentPrincipal);//Remaining loan Balance

MortgageTable.setCaret (new DefaultCaret()); // Sets Scroll position to the top left corner
MortgageTable.append(String.valueOf(months) + "\t" +
CurrencyFormatter.format(MonthlyPaymentPrincipal) + "\t" +
CurrencyFormatter.format(MonthlyPaymentInterest) + "\t" +
CurrencyFormatter.format(remainingLoanBalance) + "\n");//
}

//New calculation button
if(command == ClearButton)
{
mortgageAmount.setText(null);
MonthlyPayment.setText(null);
InterestRate.setText(null);
TermofLoan.setText(null);
MortgageTable.setText(null);


};
public static void main (String[] args);
} }


Paul
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
manusp is offline Offline
4 posts
since Jul 2007
Jul 23rd, 2007
0

Re: Java Error

Your message already mentions the problem. Your main() method does not do anything. It needs to create the instance of the class and show it.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Jul 23rd, 2007
0

Re: Java Error

public static void main (String[] args);


I know but not exactly sure how the code should be written. Included the above in my code but get an error msg of illegal start of expression public static void main (String[] args);

I am not java or program material savvy! Help please...

should it be written as public void mortcalcuwk3 (String[] args); or how shoudl it be written to get the gui windows to appear??
Reputation Points: 10
Solved Threads: 0
Newbie Poster
manusp is offline Offline
4 posts
since Jul 2007
Jul 23rd, 2007
0

Re: Java Error

The main method is the most basic piece of any program. If you do not understand how to write it then I really have to wonder how you managed to write all of that GUI code yourself.

Anyway, that said, you have the signature for main correct but you have a semicolon at the end and no open brace. It should be:
Java Syntax (Toggle Plain Text)
  1. public static void main(String[] args) {
  2. // your code to create the object here
  3. }
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Jul 23rd, 2007
0

Re: Java Error

What I would recommend is checking to make sure that all methods that are not called from an object using the . operator are declared as static. Otherwise the compiler may just, oh, gosh, not run the blasted thing. Some methods didn't have static in there; I couldn't tell whether or not they were called on their own, but you should keep an eye on that. Buena suerte.
Reputation Points: 86
Solved Threads: 2
Junior Poster
venomlash is offline Offline
143 posts
since Oct 2006
Jul 23rd, 2007
0

Re: Java Error

Click to Expand / Collapse  Quote originally posted by venomlash ...
What I would recommend is checking to make sure that all methods that are not called from an object using the . operator are declared as static. Otherwise the compiler may just, oh, gosh, not run the blasted thing. Some methods didn't have static in there; I couldn't tell whether or not they were called on their own, but you should keep an eye on that. Buena suerte.
That has no bearing on the issue he is having. When to use static methods instead of normal class methods is a separate design issue.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Jul 23rd, 2007
0

Re: Java Error

Sorry. There's always the chance that he's working with one of those really janky compilers (like BlueJ) that show one error and say nothing about the 5,000 others also lurking in your code. But hey, I apologize for my public disservice announcement.
Reputation Points: 86
Solved Threads: 2
Junior Poster
venomlash is offline Offline
143 posts
since Oct 2006
Jul 23rd, 2007
0

Re: Java Error

Guys, sorry but just give me exactly how the code should be written, so i cn turn in my assignment by tonight! Like i said i'll never be a java programmer and i am just trying to complete this class.. I have no shame here but there has been an over kill of progrmming classes just to complete a BSIT degree it is almost tlike I am going for a computer sicence degree vs. info tech... thta is the reason i went for the IT vs. CS to avoid too many programming classes.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
manusp is offline Offline
4 posts
since Jul 2007
Jul 23rd, 2007
0

Re: Java Error

Last edited by Ezzaral; Jul 23rd, 2007 at 4:47 pm.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Jul 23rd, 2007
0

Re: Java Error

ezzaral, thanks......
Reputation Points: 10
Solved Threads: 0
Newbie Poster
manusp is offline Offline
4 posts
since Jul 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: [help_reqd]Noobie needs help
Next Thread in Java Forum Timeline: adding classes at run time (plug-in?)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC