Solved

No MAIN METHOD -- Java

Posted on 2011-03-15
5
1,318 Views
Last Modified: 2012-05-11
Can someone please help, I keep getting the error: no main method.

This is what its supposed to do:
Develop a Java application that determines whether any of several department store customers has exceeded the credit limit on a charge account. For each customer, the following facts are available:

A) account number;
B) balance at the beginning of the month;
C) total of all items charged by the customer this month;
D) total of all credits applied to the customer's account this month; and
E) allowed credit limit.  

The program should input all of these facts as integers, then calculate the new balance (= beginning balance + charges - credits), display the new balance, and determine whether the new balance exceeds the customers credit limit. For those customers whose credit limit is exceeded, the program should display the message "Credit Limit Exceeded." creditcheck.java
0
Comment
Question by:anshealth
5 Comments
 
LVL 26

Expert Comment

by:ksivananth
Comment Utility
add this method to your code,

public static void main( String[] args ){
  new CreditCheck().showResult() ;
}
0
 
LVL 5

Expert Comment

by:KGNickl
Comment Utility
Your program is missing a main method. You need atleast 1 main method for a program that is put inside a class. You would put that inside your credit check class. When the program runs it goes to the main first. So inside your main you could define variables and call one or more of your functions. There are also other syntax problems in your code such as missing curley brackets. Since, its obviously an assignment I'm not going to post the answer, only direction. Also, I suggest you start small and build as your go. If your write a good amount of the code and have errors it can be hard to figure out where your going wrong. Below is a very basic example of a running program. Might help you might not....

public class CreditCheck{      
      
      public static void main(String args[])
      {
            System.out.print(speak());
      }
      
      
    public static String speak() {                                                      
                String duck = "Duck!";
                return duck;
    }          
}
0
 
LVL 23

Accepted Solution

by:
wdosanjos earned 250 total points
Comment Utility
Try this.  There were some other issues with the code that I fix, so it can compile.  But the main issue was resolved by putting Scanner input = new Scanner( System.in ); in the main method.
import java.util.Scanner;

public class CreditCheck
{
    public static void main(String[] args)
    {
        //calls in java.util to get user input
        Scanner input = new Scanner( System.in );
    }

    // defines variables
    //account
    int acctNum = 0;
    //balance
    double balanceA = 0.0;
    //charges
    double shoppingcharges = 0.0;
    //credits
    double shoppingcredits = 0.0;
    //account limit
    double creditlimit = 0.0;
    //new balance
    double newbalance = 0.0;
    //credit amount
    double positivebalance = 0.0;
    //negative balace
    double negativebalance = 0.0;

    String msg = "";

    public CreditCheck()
    {

    }

    //input account number
    public void setAccountNumber (int acctNum)
    {
        acctNum = acctNum;
    }

    //initial balance
    public void setInitialBalance (double balanceB)
    {
        balanceA = balanceB;
    }

    // set total charges
    public void setTotalCharges (double charges)
    {
        shoppingcharges = charges;
    }

    //new credit limit
    public void setTotalCredits (double credits)
    {
        shoppingcredits = credits;
    }

    //credit limit
    public void setCreditLimit (double creditLimits)
    {
        creditlimit = creditLimits;
    }

    //overall balance
    public void showResult()
    {
        //balance
        newbalance = (balanceA + shoppingcharges)- shoppingcredits;
        positivebalance = creditlimit -  newbalance;
        negativebalance = creditlimit - (newbalance);



        //user balance options
        if ( newbalance < 0 )
            System.out.print( "Balance is $" + newbalance +" with remaining credit.");

        else if ( positivebalance >=0 ) //( positivecredit >=0 )
          System.out.print( "Balance is $" + newbalance + "with remaining credit");

        else
          System.out.println ("Credit limit has been exceeded." );
    }

}

Open in new window


But the code as is, does not process the user input.
0
 
LVL 23

Expert Comment

by:wdosanjos
Comment Utility
Sorry, I meant to say:  "There were some other issues with the code that I fixed, so it can compile."
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 250 total points
Comment Utility
This is based on code of wdosanjos, but it not only compiles
but aslao asks for 8 numbers separated by commas,
and then calculates sopmething

import java.util.Scanner;

public class CreditCheck
{
    public static void main(String[] args)
    {
        //calls in java.util to get user input
        System.out.println("Enter acctNum, balanceA, shopCharges, shopCred, credLim, newBalance, psitBalance, negatBalance (separate by commas): ");
        Scanner input = new Scanner( System.in );
        (new CreditCheck(input.next())).showResult();
    }

    // defines variables
    //account
    int acctNum = 0;
    //balance
    double balanceA = 0.0;
    //charges
    double shoppingcharges = 0.0;
    //credits
    double shoppingcredits = 0.0;
    //account limit
    double creditlimit = 0.0;
    //new balance
    double newbalance = 0.0;
    //credit amount
    double positivebalance = 0.0;
    //negative balace
    double negativebalance = 0.0;

    String msg = "";

    public CreditCheck(String s)

    {
        String [] parms = s.split(",");
        acctNum = Integer.parseInt(parms[0]);
        balanceA = Double.parseDouble(parms[1]);
               shoppingcharges = Double.parseDouble(parms[2]);
               shoppingcredits  = Double.parseDouble(parms[3]);
              creditlimit = Double.parseDouble(parms[4]);
              newbalance  = Double.parseDouble(parms[5]);
              positivebalance= Double.parseDouble(parms[6]);
               negativebalance = Double.parseDouble(parms[7]);


    }

    //input account number
    public void setAccountNumber (int acctNum)
    {
        acctNum = acctNum;
    }

    //initial balance
    public void setInitialBalance (double balanceB)
    {
        balanceA = balanceB;
    }

    // set total charges
    public void setTotalCharges (double charges)
    {
        shoppingcharges = charges;
    }

    //new credit limit
    public void setTotalCredits (double credits)
    {
        shoppingcredits = credits;
    }

    //credit limit
    public void setCreditLimit (double creditLimits)
    {
        creditlimit = creditLimits;
    }

    //overall balance
    public void showResult()
    {
        //balance
        newbalance = (balanceA + shoppingcharges)- shoppingcredits;
        positivebalance = creditlimit -  newbalance;
        negativebalance = creditlimit - (newbalance);



        //user balance options
        if ( newbalance < 0 )
            System.out.print( "Balance is $" + newbalance +" with remaining credit.");

        else if ( positivebalance >=0 ) //( positivecredit >=0 )
          System.out.print( "Balance is $" + newbalance + "with remaining credit");

        else
          System.out.println ("Credit limit has been exceeded." );
    }

}

Open in new window



Results:



Enter acctNum, balanceA, shopCharges, shopCred, credLim, newBalance, psitBalance, negatBalance (separate by commas): 
23,500,200,300,500,500,350,100
Balance is $400.0with remaining credit
Process finished with exit code 0

Open in new window


0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now