Results 1 to 11 of 11
  1. #1
    JavaCake is offline Member
    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0

    Default Pizza ordering system - university project urgent help needed!

    Hi all,

    I am a complete beginner in Java and things are moving quite quickly at university and I'm having difficulty keeping up. I have a project and I will share the specifications and show you what I've done so far. It may be completely awful, and the specification is quite long but I'd be very happy if you'd just bear with me and give me a hand, I've got until this Friday - the 14th of December to finish this and not sure how I'm going to do it!

    Background

    As part of a larger project, building an online ordering system for a Pizza company, you need to design and implement a system for calculating the costs and some other features about a pizza. The system will allow you to build a pizza from a base and some toppings.

    Task

    Your task is to create a prototype which allows cost calculations for pizzas.

    You will need at least three classes.

    Pizza
    This should carry all the essential information about a pizza, including a single base and some toppings. This class should know what toppings and which base the pizza has, so it should be the only class that has the information to calculate the cost of the pizza.

    PizzaBase
    This class should model a pizza base. You will need at least two, one thick and one thin. This needs to have information about different bases & prices.

    PizzaTopping
    This class should model a pizza topping. You need at least four toppings, but you may provide as many as you choose. Again this needs to have information about toppings & their prices.

    For later stages of this coursework, you will build a simple user interface. This is a prototype system, so the user interface does NOT need to be complex; a simple command-line interface using Scanner and println statements is entirely sufficient. However, as your classes may be used in several different situations, none of Pizza, PizzaBase nor PizzaTopping should require any user interaction. None of the above classes need main methods.

    There are a number of features that you should attempt to achieve; please complete these in the order given.

    Build a Pizza
    The initial version of your system should allow enable you to create objects for a pizza, one base and several toppings. Each of the ingredients should have a cost associated with it. You should be able to combine these to create a pizza which should have one and only one base, but many toppings. The finished pizza should calculate it’s cost. You should write a simple class called PizzaBuild which contains a main method which demonstrates this working.

    Create a user interface
    Create a new class called PizzaChoice. This should have a main method, and class should provide a simple user interface. This should provide you with a choose of one base, and a number of toppings. It should compose the objects that you created in the previous task. Once complete, you should print a short report showing all the ingredients, the price for each and the total cost. The report should be formatted for easy reading. You may create additional classes, beyond PizzaChoice should you find this useful.

    Named Pizza
    Sometimes, there can be too many choices in life. Write a new class PizzaMenu, with a main method, which allows the user to choose from a menu of predefined pizza’s. For instance, a Margherita pizza consists of tomato, mozzarella and basil, on a thin base. You should provide the user with a choice of at least three pizzas. As before, you should print a short report showing all the ingredients. You may create additional classes beyond PizzaMenu should you find this useful.

    Vegetarian Options
    Modify your PizzaToping, PizzaBase and Pizza classes so that the contain a property which describes whether they are vegetarian or not. A pizza should be vegetarian if and only if all of its ingredients are. Extend the reports produced by the last task so that they clearly state whether the pizza is suitable for vegetarians.

    So, here is my code so far:

    Java Code:
     import java.util.Map;
    import java.util.HashMap;
    
    public class Pizza {
    
    	PizzaBase base;
    	Map<String,PizzaTopping> toppings = new HashMap<String,PizzaTopping>();
    	
    	Pizza(PizzaBase b, HashMap<String,PizzaTopping> t){
    		base = b;
    		toppings = t;
    	}
    	
    	public void putBase(String b){
    		PizzaBase base = new PizzaBase(b);
    	}
    	
    	public void addToppings(String t){
    		for(int i = 0; i<toppings.size(); i++){
    		PizzaTopping topping = new PizzaTopping(t);
    		toppings.add("olives");
    		}
    		
    	}
    	
    	public double pizzaCost(){	
    		
    			
    		}
    	}
    ------

    Java Code:
     
    	
    public class PizzaBase {
    
    	private String base;
    	private double cost;
    	
    	PizzaBase(String b){
    		base = b;
    	
    	if(base.equals("thin")){
    		setCost(1.8);
    	}
    	
    	else if(base.equals("thick"))
    		setCost(2.0);
    	}
    
    	public double getCost() {
    		return cost;
    	}
    
    	private void setCost(double cost) {
    		this.cost = cost;
    	}
      }
    ---
    Java Code:
    import java.util.Map;
    import java.util.HashMap;
    
    public class PizzaTopping {
    	
    	private String topping;
    	private double cost;
    	
    	PizzaTopping(String t){
    		topping = t;
    
    	if(topping.equals("tomato sauce")){ 
    		setCost(0.1);
    	}
    		
    	else if(topping.equals("olives")){
    		setCost(0.1);
    	}
    	
    	else if(topping.equals("corn")){
    		setCost(0.15);
    	}
    	
    	else if(topping.equals("mushrooms")){
    		setCost(0.2);
    	}
    	
    	else if(topping.equals("pineapple")){
    		setCost(0.25);
    	}}
    
    	public double getCost(){
    		return cost;
    	}
    	
    	private void setCost(double cost) {
    		this.cost = cost;
    	}
    }
    ---
    Java Code:
    public class PizzaBuild {
    
    	public static void main(String[] args) {
    		
    		Pizza p = new Pizza();
    
    	}
    
    }
    Again please remember I am very new to java and what I've done so far may be completely wrong. I just want your feedback for what I've done so far and hope that you can point me in the right direction so that I can get this project done. I'm not sure what I'm doing is right at all, so if you could just have a look and let me know what you think I'd be grateful. Thank you.

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Pizza ordering system - university project urgent help needed!

    Hi! Do you have a specific question? Is something not working the way you expect it to?

  3. #3
    JavaCake is offline Member
    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0

    Default Re: Pizza ordering system - university project urgent help needed!

    Quote Originally Posted by quad64bit View Post
    Hi! Do you have a specific question? Is something not working the way you expect it to?
    Hey. I'm sorry if I didn't state it very clearly in my post. All I'm looking for is for feedback on whether what I've done so far makes sense or not, and how I can get it to work. As I said at the very beginning of my post, I've just began programming and my university course is moving a bit quickly, I'm having trouble keeping up. I have to hand in this project this Friday and I'm not sure if I'm on the right track or not. So basically I'd like some feedback on what I've done so far and it would be nice if you experts could point me in the right direction... I hope that's not too much to ask.

  4. #4
    Darkzombies is offline Senior Member
    Join Date
    Nov 2012
    Posts
    105
    Rep Power
    0

    Default Re: Pizza ordering system - university project urgent help needed!

    Well, I'm not sure if you have to do it a certain way, but you can make an enum for strings that don't change (I.E. constants) and check the input against the values in the enum.

    Java Code:
    public enum PizzaToppingsAvailable{
       OLIVES("olives"), PINEAPPLE("pineapple"), etc.
    
       private String toppings;
    
       private PizzaToppingsAvailable(String toppings){
          this.toppings = toppings;
       }
    
       public String getToppings(){
          return toppings;
       }
    }

  5. #5
    JavaCake is offline Member
    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0

    Default Re: Pizza ordering system - university project urgent help needed!

    Quote Originally Posted by Darkzombies View Post
    Well, I'm not sure if you have to do it a certain way, but you can make an enum for strings that don't change (I.E. constants) and check the input against the values in the enum.

    Java Code:
    public enum PizzaToppingsAvailable{
       OLIVES("olives"), PINEAPPLE("pineapple"), etc.
    
       private String toppings;
    
       private PizzaToppingsAvailable(String toppings){
          this.toppings = toppings;
       }
    
       public String getToppings(){
          return toppings;
       }
    }
    We haven't actually gone through enums yet so I don't think we're supposed to do it that way. I'm sure I wouldn't lose marks for it but I'd just rather stick to what we've done so far than go into different directions...Looking at what I've done so far one thing I am certainly wondering is where I should have my HashMap, and whether I really need the chain of if and else if statements in the PizzaTopping & PizzaBase classes. I have a feeling I'm overcomplicating things...

  6. #6
    JavaCake is offline Member
    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0

    Default Re: Pizza ordering system - university project urgent help needed!

    Bump...

  7. #7
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    137
    Rep Power
    0

    Default Re: Pizza ordering system - university project urgent help needed!

    I am new to Java too. I think you should consider IS-A and HAS-A relationships to make your code shine in the university. PIZZA HAS-A TOPPING which to me seems like "interface" instead of "class". Interface can "Topp" on other foods aswell by implementing it. But compositing Topping in Pizza... My simle suggestion is:
    Java Code:
    interface Top {
       //these are constants
        String = 
        mushrooms = "Mushrooms", 
        vinegar = "Vinegar",
        chefSpit = "Boo!A spit",
        other = "etc";
        //functions
        /*add your desired functions, if any here */
    }
    
    public class Pizza implements Top {
    
     // add your topping here 
    }
    That`s my suggestion, just put IS-A and HAS-A and you`ll find that Topping suits for interface better.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default Re: Pizza ordering system - university project urgent help needed!

    Java Code:
    interface Top {
       //these are constants
        String = 
        mushrooms = "Mushrooms", 
        vinegar = "Vinegar",
        chefSpit = "Boo!A spit",
        other = "etc";
        //functions
        /*add your desired functions, if any here */
    }
    
    public class Pizza implements Top {
    
     // add your topping here 
    }
    You have that way wrong I'm afraid.

    This code here is saying a Pizza is-a Top.
    Has-a would be represented as:
    Java Code:
    public class Pizza {
       List<Top> toppings;
    }
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    137
    Rep Power
    0

    Default Re: Pizza ordering system - university project urgent help needed!

    Well, I might be new, but I am afraid I can`t totally agree with you mr. Tolls. The way you say is that Pizza always have toppings, which may be true but might not be true aswell. I am reading B.Eckel "Thinking in Java" and the chapter with Interfaces, purely show that interface is actually more than HAS-A instead of simply multiple inheriting stuff. Besides consider this:
    Java Code:
    interface Eatable {
          public boolean isEatable() {}
    }
    interface Purchasable {
         public boolean canByAtMall() {}
    }
    interface Womanizer {
        public boolean girlsWillLikeYou() {}
    }
    
    class HotDog implements Eatable, Purchasable {
     //add code
    }
    classGreenSalad implements Eatable, Purchasable, Womanizer {
        
    }
    This to me is exactly a HAS-A some properties instead of just extending Eatable... how can you extend something that must represent a bahaviour?
    One more thing - what if I want a special pizza blat so I can make pizza at home so I can wrap meat in it? Or make other typos of Pizza? If I extend your Pizza, I`ll always have reference to toppigs variables, so you are telling explictily that Pizza has toppings. But I must disagree... It might be a dietic pizza without anything or just blat pizza instead of bread for example.
    Last edited by heatblazer; 12-11-2012 at 04:46 PM. Reason: error typo 2

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default Re: Pizza ordering system - university project urgent help needed!

    Behaviour is not a HAS-A relationship.

    If you want to go the behaviour route, then we are talking contracts.
    Implementing an interface, as with extending a class, is simply creating an IS-A, as far as class type is concerned.
    After all, if (using your Pizza example above) my Pizza was not a Top then this would not work:
    Java Code:
    public void someMethod(Top top) {
    }
    
    public void someOtherMethod() {
       Pizza p = new Pizza();
       someMethod(p);
    }
    That there is the definition of an is-a.

    My pizza does not have to have a topping.
    There's nothing in my model above that says I have to have anything in my toppings list.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  11. #11
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    137
    Rep Power
    0

    Default Re: Pizza ordering system - university project urgent help needed!

    I`ve tried some polimprphic classes, that implemented many interfaces, and this proved you are completely right. But I guess it`s language flaw that makes such distraction. As not a native english speaker ( such as me ) it`s quite logical that some class HAS-A interrface, which is as logical as some class extends a base class. The only way for me to get to that strange concept was with polymorphism + multiple inheritance. To me that is not a good concept in Java.
    I might add that link that compares abstract class vs interface
    http://mindprod.com/jgloss/interfacevsabstract.html There is a row IS-A VS CAN-DO, which gives a good examples.
    Last edited by heatblazer; 12-12-2012 at 12:07 PM. Reason: adding link

Similar Threads

  1. Replies: 1
    Last Post: 12-05-2012, 08:57 PM
  2. Replies: 2
    Last Post: 01-19-2012, 07:43 PM
  3. Pizza Order System
    By pinkdreammsss in forum Java Applets
    Replies: 7
    Last Post: 10-09-2011, 09:31 PM
  4. Help for University Project
    By ja107 in forum Networking
    Replies: 3
    Last Post: 03-18-2010, 10:22 AM
  5. Help for University Project
    By ja107 in forum Networking
    Replies: 1
    Last Post: 03-04-2010, 12:22 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •