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.io.*;
import java.util.*;

public class CA2
{
public static void main (String args[])
{
    Scanner kbReader = new Scanner(System.in);
    System.out.print ("Enter your account number: ");
    int acctnum = kbReader.nextInt ();
    
    Scanner kb1Reader = new Scanner(System.in);
    System.out.print ("Please enter the first purchase you made this month: ");
    double p1 = kb1Reader.nextInt ();
    
    
  
    
    double total = ;
    double remain = 5000 - total;
    
    if(total<=5000)
    {
        System.out.println("You have" + remain + "dollars remaining in your account");
        
    }
        else 
        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;
    
    while(condition){
        /*
         * 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;
    }
    
    System.out.println("exit");
    System.exit(0);
}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.