473,804 Members | 3,941 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Beginner stuck on coursework with HASHMAP's!

2 New Member
This is the car dealership object relating to the coursework, there is also a separate object named car that i think i need to link to. The problem is on the addcar() method. Any help would be greatly appreciated.

/** A CarDealer object represents a business that buys and resells used cars */
import java.util.Array List;
import java.util.HashM ap;
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 ArrayList<Sale> Sold; // An ArrayList field is needed, to hold the Sale objects created as sales are made

/** Constructor */
public CarDealer()
{
dayNumber = 1;
Sold = new ArrayList<Sale> ();
prepStock = new HashMap<String, Car>();
saleStock = new HashMap<String, Car>();
}

public void advanceDate()
{
dayNumber++;
System.out.prin tln("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)
{ // Replace this comment with your code
prepStock.put(r eg, model, paid);
}

CAR OBJECT

/** An object of class Car represents a car that the dealer has bought
* and is preparing for sale, or has on sale, or has sold.
*/
public class Car
{
private String registration; // Unique UK vehicle identification
private String model; // What kind of car
private int paid; // How much the dealer paid
private int askingPrice; // "Windscreen " price

/** Constructor - assumes that when a Car object is created, the
* asking price is not decided and will be set later
*/
public Car(String reg, String model, int paid)
{
registration = reg;
this.model = model;
this.paid = paid;
}

public String getRegistration ()
{
return registration;
}

public String getModel()
{
return model;
}

public int getPaid()
{
return paid;
}

/** To set a car's asking price to a specified sum */
public void setAskingPrice( int price)
{
askingPrice = price;
}

public int getAskingPrice( )
{
return askingPrice;
}
}
Apr 16 '07 #1
6 2936
r035198x
13,262 MVP
This is the car dealership object relating to the coursework, there is also a separate object named car that i think i need to link to. The problem is on the addcar() method. Any help would be greatly appreciated.

/** A CarDealer object represents a business that buys and resells used cars */
import java.util.Array List;
import java.util.HashM ap;
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 ArrayList<Sale> Sold; // An ArrayList field is needed, to hold the Sale objects created as sales are made

/** Constructor */
public CarDealer()
{
dayNumber = 1;
Sold = new ArrayList<Sale> ();
prepStock = new HashMap<String, Car>();
saleStock = new HashMap<String, Car>();
}

public void advanceDate()
{
dayNumber++;
System.out.prin tln("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)
{ // Replace this comment with your code
prepStock.put(r eg, model, paid);
}

CAR OBJECT

/** An object of class Car represents a car that the dealer has bought
* and is preparing for sale, or has on sale, or has sold.
*/
public class Car
{
private String registration; // Unique UK vehicle identification
private String model; // What kind of car
private int paid; // How much the dealer paid
private int askingPrice; // "Windscreen " price

/** Constructor - assumes that when a Car object is created, the
* asking price is not decided and will be set later
*/
public Car(String reg, String model, int paid)
{
registration = reg;
this.model = model;
this.paid = paid;
}

public String getRegistration ()
{
return registration;
}

public String getModel()
{
return model;
}

public int getPaid()
{
return paid;
}

/** To set a car's asking price to a specified sum */
public void setAskingPrice( int price)
{
askingPrice = price;
}

public int getAskingPrice( )
{
return askingPrice;
}
}
1.) Use code tags next time when posting code.
2.)What problems are you having with the addCar method and what ideas do you have for it?
Apr 17 '07 #2
JosAH
11,448 Recognized Expert MVP
Expand|Select|Wrap|Line Numbers
  1. public void addCar(String reg, String model, int paid)
  2.     { // Replace this comment with your code
  3.        prepStock.put(reg, model, paid);
  4.     }
Your HashMaps take a String (the registration code for the car) and a Car.
Your method supplies you with the registration code, but not with a Car object.
You have to create a new Car first given the other parameter values.

kind regards,

Jos
Apr 17 '07 #3
bumrag
2 New Member
Thankyou for your help guys, Ive tried to create a new Car object but at the moment all i seem to be doing is sitting here staring at a blank screen, Any help would be greatly APPRECIATED, i know i have to initialise a new Car object, i have tried using,

Car C = new Car();

However, it says it cannot find symbol constructor. Has anyone ideas of how to resolve this?

martin
Apr 17 '07 #4
JosAH
11,448 Recognized Expert MVP
Thankyou for your help guys, Ive tried to create a new Car object but at the moment all i seem to be doing is sitting here staring at a blank screen, Any help would be greatly APPRECIATED, i know i have to initialise a new Car object, i have tried using,

Car C = new Car();

However, it says it cannot find symbol constructor. Has anyone ideas of how to resolve this?

martin
But you wrote this constructor yourself didn't you?
Expand|Select|Wrap|Line Numbers
  1. public Car(String reg, String model, int paid)
As far as I can see it's the only constructor defined in your class. Hint: compare
its parameters to the parameters of the addCar( ... ) method.

kind regards,

Jos
Apr 18 '07 #5
r035198x
13,262 MVP
Thankyou for your help guys, Ive tried to create a new Car object but at the moment all i seem to be doing is sitting here staring at a blank screen, Any help would be greatly APPRECIATED, i know i have to initialise a new Car object, i have tried using,

Car C = new Car();

However, it says it cannot find symbol constructor. Has anyone ideas of how to resolve this?

martin
You create the Car using a constructor in the Car class. You do not have one that takes no arguments (Car()), so use the one you have. You can read this for more details on constructors.
Apr 18 '07 #6
sateesht
41 New Member
As your Car class don't have a no argument Constructor, so by using this statement Car c=new Car(), obviously you'll get the Compilation Error, so you better to Create the Car Object by using Constructor you have i.e. a three argument constructor.
Apr 19 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
27911
by: dougjrs | last post by:
I have a HashMap that is storing form data that will later be inserted into a database. I have been able to create the HashMap just fine, but I wanted to be able to take my HashMap and just "dump" it out to the screen to make sure that everything is working as I expect. (It was really to easy to code so I think that I may be mising something). This is a piece of the code where I am updating the HashMap: if ( map.containsKey(temp)) {...
1
16805
by: Christian Gollwitzer | last post by:
Hi, I'm trying to loop over the elements in a hashmap of the STL-implementation by SGI. The point is, that because the key/value pair is stored as std::pair in the COntainer, the code becomes very ugly and unreadable soon. I'm aware that there exists the for_each-template, but this doesn't make the code any better because the body of the for-loop must then live in an extra function (consider two nested loops). Now I tried to mimic the...
4
5768
by: David | last post by:
Hi, I have created the following HashMap class. class HashMap: public hash_map<string, string, HashString, HashStringCompare> { public: HashMap(): hash_map<string, string, HashString, HashStringCompare>() {} };
2
10772
by: xor | last post by:
I'm doing up a school project using java, and am a little new to it (I've worked with other languages for years though). I've seen code posted by the instructor using HashMap like this... public HashMap<Position, Integer> boardNumbers; .... and ... HashMap<Integer, Integer> allNumbers = new HashMap<Integer, Integer>();
1
1568
by: m2kamp | last post by:
Working on a project for my class and spent too long searching around on the internet trying to find the right answer... Basically its a simple vending machine program using a hashmap. So i got this so far... public void runSimulator() { SoftDrink softdrink1 = new SoftDrink("A1","Coke",1.25); SoftDrink softdrink2 = new SoftDrink("A2","Pepsi",1.25);
4
1945
by: panos100m | last post by:
Hi these are the conents of my hashmap printing out the entrySet. entrySet1: OrderDate=10/30/2007, entrySet2: Level_0={Item_0={ItemTotal= 3.99, ItemName=test® in, ShipDate=10/31/2007, ItemPrice= 3.99, ItemNumber=8504, ItemQuantity=1}, ShipMethodID=75, ItemCount=1, Items_StatusID=2, Items_Status=Shipped, ShipMethod=, Tracking_TrackingNumber=, ShippingLevelID=1} entrySet3: Outcome={ReturnCode=0, ReturnMessage}
15
5678
by: lbrtchx | last post by:
Hi, ~ I have found myself in need of some code resembling a Hashmap ~ This is easily done in Java this way: ~ import java.util.*; // __ public class JMith00Test{
3
5408
dlite922
by: dlite922 | last post by:
I could have this done in php in three lines of code but in Java here's what I need to do: English Looping through list of words I call a function that returns a HashSet of movie titles that contain that particular word. I want to insert these titles into a HashMap with their value being a counter of how many times this title occured. (if two words return the same title, that title's value (counter) would be 2) Relative Code:
1
5625
by: evelina | last post by:
Hello, I need help. I have the following hashmap: HashMap<HashMap<Dimension, Integer>, String> mapList = new HashMap<HashMap<Dimension, Integer>, String>(); I want to extract Dimesion from the key, where the Integer is "1", and String from the value. How could I iterate it? I wrote that, but it doesn't work at the way I expected: HashMap<Dimension, String> singleValues = new HashMap<Dimension, String>();
0
9584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10337
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10082
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9160
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7622
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3822
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.