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

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




help with some java questions

 
Reply to this topicStart new topic

help with some java questions

bluej
19 Apr, 2007 - 08:20 AM
Post #1

New D.I.C Head
*

Joined: 17 Apr, 2007
Posts: 6


My Contributions
hey can anyone help me with the question, ive tried everything but cannot compile them. any help will be appreciated.. heres the code. thanks


CODE
/** 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.put(reg, new Car(reg, model, paid));
    

   }
    
    /** Method to be called when a car is put on sale. The asking price must be specified.
     *  The Car object with the specified registration is moved to the sale stock.
     */
    public void putOnSale(String reg, int ask)
    {

        Car c = saleStock.get(reg);
        c.setAsk(c.getAsk());

    
    }
    
    /** Method to reduce the asking price of a car by a specified amount */
    public void reducePrice(String reg, int amount)
    {
        
        
      Car c = saleStock.get(reg);


    }
    
    /** Method to be called when a car has been sold. The price received must be specified.
     *  The Car object with the specified registration is removed from the sale stock
     *  and an appropriate Sale object created and added to the collection of sales.
     */
    public void sellCar(String reg, int received)
    {
        Car c = saleStock.get(reg);
        reg = reg + received;
        
        saleStock.remove(reg);
        

        
    }

    /** Method to print a report giving:
     *  - The number of cars sold so far
     *  - The total profit made on those sales
     *  - The average discount per sale.
     *  
     *  Notes:
     *  - The profit on a sale is the difference between the price obtained
     *    and the price the dealer paid for the car.
     *  - The discount on a sale is the difference between the asking price
     *    and the price obtained.
     */
    public void printOverallSummary()
    {
        // Replace this comment with your code
    }
    
    /** Method to print a report giving:
     *  - The number of cars currently in preparation
     *  - The number of cars currently for sale
     *  - The number of cars sold on the current day
     *  - The total amount received for those sales
     */
    public void printDaySummary()
    {
        System.out.println(prepStock.get("numCars"));
        System.out.println(saleStock.get("numCars"));
        if (dayNumber==dayNumber)
        {

        }
    }
      
    /** Method to print a report giving details of the single most profitable sale
     *  so far achieved.
     */
    public void showBestSale()
    {
        
    }
    
    /** Method to print a report giving details of every sale starting from a
     *  specified day and continuing up to another specified day.
     */
    public void listDaySales(int dayFrom, int dayTo)
    {
        
        while(dayFrom < dayTo) {


        }
    }
  
    /** Method to print a report giving details of all the sales achieved for a
     *  specified model.
     */
    public void listModelSales(String model)
    {  
        if(reg.equals(model))
        System.out.prinltn("sales");
        index++;
    }

}


edit: added [code] tags ~ jayman9

This post has been edited by jayman9: 19 Apr, 2007 - 08:57 AM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Help With Some Java Questions
19 Apr, 2007 - 08:56 AM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,302



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Post the error messages that you are receiving when you compile your code. It will make it much easier to help you.
User is online!Profile CardPM
+Quote Post

bluej
RE: Help With Some Java Questions
19 Apr, 2007 - 09:17 AM
Post #3

New D.I.C Head
*

Joined: 17 Apr, 2007
Posts: 6


My Contributions

there are quite a few error messages mostly cannot find variable car, variable reg, variable index..
i am not sure what im doing whether i am using the right methods.. also the questions are very hard to understand.
User is offlineProfile CardPM
+Quote Post

rfencl
RE: Help With Some Java Questions
19 Apr, 2007 - 09:32 AM
Post #4

New D.I.C Head
*

Joined: 18 Apr, 2007
Posts: 7


My Contributions
You need to supply a car class. I've fixed up the code and have gotten it to compile. But I've not tried in anyway to deal with getting this to work.
Remember to compile each time you add a small amount of code. I like to get a basic program working and add features incrementally rather than trying to get the whole program written at once. I hope this helps.

CODE

/** 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.put(reg, new Car(reg, model, paid));


   }

    /** Method to be called when a car is put on sale. The asking price must be specified.
     *  The Car object with the specified registration is moved to the sale stock.
     */
    public void putOnSale(String reg, int ask)
    {

        Car c = saleStock.get(reg);
        c.setAsk(c.getAsk());


    }

    /** Method to reduce the asking price of a car by a specified amount */
    public void reducePrice(String reg, int amount)
    {


      Car c = saleStock.get(reg);


    }

    /** Method to be called when a car has been sold. The price received must be specified.
     *  The Car object with the specified registration is removed from the sale stock
     *  and an appropriate Sale object created and added to the collection of sales.
     */
    public void sellCar(String reg, int received)
    {
        Car c = saleStock.get(reg);
        reg = reg + received;

        saleStock.remove(reg);



    }

    /** Method to print a report giving:
     *  - The number of cars sold so far
     *  - The total profit made on those sales
     *  - The average discount per sale.
     *
     *  Notes:
     *  - The profit on a sale is the difference between the price obtained
     *    and the price the dealer paid for the car.
     *  - The discount on a sale is the difference between the asking price
     *    and the price obtained.
     */
    public void printOverallSummary()
    {
        // Replace this comment with your code
    }

    /** Method to print a report giving:
     *  - The number of cars currently in preparation
     *  - The number of cars currently for sale
     *  - The number of cars sold on the current day
     *  - The total amount received for those sales
     */
    public void printDaySummary()
    {
        System.out.println(prepStock.get("numCars"));
        System.out.println(saleStock.get("numCars"));
        if (dayNumber==dayNumber)
        {

        }
    }

    /** Method to print a report giving details of the single most profitable sale
     *  so far achieved.
     */
    public void showBestSale()
    {

    }

    /** Method to print a report giving details of every sale starting from a
     *  specified day and continuing up to another specified day.
     */
    public void listDaySales(int dayFrom, int dayTo)
    {

        while(dayFrom < dayTo) {


        }
    }

    /** Method to print a report giving details of all the sales achieved for a
     *  specified model.
     */
    public void listModelSales(String reg, String model)
    {
        if(reg.equals(model))
        System.out.println("sales");
        //index++;
    }

    public class Car
    {
        double ask = 0.0;

        public Car(String reg, String model, int paid)
        {}

        void setAsk(double d)
        {
            ask = d;
        }

        double getAsk()
        {
            return ask;
        }

    }

}

User is offlineProfile CardPM
+Quote Post

bluej
RE: Help With Some Java Questions
19 Apr, 2007 - 09:36 AM
Post #5

New D.I.C Head
*

Joined: 17 Apr, 2007
Posts: 6


My Contributions
thanks for your help!
User is offlineProfile CardPM
+Quote Post

bluej
RE: Help With Some Java Questions
19 Apr, 2007 - 09:42 AM
Post #6

New D.I.C Head
*

Joined: 17 Apr, 2007
Posts: 6


My Contributions
ive done the car class. that compiled. dont know if i did it right or not, but it seems to work.

/** 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;
}
}


also got the class sales to work, just confused at the questions of the class car dealer, have no idea how to print all the data that is required

/** A Sale object will hold the available information about
* the sale of a particular car
*/
public class Sale
{

private String carSold;
private double dayOfSale;
private int price;

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


public String getCarSold()
{
return carSold;
}

public double getDayOfSale()
{
return dayOfSale; // day of the car sale
}

public int getPrice()
{
return price;
}
}
User is offlineProfile CardPM
+Quote Post

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

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