Solved

No MAIN METHOD -- Java

Posted on 2011-03-15
5
1,341 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
ID: 35142162
add this method to your code,

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

Expert Comment

by:KGNickl
ID: 35142183
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
ID: 35142238
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
ID: 35142258
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
ID: 35142691
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
topping2 challenge 13 89
tomcat administrtor 12 46
Desingning Refactoring existing code 2 24
CSV file parsing thru Java 13 26
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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 …

813 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

14 Experts available now in Live!

Get 1:1 Help Now