Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / July 2006

Tip: Looking for answers? Try searching our database.

New to java need help with code been up all night.

Thread view: 
Everett Arndt - 29 Jul 2006 12:02 GMT
I started this program three days ago the books have me confused trying to
keep my wits about what I am trying to do.

Here are my errors and my code:

C:\POS407\JavaPrograms\bin>run

C:\POS407\JavaPrograms\bin>REM Change directory to the classes directory

C:\POS407\JavaPrograms\bin>cd ..\classes

C:\POS407\JavaPrograms\classes>REM Execute Java program

C:\POS407\JavaPrograms\classes>java -classpath . EverettMortgagePayment_CR4
Exception in thread "main" java.lang.NoSuchMethodError: main

C:\POS407\JavaPrograms\classes>REM Change directory back to the bin
directory

C:\POS407\JavaPrograms\classes>cd ..\bin

C:\POS407\JavaPrograms\bin>

here is my code:

//*******************************************************
// Code for storing loan information and printing an
*
// amortization report.
*
//*******************************************************

import java.io.*;
import java.text.DecimalFormat;

public class EverettMortgagePayment_CR4
{
  private double loanAmount;   // Loan Amount
  private double interestRate; // Annual Interest Rate
  private double loanBalance;  // Monthly Balance
  private double term;         // Payment Term
  private double payment;      // Monthly Payment
  private int loanYears;       // Years of Loan

  //****************************************************
  // The beginning code uses three parameters:
*
  // which is the loan balance, the annual interest
*
  // rate, and term in years of the loan.
*
  // These values are stored in the corresponding
*
  // code of the program. The private calcPayment code
*
  // is then executed.
*
  //****************************************************

  public EverettMortgagePayment_CR4(double loan, double rate, int years)
  {
     loanAmount = loan;
     loanBalance = loan;
     interestRate = rate;
     loanYears = years;
     calcPayment();
  }

  //******************************************************
  // This area is used to calculate the amount paid per
*
  // month. The result put in the payment field. Then it
*
  // save for use later
*
  //******************************************************

  private void calcPayment()
  {
     // Calculate value of Term
     term =
       Math.pow((1+interestRate/12.0), 12.0 * loanYears);

     // Calculate monthly payment
     payment =
       (loanAmount * interestRate/12.0 * term) / (term - 1);
  }

  //********************************************************
  // The getNumberOfPayments is a mathmatical equation
*
  // allows for the number of loan payments over the years.
*
  //********************************************************

  public int getNumberOfPayments()
  {
     return 12 * loanYears;
  }

  //*********************************************************
  // The makeReport saves the amortization report to a file
*
  // that is created by the filename argumentin the code
*
  //*********************************************************

  public void makeReport(String filename) throws IOException
  {
     double monthlyInterest; // The monthly interest rate
     double principal;       // The amount of principal

     // Create a DecimalFormat object for output formatting.
     DecimalFormat dollar = new DecimalFormat("#,##0.00");

     // Create objects necessary for file output.
     FileWriter fwriter = new FileWriter(filename);
     PrintWriter outputFile = new PrintWriter(fwriter);

     // Print monthly payment amount.
     outputFile.println("Monthly Payment: $"
                  + dollar.format(payment));

     // Print the report header.
     outputFile.println("Month\tInterest\tPrincipal\tBalance");
     outputFile.println("-----------------------------------"
                      + "--------------");

     // Display the amortization table.
     for (int month = 1; month <= getNumberOfPayments(); month++)
     {
        // Calculate monthly interest.
        monthlyInterest = interestRate / 12.0 * loanBalance;

        if (month != getNumberOfPayments())
        {
           // Calculate payment applied to principal
           principal = payment - monthlyInterest;
        }
        else    // This is the last month.
        {
           principal = loanBalance;
           payment = loanBalance + monthlyInterest;
        }

        // Calculate the new loan balance.
        loanBalance -= principal;

        // Display a line of data.
        outputFile.println(month
                     + "\t"
                     + dollar.format(monthlyInterest)
                     + "\t\t"
                     + dollar.format(principal)
                     + "\t\t"
                     + dollar.format(loanBalance));
     }

     // Close the file.
     outputFile.close();
  }

  //********************************************************
  // The getLoanAmount code returns the loan amount.
*
  //********************************************************

  public double getLoanAmount()
  {
     return loanAmount;
  }

  //********************************************************
  // The getInterestRate code returns the interest rate.
*
  //********************************************************

  public double getInterestRate()
  {
     return interestRate;
  }

  //********************************************************
  // The getLoanYears code returns the years of the loan.
*
  //********************************************************

  public int getLoanYears()
  {
     return loanYears;
  }
}
cp - 29 Jul 2006 12:51 GMT
Exception in thread "main" java.lang.NoSuchMethodError: main

Thats your error. You have forgotten to include the main method which all
java applications must have.

public static void main(String[] args){
//code
}
Patricia Shanahan - 29 Jul 2006 14:21 GMT
> Exception in thread "main" java.lang.NoSuchMethodError: main
>
[quoted text clipped - 4 lines]
>  //code
> }

Here's some all-nighter avoidance advice for the OP:

It is a good idea to write and test a VERY simple program first.

I do that whenever I'm starting to learn a new language, or switching to
a new development environment even for a familiar language.

For Java, the typical test program is:

public class HelloWorld{
  public static void main(String[] args){
   System.out.println("Hello, world");
  }
}

Don't attempt anything more ambitious until your HelloWorld program
compiles and runs.

In the early stages of learning a language, start each program out as
HelloWorld (or equivalent for the language), and make incremental
changes until it is the program you want. At each step, there should be
a working program, and a new one that incorporates one change.

Patricia
Greg R. Broderick - 29 Jul 2006 15:07 GMT
"Everett Arndt" <ecarndt@verizon.net> wrote in news:ReHyg.49$L31.31
@trndny06:

> C:\POS407\JavaPrograms\classes>java -classpath . EverettMortgagePayment_CR4
> Exception in thread "main" java.lang.NoSuchMethodError: main

In order to be directly runnable, a Java class must have a public static
method named "main".  You cannot directly specify a method on your command
line, just the class name in which main is located.

Cheers
GRB

Signature

---------------------------------------------------------------------
Greg R. Broderick            gregb.usenet200606@blackholio.dyndns.org

A. Top posters.
Q. What is the most annoying thing on Usenet?
---------------------------------------------------------------------



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.