Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6678815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:17:12+00:00 2026-05-26T04:17:12+00:00

I’ve created two classes. When I choose to retrieve the deposit or withdraw historical

  • 0

I’ve created two classes. When I choose to retrieve the deposit or withdraw historical I can only get the dates, the values that appear are only the last one deposited.
I do not understand why it is showing only the dates.

This is the first class:

import javax.swing.*;
import java.text.*;
import java.util.*;

public class AtmTime{
private String date;
private double cash, funds;
private DecimalFormat dfmt = new DecimalFormat("$,###,##0.00");

public void addFunds(double moneyIn){
    funds = funds + moneyIn;
}
public void withdrawFunds(double moneyOut){
    while(moneyOut > funds){
        JOptionPane.showMessageDialog(null,"You have tried to withdraw " + dfmt.format(moneyOut), "Insufficient funds: " + dfmt.format(funds), JOptionPane.INFORMATION_MESSAGE);
        moneyOut = Double.parseDouble(JOptionPane.showInputDialog(null,"Try again ", "Withdraw", JOptionPane.INFORMATION_MESSAGE));
    }
    funds = funds - moneyOut;
}
public double getFunds(){
    return funds;
}
public double getCash(){
    return cash;
}
public String getDate(){
    DateFormat dfm = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    Date dates = new Date();
    return dfm.format(dates);
}
}

And this is the second one:

import javax.swing.*;
import java.text.*;
import java.util.*;

public class AtmTimeApp{
public static void main(String []args){
    int control = 0;
    String date;
    double cash = 0;
    DecimalFormat dfmt = new DecimalFormat("$,###,##0.00");
    List<AtmTime> atmListIn = new ArrayList<AtmTime>();
    List<AtmTime> atmListOut = new ArrayList<AtmTime>();
    AtmTime atm = new AtmTime();

    while(control !=6){
        control = Integer.parseInt(JOptionPane.showInputDialog(null,"1- Funds \n 2- Add money \n 3- Withdraw \n4- Deposit history \n5- Withdraw history \n6- Exit", "Choose an option below", JOptionPane.INFORMATION_MESSAGE));
        if(control == 2){
            date = atm.getDate();
            double moneyIn = Double.parseDouble(JOptionPane.showInputDialog(null,"Amount ", "Add Money", JOptionPane.INFORMATION_MESSAGE));
            atm.setDate(date);
            atm.addFunds(moneyIn);
            atmListIn.add(atm);
            JOptionPane.showMessageDialog(null,"Your new funds " + dfmt.format(atm.getFunds()), "On " + atm.getDate(), JOptionPane.INFORMATION_MESSAGE);
        }
        else if(control == 1){
                JOptionPane.showMessageDialog(null,"" + dfmt.format(atm.getFunds()), "Total in your account", JOptionPane.INFORMATION_MESSAGE);
        }
            else if(control == 3){
                date = atm.getDate();
                double moneyOut = Double.parseDouble(JOptionPane.showInputDialog(null,"Amount ", "Withdraw Money", JOptionPane.INFORMATION_MESSAGE));
                atm.withdrawFunds(moneyOut);
                atmListOut.add(atm);
                JOptionPane.showMessageDialog(null,"New funds " + dfmt.format(atm.getFunds()), "Operation Successful completed", JOptionPane.INFORMATION_MESSAGE);
            }
                else if (control == 4){
                        for (int i=0;i<atmListIn.size();i++){
                            atm = atmListIn.get(i);
                            JOptionPane.showMessageDialog(null,"Deposit of " + dfmt.format(atm.getCash()), "When " + atm.getDate(), JOptionPane.INFORMATION_MESSAGE);
                        }
                    }
                    else if (control == 5){
                        for (int i=0; i<atmListOut.size();i++){
                            atm = atmListOut.get(i);
                            JOptionPane.showMessageDialog(null,"Withdraw of " + dfmt.format(atm.getCash()), "When " + atm.getDate(), JOptionPane.INFORMATION_MESSAGE);
                        }
                    }
                else if(control !=1 && control !=2 && control !=3 && control !=4 && control !=5 && control !=6)
                    JOptionPane.showMessageDialog(null,"Please choose a valid option", "Invalid number", JOptionPane.ERROR_MESSAGE);
    }
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:17:13+00:00Added an answer on May 26, 2026 at 4:17 am

    The problem is you’re repeatedly adding references to the same object:

    List<AtmTime> atmListIn = new ArrayList<AtmTime>();
    List<AtmTime> atmListOut = new ArrayList<AtmTime>();
    AtmTime atm = new AtmTime();
    
    while(control !=6){
        control = Integer.parseInt(...);
        if(control == 2){
            date = atm.getDate();
            double moneyIn = Double.parseDouble(...);
            atm.setDate(date);
            atm.addFunds(moneyIn);
            atmListIn.add(atm);
    

    You should be creating a new object each time you want to add a record to the list, e.g.

    List<AtmTime> atmListIn = new ArrayList<AtmTime>();
    List<AtmTime> atmListOut = new ArrayList<AtmTime>();
    
    while(control != 6) {
        control = Integer.parseInt(...);
        if(control == 2) {
            date = atm.getDate();
            double moneyIn = Double.parseDouble(...);
            AtmTime atm = new AtmTime(date, moneyIn);
            atmListIn.add(atm);
    

    … and likewise elsewhere. Basically, get rid of that single atm variable declared outside the loop – you really want to be using a separate variable on each iteration, which will force you to either fetch an existing object to update/display, or create a new object to add.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.