View Single Post
  #1 (permalink)  
Old 01-28-2008, 10:06 AM
otoro_java otoro_java is offline
Member
 
Join Date: Jan 2008
Posts: 5
otoro_java is on a distinguished road
HashMap with objects
Hi,

Trying to learn HashMap and have lots of questions, so please excuse my ignorance.

I have two classes:
HashMapDemo.class
Account.class

Program is to do simple arithmetic, and write/read from file later on.

So far this is what I have:

Code:
//Account class public class Account{ String customerAccount; String customerName; double customerBalance; public Account(String customerAccount, String customerName,double customerBalance){ //Constructor this.customerAccount = customerAccount; this.customerName = customerName; this.customerBalance = customerBalance; } public String toString() { String output = customerAccount + " " + customerName + " " + customerBalance; return output; } public double doDeposit(double newDeposit){ //Purpose is to get the existing customer balance and add the new amount through input from joptionpane Double output = customerBalance + newDeposit; return output; }
Code:
//HashMapDemo class import java.util.*; public class HashMapDemo { int accountBalance = 100; public static void main(String[] args) { HashMap hm = new HashMap(); Account anAcct1 = new Account("12-12-12", "Joe", 600); Account anAcct2 = new Account("45-45-45", "Jane", 500); //Account methods Account methodAccount = new Account(); hm.put("100", anAcct1); hm.put("200", anAcct2); System.out.println("Account number : " + hm); System.out.println("\nMake a new dposit to account"); //This is where I am stuck System.out.println(hm.get("100")+methodAccount.doDeposit(300)); // Function toString() System.out.println("Account number : " + hm); } }
Thanks in advance
Reply With Quote
Sponsored Links