assignment please help


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 11 of 11

Thread: assignment please help

  1. #1
    Join Date
    May 2006
    Posts
    7

    assignment please help

    hi I have wrote all my classes without error but i'm not getting the expected out please help this is what i'm getting

    ***** The shop has the following items *****
    There are 0 of Jaws - VHS in stock Running time is 95 minutes.
    There are 8 of Jaws in stock Running time is 95 minutes. Number of discs is set is 1 Has the movie got additional features false
    There are 0 of Shrek 2 in stock Running time is 102 minutes. Number of discs is set is 1 Has the movie got additional features true
    There are 6 of NRL in stock Game platform is PS2 amd the Maximum number of players is 2
    There are 11 of Doom in stock Game platform is PC amd the Maximum number of players is 2
    There are 3 of AFL in stock Game platform is PS2 amd the Maximum number of players is 1
    There are 0 of Jaws - VHS in stock Running time is 95 minutes.
    There are 8 of Jaws in stock Running time is 95 minutes. Number of discs is set is 1 Has the movie got additional features false
    There are 0 of Shrek 2 in stock Running time is 102 minutes. Number of discs is set is 1 Has the movie got additional features true
    There are 6 of NRL in stock Game platform is PS2 amd the Maximum number of players is 2
    There are 11 of Doom in stock Game platform is PC amd the Maximum number of players is 2
    There are 3 of AFL in stock Game platform is PS2 amd the Maximum number of players is 1

    ***** The library has the following games for PS2 *****
    There are 6 of NRL in stock Game platform is PS2 amd the Maximum number of players is 2
    There are 3 of AFL in stock Game platform is PS2 amd the Maximum number of players is 1

    ***** The total number of sales from the library is $71.7 *****
    ***** The total items sold from the library is 3 *****

    the expected is

    *** The wholesaler contains the following items: ***
    Movie Jaws - VHS price $12.0 stock:0 sold:0 Run-Time:95 mins
    DVD Jaws price $12.0 stock:4 sold:6 Run-Time:95 mins no special features
    DVD Shrek 2 price $14.95 stock:0 sold:0 Run-Time:102 mins special features
    Game NRL price $29.5 stock:3 sold:2 Max Players:2 Platform:PS2
    Game Doom price $30.2 stock:9 sold:1 Max Players:2 Platform:PC
    Game AFL price $29.95 stock:2 sold:0 Max Players:1 Platform:PS2

    *** The wholesaler has low stock (less than 3) of the following items: ***
    Movie Jaws - VHS price $12.0 stock:0 sold:0 Run-Time:95 mins
    DVD Shrek 2 price $14.95 stock:0 sold:0 Run-Time:102 mins special features
    Game AFL price $29.95 stock:2 sold:0 Max Players:1 Platform:PS2

    *** The wholesaler has the following games for PS2: ***
    Game NRL price $29.5 stock:3 sold:2 Max Players:2 Platform:PS2
    Game AFL price $29.95 stock:2 sold:0 Max Players:1 Platform:PS2

    *** The wholesaler has sold 9 items for a total of $161.2 ***

    *** Error - item AFL is already in the stock list ***

    *** Error - there are not 5 copies of Jaws in stock ***

    i thinking i need to make changes in my main wholesaler class which is

    public class Wholesaler
    {
    private Vector<Item> mItems = new Vector<Item>();

    public boolean addItem(Item newItem)
    {
    mItems.add(newItem);
    return true;
    }

    public boolean findItem(String searchName)
    {
    boolean found=false;
    for (Item nextItem : mItems)
    {
    if (nextItem.getName().equalsIgnoreCase
    (searchName))
    found = true;
    else
    found = false;
    }
    return found;
    }


    public void listItems()
    {
    System.out.println("***** The shop has the following items ***** ");
    for (Item nextItem : mItems)
    {
    System.out.println(nextItem);
    }
    }

    public void listlowStock(int threshhold)
    {
    int total = 0;
    for (Item nextItem : mItems)
    {
    System.out.println(nextItem);
    if (nextItem.getNuminStock() < threshhold);
    }

    }

    public void listGamesbyPlatform(String platform)
    {
    System.out.println ();
    System.out.println("***** The library has the following games for " + platform + " *****");
    for (Item nextItem : mItems)
    {
    if (nextItem instanceof Game)
    {
    if (((Game)nextItem).getPlatform().equals(platform))
    System.out.println(nextItem);
    }
    }
    }

    public void calcTotalSales()
    {
    int totalSold = 0;
    double totalSales = 0.0;
    for (Item nextItem : mItems)
    {
    totalSold += nextItem.getNumSold();
    totalSales += nextItem.getNumSold()*nextItem.getPrice();
    }
    System.out.println ();
    System.out.println("***** The total number of sales from the library is $" + totalSales + " *****");
    System.out.println("***** The total items sold from the library is " + totalSold + " *****");
    }

    }


    any help would be so helpful
    thanks
    alak

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Why have you identified THIS class as being the class with a problem?

    Looks to me that your "toString" method for your Item class (or is it your Game class?) does not agree with the format called for in the specifications.

    It also appears that somewhere in your code you are invoking either a constructor twice or adding information twice. I find it interesting that you are also calling "toString" twice...

  3. #3
    Join Date
    May 2006
    Posts
    7

    not sure

    well i fixed the display prob by putting in string thanks. that i'm not really sure of the other stuff i not sure if thats the rigth class or not i took a guess i have attached my bluej file if you can see anything it would be great

    big thanks alak
    Attached Files Attached Files

  4. #4
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Did you write all of the code you uploaded or was any of it provided to you for your implementation of the "wholesaler" class?

    Your code does not distinguish among the types of inventory - you have the three classes (movie, dvd, game) but your wholesaler class does not use them. If you wrote these classes, I suggest that you either implement an Item interface or create an abstract Item class which is extended by each of the inventory types.

    Set up your toString methods to output data as "expected". You don't have some of the data fields called for in the "expected" output.
    Last edited by nspils; 05-22-2006 at 12:50 AM.

  5. #5
    Join Date
    May 2006
    Posts
    7
    yes i did write it all (except the test)

    i do have a abstract item

    i don't know what you mean by expected???

  6. #6
    Join Date
    May 2006
    Posts
    7
    yes i did write it all (except the test)

    i do have a abstract item

    i don't know what you mean by expected???

  7. #7
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    OK ... I asked the question because I did not know what kind of flexibility you had in your project.

    I guess I missed the use of an abstract class. [I did look at your Abst1(?) code but I didn't see where you used it].

    I noticed that you were deriving DVD from Movie. Was this a requirement for the project (had to have at least one class derived from another)? I can understand some of the appeal of this structure, but I don't think I would do it this way.

    Regarding my use of the word "expected": You included a section in your first posting which you had introduced as "the expected is ...". I interpreted that as being sample output, or the "test case" which you had been given to demonstrate what your program's output should look like. Based on this interpretation I suggested that you structure your output to produce the text and values contained in the "expected" case.

    If you are using Java 5, your use of Generics will allow you to have the compiler check the type of the objects you are adding to your collection as each object is added, so that when you deal with the elements of the collection you are assured that you know the "type" of the object you'll be modifying or viewing when you later use the collection. For you, then, you could make your Vector a Vector<Item> - a vector of Item objects, and only Item objects.

    SO - how do you make all of your objects of type Item? Especially when you have decided to have three kinds of "Items" (movie, dvd, game)? You can write an Item interface, provide that interface with fields which are common to all Items (name, price, items in stock, items sold), declare some methods which are common to all (toString, setName, getName, setStock, getStock, getSold). Then, you have your Movie, DVD, and Game classes implement that Item interface, including the definition of the various "Item" methods. You have created what is, in effect, an ADT of "Item", and you can add objects of type Item to your Vector, you can call an Item's toString method, and the object will respond with the object's "real" toString method - one for DVD, for Movie, or Game depending on what kind of Item it is ... The objects will be "Items", and they will be "Movie" or "DVD" or "Game", too.

    The alternative is to have Item be a base class, then you derive the three kinds of Items from that base class, defining the unique fields and methods in the children classes.

  8. #8
    Join Date
    May 2006
    Posts
    7

    restrictions

    oh i see what you meant by expected. yeah i have to have those class off the abstract class item as per the diagram in the .doc file i posted i have to have the same which makes things hard. and i don't know if i'm working with java 55 i'm guessing not .

    is there anything you can help me with the maths errors it it becase my item in stock is not correct

    thanks kala

  9. #9
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Here are some modifications of your addStock and sellStock methods

    Code:
      
        // increase stock on hand by amount
        public void receiveStock(int amount)
        {
            mNuminStock += amount;
        }
        
        //reduce stock on hand by amount sold
        public boolean sellCopies(int amount)
        {
           if(mNuminStock >= amount) 
           {
               mNumSold -= amount;
               return true;
           }
           else return false;
        }

  10. #10
    Join Date
    May 2006
    Posts
    7

    Smile Thanks

    Thankyou so much that fixed my problem i was able to finish the rest then.I have completed my whole assingment now.

    Thanks so much for the help
    Kala
    :-) :-)

  11. #11
    Join Date
    May 2006
    Posts
    7

    one last question

    i have to display the class name the items i think it getPath or getClass but i don't know how to write up the method.

    hope you can help i only just noticed i was missing this an its due in 3 1/2 hours

Similar Threads

  1. Replies: 3
    Last Post: 10-31-2006, 04:51 PM
  2. Assignment Operator, Returning const reference
    By codemonkey32 in forum C++
    Replies: 6
    Last Post: 02-06-2006, 04:39 PM
  3. assignment operator
    By rssmps in forum C++
    Replies: 5
    Last Post: 12-19-2005, 05:10 AM
  4. Replies: 3
    Last Post: 10-21-2005, 10:06 AM
  5. help regarding java assignment
    By abbas in forum Java
    Replies: 0
    Last Post: 12-12-2001, 09:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center