We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,991 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Charge account program?

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!");

}
}
2
Contributors
1
Reply
19 Hours
Discussion Span
3 Years Ago
Last Updated
2
Views
dorotalp91
Newbie Poster
10 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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);
}
}
stultuske
Industrious Poster
4,374 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 24

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0612 seconds using 2.76MB