Welcome to Dream.In.Code
Become a Java Expert!

Join 149,484 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,368 people online right now. Registration is fast and FREE... Join Now!




help with ArrayList and Hashmaps

 
Reply to this topicStart new topic

help with ArrayList and Hashmaps

bluej
17 Apr, 2007 - 07:24 AM
Post #1

New D.I.C Head
*

Joined: 17 Apr, 2007
Posts: 6


My Contributions

I cant seem to compile the code, if you can help please reply!
The code is



/** A CarDealer object represents a business that buys and resells used cars */
import java.util.ArrayList;
import java.util.HashMap;
public class CarDealer
{
private int dayNumber; // Day number from start of operation of business

// HashMap objects are used to provided easy lookup of cars using their registrations
// Each HashMap entry comprises a car registration as key, and the corresponding Car object
private HashMap<String, Car> prepStock; // To hold cars being prepared for sale
private HashMap<String, Car> saleStock; // To hold cars on sale
private int[] sales;
// An ArrayList field is needed, to hold the Sale objects created as sales are made

/** Constructor */
public CarDealer()
{
dayNumber = 1;

prepStock = new HashMap<String, Car>();
saleStock = new HashMap<String, Car>();
sales = new int[100];// to hold sales


}

public void advanceDate()
{
dayNumber++;
System.out.println("Day is now: " + dayNumber);
}

/** Note: Methods addCar, putOnSale, reducePrice and sellCar should print a confirmation
* message, or an error report if the operation cannot sensibly be performed.
*/

/** Method to be called when the dealer has acquired a car.
* A Car object representing the car is added to the preparation stock.
*/
public void addCar(String reg, String model, int paid)
{
System.out.println("addCar");
System.out.println("putOnSale");
System.out.println("reducePrice");
System.out.println("sellCar");

{
}

prepStock.add(new Car(reg, model, paid));


}

User is offlineProfile CardPM
+Quote Post

GWatt
RE: Help With ArrayList And Hashmaps
17 Apr, 2007 - 07:52 AM
Post #2

human inside
Group Icon

Joined: 1 Dec, 2005
Posts: 2,356



Thanked: 31 times
Dream Kudos: 500
My Contributions
Your problem is that the Hashap class's method to add new elemtns is put(K key, E element) You must use a string to index the Car Object in the map.
User is offlineProfile CardPM
+Quote Post

bluej
RE: Help With ArrayList And Hashmaps
18 Apr, 2007 - 01:36 AM
Post #3

New D.I.C Head
*

Joined: 17 Apr, 2007
Posts: 6


My Contributions
thanks for your help. seems to work now..
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 04:44PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month