Start New Discussion within our Software Development Community

Write a program that will determine whether a deparment store customer has exceeded the credit limit on a charge account(5000$). The customer gives you his/her account number, he/she has a beginning of the month balance, the program should total all the purchases by the customer for the month, total any credits and display either they are overdrawn or the balance they have remaining in their account.

im in beginner computer programming class :P so no hard stuff thanks! rly need help on this... i thought of doing a loop on the question do you have more purchases? and if they say yes they'll have to enter it, and over until they say no. how do i do that?

import java.util.*;

public class CA2
public static void main (String args[])
    Scanner kbReader = new Scanner(;
    System.out.print ("Enter your account number: ");
    int acctnum = kbReader.nextInt ();
    Scanner kb1Reader = new Scanner(;
    System.out.print ("Please enter the first purchase you made this month: ");
    double p1 = kb1Reader.nextInt ();
    double total = ;
    double remain = 5000 - total;
        System.out.println("You have" + remain + "dollars remaining in your account");
        System.out.println("Your account is overdrawn!");


by putting a loop in your code, which depends on the value of a boolean.
the startvalue is 'true', since you want the code to run at least once.
you just adjust the value of this boolean before you rerun the loop.
you could do this like this:

import javax.swing.JOptionPane;

public class Loopke {
public static void main(String args[]){
    boolean condition = true;
    int number = 1;
         * this will run as long as condition = true, so it will run at least once
         * since the original value of condition = true
        // enter the code that has to repeat
        System.out.println("ran the program: " + number + " times");
        number += 1;
        int result = JOptionPane.showConfirmDialog(null, "Enter more data?", "REPEAT",JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
        System.out.println("\tResult of the confirmation: " + result);
        // just test this a couple of times, so you see what result you get when pressing 'OK' and what result for 'Cancel'
        if ( result != 0 )
            condition = false;
This article has been dead for over six months. Start a new discussion instead.