Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete the following tasks by creating the pseudocode and diagrams for each: D

ID: 3694260 • Letter: C

Question

Complete the following tasks by creating the pseudocode and diagrams for each:

Design a class named Pizza. Data fields include a string field for a topping (such as pepperoni) and numeric fields for diameter in inches (such as 12) and price (such as 13.99). Include methods to get and set values for each of these fields. Create the class diagram and write the pseudocode that defines the class.

Design an application that declares two Pizza objects and sets and displays their values.

Design an application that declares an array of 10 Pizzas. Prompt the user for data for each of the Pizzas, then display all the values.

Explanation / Answer

//Class Pizza that contains 3 parameters and 2 methods..

Class Pizza

{

String topping;

int size;

double price;

public void getPizza()

{

String top;

int pizzasize;

double pizzaprice;

System.out.Println(“Enter Pizza Name:”+top);

system.out.Println(“Enter size of pizza”+pizzasize);

system.out.Println(“Enter price of pizza:”+pizzaprice);

set(top,pizzasize,pizzaprice); // set the values that has read from get method.

}

public void setPizza(String top,int pizzasize,double pizzaprice)

{

this.topping=top;

this.size=pizzasize;

this.price=pizzaprice;

}

}

public static void main(String args[])

{

Pizza pi,pi1;

pi.getPizza();

pi1.getPizza();

system.out.Println(“Pizza 1 name”+pi.topping+”Pizza size”+pi.size+”Pizza Price”+pi.price);

system.out.Println(“Pizza 2 name”+pi1.topping+”Pizza size”+pi1.size+”Pizza Price”+pi1.price);

}

public static void main(String args[])

{

Pizza[] pizzas=new Pizza[10];

for(int i=0;i<10;i++)

{

pizzas[i]=new Pizza(); // For initializing Pizza objects.

}

for(int i=0;i<10;i++)

pizzas[i].getPizza();

for(int i=0;i<10;i++)

                system.out.Println(“Pizza”+i+”name”+pizzas[i].topping+”Pizza size”+pizzas[i].size+”Pizza Price”+pizzas[i].price);

}             

Class diagram for Pizza class

Analysis   

Pizza

Topping

Size

Price

get Pizza

set Pizza

Design

Pizza

-Topping:String

-Size: int

-Price: double

getPizza()

setPizza(name,int,double)

Pizza

Topping

Size

Price

get Pizza

set Pizza