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

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.

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??

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:

public static void main(String[] args) {
   // your code to create the object here
}

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.

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.

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.

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.

ezzaral, thanks......

Guys, sorry but just give me exactly how the code should be written, so i cn turn in my assignment by tonight!

That's NOT how things work. If you're incapable of or unwilling to (sounds not the case here) doing your work you SHOULD fail early, to prevent worse failure later on.

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.

You're doing this type of GUI stuff and never learned how to write a main method? How many other times has someone else just given you exactly how the code should be written?

And this is just classic. You should definately not receive either a BSIT or BSCS if you cannot even grasp some of the most basic concepts of programming. You may not be angling to be a programmer, but to work in the IT field and have absolutely no grasp of programming concepts, qualifies you as nothing more than a "Data Entry" candidate, at best (or manager, it seems, sometimes).

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.