Java Exercise

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dave128
    New Member
    • Oct 2006
    • 6

    #1

    Java Exercise

    Hi, I have an exercise I need to do for Java. I am not sure how to start this program. Can somebody help me get started on this problem? Thanks in advance for your help. The problem is as follows:
    Develop a Java application that will determine 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.
    e) allowed credit limit.

    The program should input all these facts as integers, calculate the new balance(= beginning balance + charges - credits), display the new balance and determine whether the new balance exceeds the customer's credit limit. For those customers whose credit limit is exceeded, the program should display the message "Credit limit exceeded"
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by Dave128
    Hi, I have an exercise I need to do for Java. I am not sure how to start this program. Can somebody help me get started on this problem? Thanks in advance for your help. The problem is as follows:
    Develop a Java application that will determine 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.
    e) allowed credit limit.

    The program should input all these facts as integers, calculate the new balance(= beginning balance + charges - credits), display the new balance and determine whether the new balance exceeds the customer's credit limit. For those customers whose credit limit is exceeded, the program should display the message "Credit limit exceeded"
    Start by working on how to get the input and store in conveniently.

    Comment

    • Dave128
      New Member
      • Oct 2006
      • 6

      #3
      Here is code I started but I am getting errors. Can anybody help me get this problem corrected?

      [/CODE]
      import java.util.Scann er;

      public class CreditCheck
      {
      Scanner input = new Scanner( System.in );
      // define instance variable
      int acctNo = 0;
      double shopinitA = 0.0;// initial balance
      double shopcharges = 0.0; // charges applied to user's acct
      double shopcredits = 0.0; // credits applied to user's acct
      double shopcreditlimit = 0.0; // user's acct limit
      double newbal = 0.0; //user's calculated balance
      double positivecredit = 0.0; // money left to spend
      double negativecredit = 0.0; // amount of money overdrawn
      String msg = "";

      public CreditCheck()
      {
      }

      //acct number based on user's input
      public void setAccountNumbe r (int acctNo)
      {
      acctNo = acctNo;
      }

      //method for initial balance on user's input
      public void setInitialBalan ce (double initA)
      {
      shopinitA = initA;
      }

      // method to establish total charges based on user's input
      public void setTotalCharges (double charges)
      {
      shopcharges = charges;
      }

      // method establishes total credits based on user's input
      public void setTotalCredits (double credits)
      {
      shopcredits = credits;
      }

      //method establishes total credit based on user's input
      public void setCreditLimit (double creditLimit)
      {
      shopcreditlimit = creditLimit;
      }


      // balance calculation and results
      public void showResult()
      {
      //calculate balance
      newbal = (shopinitA + shopcharges)- shopcredits;
      positivecredit = shopcreditlimit - newbal;
      negativecredit = shopcreditlimit - (newbal);



      //user balance options
      if ( newbal < 0 )
      System.out.prin t( "Your balance is $" , newbal(positive credit) +"to spend.");

      else if ( positivecredit >=0 )
      System.out.prin t( "Your balance is $" , newbal + "\n and you still have $");

      else
      System.out.prin tln ("Credit Limit exceeded" );
      }

      }

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by Dave128
        Here is code I started but I am getting errors. Can anybody help me get this problem corrected?

        [/CODE]
        import java.util.Scann er;

        public class CreditCheck
        {
        Scanner input = new Scanner( System.in );
        // define instance variable
        int acctNo = 0;
        double shopinitA = 0.0;// initial balance
        double shopcharges = 0.0; // charges applied to user's acct
        double shopcredits = 0.0; // credits applied to user's acct
        double shopcreditlimit = 0.0; // user's acct limit
        double newbal = 0.0; //user's calculated balance
        double positivecredit = 0.0; // money left to spend
        double negativecredit = 0.0; // amount of money overdrawn
        String msg = "";

        public CreditCheck()
        {
        }

        //acct number based on user's input
        public void setAccountNumbe r (int acctNo)
        {
        acctNo = acctNo;
        }

        //method for initial balance on user's input
        public void setInitialBalan ce (double initA)
        {
        shopinitA = initA;
        }

        // method to establish total charges based on user's input
        public void setTotalCharges (double charges)
        {
        shopcharges = charges;
        }

        // method establishes total credits based on user's input
        public void setTotalCredits (double credits)
        {
        shopcredits = credits;
        }

        //method establishes total credit based on user's input
        public void setCreditLimit (double creditLimit)
        {
        shopcreditlimit = creditLimit;
        }


        // balance calculation and results
        public void showResult()
        {
        //calculate balance
        newbal = (shopinitA + shopcharges)- shopcredits;
        positivecredit = shopcreditlimit - newbal;
        negativecredit = shopcreditlimit - (newbal);



        //user balance options
        if ( newbal < 0 )
        System.out.prin t( "Your balance is $" , newbal(positive credit) +"to spend.");

        else if ( positivecredit >=0 )
        System.out.prin t( "Your balance is $" , newbal + "\n and you still have $");

        else
        System.out.prin tln ("Credit Limit exceeded" );
        }

        }
        The errors were caused by the incorrect print statements. I suppose you are going to write the main method for testing the logic of your solution?



        Code:
        import java.util.Scanner;
        
        public class CreditCheck
        {
        Scanner input = new Scanner( System.in );
        // define instance variable
        int acctNo = 0;
        double shopinitA = 0.0;// initial balance
        double shopcharges = 0.0; // charges applied to user's acct
        double shopcredits = 0.0; // credits applied to user's acct
        double shopcreditlimit = 0.0; // user's acct limit
        double newbal = 0.0; //user's calculated balance
        double positivecredit = 0.0; // money left to spend
        double negativecredit = 0.0; // amount of money overdrawn
        String msg = "";
        
        public CreditCheck()
        {
        }
        
        //acct number based on user's input
        public void setAccountNumber (int acctNo)
        {
        acctNo = acctNo;
        }
        
        //method for initial balance on user's input
        public void setInitialBalance (double initA)
        {
        shopinitA = initA;
        }
        
        // method to establish total charges based on user's input
        public void setTotalCharges (double charges)
        {
        shopcharges = charges;
        }
        
        // method establishes total credits based on user's input
        public void setTotalCredits (double credits)
        {
        shopcredits = credits;
        }
        
        //method establishes total credit based on user's input
        public void setCreditLimit (double creditLimit)
        {
        shopcreditlimit = creditLimit;
        }
        
        
        // balance calculation and results
        public void showResult()
        {
        //calculate balance
        newbal = (shopinitA + shopcharges)- shopcredits;
        positivecredit = shopcreditlimit - newbal;
        negativecredit = shopcreditlimit - (newbal);
        
        
        
        //user balance options
        if ( newbal < 0 )
        System.out.print( "Your balance is $" + newbal +"(positivecredit)to spend.");
        
        else if ( positivecredit >=0 )
        System.out.print( "Your balance is $"+ newbal + "\n and you still have $");
        
        else
        System.out.println ("Credit Limit exceeded" );
        }
        
        }

        Comment

        Working...