# Psuedocode help?



## crowleyc625 (Mar 2, 2011)

OK so I'm creating classes for a school assignment. The first part is create the class Pizza include fields for Size, toppings , price. include methods to get and set these values. create a diagram and write pseudocode that defines the class which i did

7.Pizza

Size: num
Toppings: string
Price: num

setSize(diameter:num) : void
setToppings(topping:string) : void
getSize() : num
getToppings() : string
calculatePrice() : void

a.
Class Pizza
Declarations 
num Size
string Toppings
num Price
void setSize(num diameter)
Size = diameter
return
void setToppings( string topping) 
Toppings = topping
calculatePrice()
return
num getSize()
return Size
string getToppings
return Toppings
void calculatePrice()
declarations
10 inch= 7.99
13 inch= 10.99
15 inch= 13.99
toppings= .50
Sizes= 10 inch, 13 inch, 15 inch 
Price = Size + toppings
return
endClass

the second part im stuck on and can find a satisfiing answer in the book. the question is create an application that declares two Pizza objects and sets and displays thier fields? any help would be create. this is not program specific so just the generals:banghead:


----------



## crowleyc625 (Mar 2, 2011)

thanks lol. geez


----------



## Ninjaboi (Dec 27, 2010)

Hello crowley!

I'll phrase the question you were given in this problem so that others may see it better.



> Create an application that declares two instances of the Pizza class that sets and displays their fields.


So you have a Pizza class that you created ( pseudo-code for one that you have shown ). What you are being told to do is create two instances of the Pizza class, which mean creating two objects. In most languages, this means you would have it like this:

Pizza pizza1;
Pizza pizza2;

That way you have two pizzas to work with in your application.

Next, you would set their fields. 



> Size: num
> Toppings: string
> Price: num


These are your fields. What you would do is have the class Pizza have either a constructor method or a few methods that would set these fields.



> Constructor way of doing it:
> 
> Pizza pizza1( Size = 6, Toppings = "Cheese", Price = 20 );
> Pizza pizza2( Size = 7, Toppings = "Pepperoni", Price = 24 );





> Multiple method way of doing it:
> 
> Pizza pizza1;
> Pizza pizza2;
> ...


Both ways are valid, but one is just easier to look at. Most people will make their class have both constructors and multiple methods to do these things.

For the last part you need to display the values of the fields. If you're doing it from the console it might look something like this:



> Console.Display( "Pizza 1 size: ", pizza1.GetSize() );
> Console.Display( "Pizza 1 toppings: ", pizza1.GetToppings() );
> Console.Display( "Pizza 1 price: ", pizza1.GetPrice() );
> 
> ...


This means that you would simply have your class have methods that return the values of the fields it has. Note that all this I'm displaying is from no real language I use, it's just more code-like pseudo-code. I'm not sure what language you may be using, but this should be universal enough in concept to be used in any OOP language.

Hope this helps!


----------



## crowleyc625 (Mar 2, 2011)

actually this does help we are just learning basics so it only has to make some kind of logical sense.


----------

