aspose file tools*
The moose likes Java in General and the fly likes Need help on college work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Need help on college work" Watch "Need help on college work" New topic
Author

Need help on college work

Kush Blaine
Greenhorn

Joined: Dec 09, 2012
Posts: 5
Hi guys i need help with this college:
The Item:
An Item consists of a price, a name and a quantity. An Item should have appropriate constructors and the following
methods:
1. Getter methods for each of the variables within the Item.
2. A method to increase the quantity within the Item.
3. A method to calculate the total price for that Item.
4. A toString method.
The Shopping List:
A Shopping List consists of a name and a list of Item objects. It should have appropriate constructors, as well as
methods to do the following:
1. Get the name of the list.
2. Calculate the total price required to purchase all Items in the list and return the value.
3. Search for an Item in the list (check that a certain Item is in the list, given its name), and if it is, return it.
4. Add an Item to the list (if it's already there, add one to its quantity) and return a piece of text indicating
whether it was added or the quantity was updated.
5. Remove an Item from the list (check if the Item is present in the list and if it is, remove it) and return a
boolean indicating whether or not it has been removed.
6. Display all Items in the list.
7. Find the most expensive Item and return it.
8. Find the cheapest Item and return it.
9. Find the most-wanted Item (i.e. the one with the highest quantity) & return it.
10. A method of your own invention (see below).
The Application:
The Shopping List application should allow the user to create a named shopping list. It should then provide a menu
to allow the user to repeatedly select one of the following actions:
1. Add an Item to the Shopping List (your application should let the user know whether the Item was added for
the first time or its quantity was increased).
2. Remove an Item from the Shopping List (your application should let the user know whether or not the Item
was deleted).
3. Search for an Item and display that Item’s details.
4. Display the total price required to pay for the Shopping List.
5. Display the most expensive Item in the list.
6. Display the cheapest Item in the list.
7. Display the most-wanted Item in the list.
8. Display all Items in the list.
9. Carry out the action handled by your invented method (see below).
10. Exit the program. (If the user chooses this option, your application should display an exit message before
closing.)
Your Invented Method:
Your Shopping List should contain a useful method of your own creation that adds to the Shopping List’s
functionality. For example, you could create a method that takes an amount for the user’s budget and checks to see
if the budget covers the total price of the Items in the Shopping List. If the budget isn’t enough, the method would
remove Items until the total price of the Shopping List is covered by the user’s budget. It would then inform the user
of what Items were removed.


i dont know where to start witht he shopping list and app
I have the item class done here it is :

public class Item
{
// The name of the item.
private String name;
// The quantity of the item.
private int quantity ;
// The price of the item
private double price;

public Item(String name, int quantity, double price)
{

this.name = name;
this.quantity = quantity;
this.price = price;
}


public String getName()
{
return name;
}


public int getQuantity()
{
return quantity;
}


public double getPrice()
{
return price;
}

public void setQuantity(int quantity)
{
this.quantity = quantity;
}

public void totalPrice(double totPrice)
{
totPrice = quantity * price;
}



public String toString()
{
return "Name: " + name +
" Quantity: " +
quantity + " Price: " + price;
}
}



Any help is much appreciated thanks guys
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Kush Blaine wrote:Hi guys i need help with this college:
The Item:
An Item consists of a price, a name and a quantity. An Item should have appropriate constructors and the following
methods:
1. Getter methods for each of the variables within the Item.
2. A method to increase the quantity within the Item.
3. A method to calculate the total price for that Item.
4. A toString method.



In my opinion, when it comes to these types of "color by numbers" homework assignments, it is probably best to do it in the order that the assignment is written. After all, the instructor went through all that trouble to tell you exactly what to do, you might as well do it exactly.

Anyway... you have four steps in part one. Does you code....

Kush Blaine wrote:
I have the item class done here it is :




accomplish those four steps??

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Kush Blaine
Greenhorn

Joined: Dec 09, 2012
Posts: 5
yes that bit is working fine just compiled and tested it now im after starting the shopping List(arraylist) part .
it says i need to get the user to name the list themselves so i m guessing to create a variable to store that name and then pass it as the name of the list.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Kush Blaine wrote:yes that bit is working fine just compiled and tested it now im after starting the shopping List(arraylist) part .


Really?? How will I use the class to increase the quantity? How will I use the class to calculate the total? Show us your test code that does this please.

Henry
Kush Blaine
Greenhorn

Joined: Dec 09, 2012
Posts: 5
okay dont know if you are being rude or w/e your problem is... had to a make a change to totalPrice from the item class :
public double totalPrice()
{
double totPrice = quantity * price;
return totPrice;
}

here is the sample GUI using the Item class :


import java.util.*;
public class ItemApp{
public static void main(String[] args){
// Not getting user input yet as its just a test.
Item item1 = new Item("Potatoes",20,4);
//Getter Methods
item1.getName();
item1.getQuantity();
item1.getPrice();
System.out.println(item1.toString());

//setter
item1.setQuantity(15);
item1.getQuantity();
System.out.println(item1.toString());

//totalPrice
System.out.println("totalPrice: " + item1.totalPrice());
}


}
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Kush Blaine wrote:okay dont know if you are being rude or w/e your problem is... had to a make a change to totalPrice from the item class :
public double totalPrice()
{
double totPrice = quantity * price;
return totPrice;
}

}



Well, I *was* helping you -- pointing out issues that you will encounter -- and doing so in a way that you will discover it for yourself ... but I understand, if you don't like to be helped that way. Perhaps someone else can help you instead.

Henry
Kush Blaine
Greenhorn

Joined: Dec 09, 2012
Posts: 5
nah it's cool any help is welcome. It's hard to read people expression/tone online if you know what i mean... I need to finish that exercise before wednesday.
John Bonham
Greenhorn

Joined: Dec 12, 2012
Posts: 1
Did you get your project sorted Kush?
Kush Blaine
Greenhorn

Joined: Dec 09, 2012
Posts: 5
No i have until friday evening, been busy with work lately...
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11417
    
  16

Kush,

You may want to read this page on how to properly format your code here.

Remember, folks here are giving up their own time to help you. Therefore, it is your job to make it as easy as possible for them to do so. Many folks will see improperly formatted code, figure you don't care enough to take the time to do things how we expect them, and won't bother spending their time helping you.

There are plenty of other tips here on the best way to get help here. You may want to read a few other of those articles as well.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
Don't get me started about those stupid light bulbs.
 
subject: Need help on college work