In: Computer Science
Inheritance - What is inheritance - Answer your own description in Readme.txt
Based on Hamburger project, you will create a package about Pizza.
In your Readme.txt, write how you make your Pizza package differently from the Hamburger package and also explain how inheritance work with your Pizza package.
package Hamburger;
/**
* Inheritance challenge – Hamburger place (Main, Hamburger, two
other Burger type class)
* Hamburger class should have name, bread roll type, meat, and up
to 4 additional
* additions(e.g. lettuce, tomato, carrot, etc)
* to select to be added to the burger. Each item will be charged an
additional
*/
public class Hamburger {
private String name;
//meat, price, breadRollType
private String meat;
private double price;
private String breadRollType;
private String additionName1;
private double additionPrice1;
private String additionName2;
private double additionPrice2;
private String additionName3;
private double additionPrice3;
private String additionName4;
private double additionPrice4;
public Hamburger(String name, String meat, double price, String
breadRollType) {
this.name = name;
this.meat = meat;
this.price = price;
this.breadRollType = breadRollType;
}
public void addHamburgerAddition1(String name, double
price){
this.additionName1 = name;
this.additionPrice1 = price;
}
public void addHamburgerAddition2(String name, double
price){
this.additionName2 = name;
this.additionPrice2 = price;
}
public void addHamburgerAddition3(String name, double
price){
this.additionName3 = name;
this.additionPrice3 = price;
}
public void addHamburgerAddition4(String name, double
price){
this.additionName4 = name;
this.additionPrice4 = price;
}
public double hamberPriceTotal(){
double hamburgerPrice = this.price;
System.out.println(this.name + " hambuger on a " + this.breadRollType + " roll with " + this.meat + "'s price is " + this.price);
if(this.additionName1 != null){
hamburgerPrice += this.additionPrice1;
System.out.println("Added " + this.additionName1 + " for an extra "
+ this.additionPrice1);
}
if(this.additionName2 != null){
hamburgerPrice += this.additionPrice2;
System.out.println("Added " + this.additionName2 + " for an extra "
+ this.additionPrice2);
}
if(this.additionName3 != null){
hamburgerPrice += this.additionPrice1;
System.out.println("Added " + this.additionName3 + " for an extra "
+ this.additionPrice3);
}
if(this.additionName4 != null){
hamburgerPrice += this.additionPrice4;
System.out.println("Added " + this.additionName4 + " for an extra "
+ this.additionPrice4);
}
return hamburgerPrice;
}
}
class Person(object):
def __init__(self, first_name, last_name, age, gender):
self.first_name = first_name
self.last_name = last_name
self.age = age
self.gender = gender
def print_full_name(self):
msg = '{first_name} {last_name}'.format( first_name=self.first_name, last_name=self.last_name)
print(msg)
class Teacher(Person):
def __init__(self, first_name, last_name, age, gender, subject):
super().__init__(first_name, last_name, age, gender)
self.subject = subject
def print_subject(self):
msg = "Subject: {subject}".format(subject=self.subject) print(msg)
class Student(Person):
def __init__(self, first_name, last_name, age, gender, std_class):
super().__init__(first_name, last_name, age, gender)
self.std_class = std_class
def print_class_name(self):
msg = 'Class name: {name}'.format(name=self.std_class)
print(msg) p = Person('Shera', 'Md', 20, 'Male')
p.print_full_name() t = Teacher('Gilchrist', 'Adam', 20, 'Male', 'Maths')
t.print_full_name() t.print_subject() s = Student('Priya', 'Ch', 20, 'Female', '3rd Class')
s.print_full_name()
s.print_class_name()