SlideShare a Scribd company logo
1 of 2
// Extend BoxWeight to include shipping costs. 
// Start with Box. 
class Box { 
private double width; 
private double height; 
private double depth; 
// construct clone of an object 
Box(Box ob) { // pass object to constructor 
width = ob.width; 
height = ob.height; 
depth = ob.depth; 
} 
// constructor used when all dimensions specified 
Box(double w, double h, double d) { 
width = w; 
height = h; 
depth = d; 
} 
// constructor used when no dimensions specified 
Box() { 
width = -1; // use -1 to indicate 
height = -1; // an uninitialized 
depth = -1; // box 
} 
// constructor used when cube is created 
Box(double len) { 
width = height = depth = len; 
} 
// compute and return volume 
double volume() { 
return width * height * depth; 
} 
} 
// Add weight. 
class BoxWeight extends Box { 
double weight; // weight of box 
// construct clone of an object 
BoxWeight(BoxWeight ob) { // pass object to constructor 
super(ob); 
weight = ob.weight; 
} 
// constructor when all parameters are specified 
BoxWeight(double w, double h, double d, double m) { 
super(w, h, d); // call superclass constructor 
weight = m; 
} 
// default constructor 
BoxWeight() { 
super(); 
weight = -1; 
} 
// constructor used when cube is created 
BoxWeight(double len, double m) { 
super(len); 
weight = m; 
} 
} 
// Add shipping costs 
class Shipment extends BoxWeight { 
double cost; 
// construct clone of an object 
Shipment(Shipment ob) { // pass object to constructor 
super(ob); 
cost = ob.cost;
} 
// constructor when all parameters are specified 
Shipment(double w, double h, double d, 
double m, double c) { 
super(w, h, d, m); // call superclass constructor 
cost = c; 
} 
// default constructor 
Shipment() { 
super(); 
cost = -1; 
} 
// constructor used when cube is created 
Shipment(double len, double m, double c) { 
super(len, m); 
cost = c; 
}} 
class DemoShipment { 
public static void main(String args[]) { 
Shipment shipment1 =new Shipment(10, 20, 15, 10, 3.41); 
Shipment shipment2 =new Shipment(2, 3, 4, 0.76, 1.28); 
double vol; 
vol = shipment1.volume(); 
System.out.println("Volume of shipment1 is " + vol); 
System.out.println("Weight of shipment1 is "+ shipment1.weight); 
System.out.println("Shipping cost: $" + shipment1.cost); 
System.out.println(); 
vol = shipment2.volume(); 
System.out.println("Volume of shipment2 is " + vol); 
System.out.println("Weight of shipment2 is "+ shipment2.weight); 
System.out.println("Shipping cost: $" + shipment2.cost); 
}} 
The output of this program is shown here: 
Volume of shipment1 is 3000.0 
Weight of shipment1 is 10.0 
Shipping cost: $3.41 
Volume of shipment2 is 24.0 
Weight of shipment2 is 0.76 
Shipping cost: $1.28

More Related Content

Viewers also liked

Derechos Sexuales Durante La Adolescencia
Derechos Sexuales Durante La AdolescenciaDerechos Sexuales Durante La Adolescencia
Derechos Sexuales Durante La AdolescenciaAnna A
 
What reading activities have you done
What reading activities have you doneWhat reading activities have you done
What reading activities have you doneJacqui Sharp
 
Leadership and Vision
Leadership and VisionLeadership and Vision
Leadership and Visionjefftrogers
 
Trabajo del teléfono
Trabajo del teléfonoTrabajo del teléfono
Trabajo del teléfonopiquepapasito
 
'13.2.10 know it-alls
'13.2.10 know it-alls'13.2.10 know it-alls
'13.2.10 know it-allsjudsonISU
 
El cortejo nupcial helado en la nieve (novela)
El cortejo nupcial helado en la nieve (novela)El cortejo nupcial helado en la nieve (novela)
El cortejo nupcial helado en la nieve (novela)Victor Martin Nuñez
 
Unit 3 PowerPoint Creative Writing & Literature
Unit 3 PowerPoint Creative Writing & LiteratureUnit 3 PowerPoint Creative Writing & Literature
Unit 3 PowerPoint Creative Writing & LiteratureRichard Coleman
 
Daily Routines (Study sheet)
Daily Routines  (Study sheet)Daily Routines  (Study sheet)
Daily Routines (Study sheet)Ifik Firdaus
 
An examination of selected wood properties of some economic tropical timber s...
An examination of selected wood properties of some economic tropical timber s...An examination of selected wood properties of some economic tropical timber s...
An examination of selected wood properties of some economic tropical timber s...Alexander Decker
 
Cn柴狗的惡夢
Cn柴狗的惡夢Cn柴狗的惡夢
Cn柴狗的惡夢ICEO
 
Lenguaje y estructura
Lenguaje y estructuraLenguaje y estructura
Lenguaje y estructuraLisa Carrion
 
Ibarra gonzález josé de jesús
Ibarra gonzález josé de jesúsIbarra gonzález josé de jesús
Ibarra gonzález josé de jesúsChuii Ibrr
 
Literatura y representación
Literatura y representaciónLiteratura y representación
Literatura y representaciónLisa Carrion
 

Viewers also liked (17)

Derechos Sexuales Durante La Adolescencia
Derechos Sexuales Durante La AdolescenciaDerechos Sexuales Durante La Adolescencia
Derechos Sexuales Durante La Adolescencia
 
Definición
DefiniciónDefinición
Definición
 
Mapaconceptual
MapaconceptualMapaconceptual
Mapaconceptual
 
What reading activities have you done
What reading activities have you doneWhat reading activities have you done
What reading activities have you done
 
Leadership and Vision
Leadership and VisionLeadership and Vision
Leadership and Vision
 
Trabajo del teléfono
Trabajo del teléfonoTrabajo del teléfono
Trabajo del teléfono
 
Funciones de uso diario de un navegador
Funciones de uso diario de un navegadorFunciones de uso diario de un navegador
Funciones de uso diario de un navegador
 
Temas!
Temas!Temas!
Temas!
 
'13.2.10 know it-alls
'13.2.10 know it-alls'13.2.10 know it-alls
'13.2.10 know it-alls
 
El cortejo nupcial helado en la nieve (novela)
El cortejo nupcial helado en la nieve (novela)El cortejo nupcial helado en la nieve (novela)
El cortejo nupcial helado en la nieve (novela)
 
Unit 3 PowerPoint Creative Writing & Literature
Unit 3 PowerPoint Creative Writing & LiteratureUnit 3 PowerPoint Creative Writing & Literature
Unit 3 PowerPoint Creative Writing & Literature
 
Daily Routines (Study sheet)
Daily Routines  (Study sheet)Daily Routines  (Study sheet)
Daily Routines (Study sheet)
 
An examination of selected wood properties of some economic tropical timber s...
An examination of selected wood properties of some economic tropical timber s...An examination of selected wood properties of some economic tropical timber s...
An examination of selected wood properties of some economic tropical timber s...
 
Cn柴狗的惡夢
Cn柴狗的惡夢Cn柴狗的惡夢
Cn柴狗的惡夢
 
Lenguaje y estructura
Lenguaje y estructuraLenguaje y estructura
Lenguaje y estructura
 
Ibarra gonzález josé de jesús
Ibarra gonzález josé de jesúsIbarra gonzález josé de jesús
Ibarra gonzález josé de jesús
 
Literatura y representación
Literatura y representaciónLiteratura y representación
Literatura y representación
 

Similar to Seminar

6.INHERITANCE.ppt(MB).ppt .
6.INHERITANCE.ppt(MB).ppt                    .6.INHERITANCE.ppt(MB).ppt                    .
6.INHERITANCE.ppt(MB).ppt .happycocoman
 
Class object method constructors in java
Class object method constructors in javaClass object method constructors in java
Class object method constructors in javaRaja Sekhar
 
5.CLASSES.ppt(MB)2022.ppt .
5.CLASSES.ppt(MB)2022.ppt                       .5.CLASSES.ppt(MB)2022.ppt                       .
5.CLASSES.ppt(MB)2022.ppt .happycocoman
 
Java-Module 3-PPT-TPS.pdf.Java-Module 3-PPT-TPS.pdf
Java-Module 3-PPT-TPS.pdf.Java-Module 3-PPT-TPS.pdfJava-Module 3-PPT-TPS.pdf.Java-Module 3-PPT-TPS.pdf
Java-Module 3-PPT-TPS.pdf.Java-Module 3-PPT-TPS.pdfkakarthik685
 
Multi level hierarchy
Multi level hierarchyMulti level hierarchy
Multi level hierarchymyrajendra
 
You still work for packaging company that makes boxes and cylindrical.docx
 You still work for packaging company that makes boxes and cylindrical.docx You still work for packaging company that makes boxes and cylindrical.docx
You still work for packaging company that makes boxes and cylindrical.docxajoy21
 
MODULE_3_Methods and Classes Overloading.pptx
MODULE_3_Methods and Classes Overloading.pptxMODULE_3_Methods and Classes Overloading.pptx
MODULE_3_Methods and Classes Overloading.pptxVeerannaKotagi1
 
Mpl 9 oop
Mpl 9 oopMpl 9 oop
Mpl 9 oopAHHAAH
 
Write a method replaceKey in the BinaryHeap class with the following .docx
 Write a method replaceKey in the BinaryHeap class with the following .docx Write a method replaceKey in the BinaryHeap class with the following .docx
Write a method replaceKey in the BinaryHeap class with the following .docxajoy21
 
C++ Inheritance Hierarchy! Package-delivery services, such as FedEx.pdf
C++ Inheritance Hierarchy! Package-delivery services, such as FedEx.pdfC++ Inheritance Hierarchy! Package-delivery services, such as FedEx.pdf
C++ Inheritance Hierarchy! Package-delivery services, such as FedEx.pdfarihantelectronics
 

Similar to Seminar (16)

Chapter ii(oop)
Chapter ii(oop)Chapter ii(oop)
Chapter ii(oop)
 
6.INHERITANCE.ppt(MB).ppt .
6.INHERITANCE.ppt(MB).ppt                    .6.INHERITANCE.ppt(MB).ppt                    .
6.INHERITANCE.ppt(MB).ppt .
 
Class object method constructors in java
Class object method constructors in javaClass object method constructors in java
Class object method constructors in java
 
5.CLASSES.ppt(MB)2022.ppt .
5.CLASSES.ppt(MB)2022.ppt                       .5.CLASSES.ppt(MB)2022.ppt                       .
5.CLASSES.ppt(MB)2022.ppt .
 
class object.pptx
class object.pptxclass object.pptx
class object.pptx
 
Java-Module 3-PPT-TPS.pdf.Java-Module 3-PPT-TPS.pdf
Java-Module 3-PPT-TPS.pdf.Java-Module 3-PPT-TPS.pdfJava-Module 3-PPT-TPS.pdf.Java-Module 3-PPT-TPS.pdf
Java-Module 3-PPT-TPS.pdf.Java-Module 3-PPT-TPS.pdf
 
Multi level hierarchy
Multi level hierarchyMulti level hierarchy
Multi level hierarchy
 
7_-_Inheritance
7_-_Inheritance7_-_Inheritance
7_-_Inheritance
 
Java misc1
Java misc1Java misc1
Java misc1
 
You still work for packaging company that makes boxes and cylindrical.docx
 You still work for packaging company that makes boxes and cylindrical.docx You still work for packaging company that makes boxes and cylindrical.docx
You still work for packaging company that makes boxes and cylindrical.docx
 
MODULE_3_Methods and Classes Overloading.pptx
MODULE_3_Methods and Classes Overloading.pptxMODULE_3_Methods and Classes Overloading.pptx
MODULE_3_Methods and Classes Overloading.pptx
 
Oop
OopOop
Oop
 
Mpl 9 oop
Mpl 9 oopMpl 9 oop
Mpl 9 oop
 
Write a method replaceKey in the BinaryHeap class with the following .docx
 Write a method replaceKey in the BinaryHeap class with the following .docx Write a method replaceKey in the BinaryHeap class with the following .docx
Write a method replaceKey in the BinaryHeap class with the following .docx
 
Lab3
Lab3Lab3
Lab3
 
C++ Inheritance Hierarchy! Package-delivery services, such as FedEx.pdf
C++ Inheritance Hierarchy! Package-delivery services, such as FedEx.pdfC++ Inheritance Hierarchy! Package-delivery services, such as FedEx.pdf
C++ Inheritance Hierarchy! Package-delivery services, such as FedEx.pdf
 

Seminar

  • 1. // Extend BoxWeight to include shipping costs. // Start with Box. class Box { private double width; private double height; private double depth; // construct clone of an object Box(Box ob) { // pass object to constructor width = ob.width; height = ob.height; depth = ob.depth; } // constructor used when all dimensions specified Box(double w, double h, double d) { width = w; height = h; depth = d; } // constructor used when no dimensions specified Box() { width = -1; // use -1 to indicate height = -1; // an uninitialized depth = -1; // box } // constructor used when cube is created Box(double len) { width = height = depth = len; } // compute and return volume double volume() { return width * height * depth; } } // Add weight. class BoxWeight extends Box { double weight; // weight of box // construct clone of an object BoxWeight(BoxWeight ob) { // pass object to constructor super(ob); weight = ob.weight; } // constructor when all parameters are specified BoxWeight(double w, double h, double d, double m) { super(w, h, d); // call superclass constructor weight = m; } // default constructor BoxWeight() { super(); weight = -1; } // constructor used when cube is created BoxWeight(double len, double m) { super(len); weight = m; } } // Add shipping costs class Shipment extends BoxWeight { double cost; // construct clone of an object Shipment(Shipment ob) { // pass object to constructor super(ob); cost = ob.cost;
  • 2. } // constructor when all parameters are specified Shipment(double w, double h, double d, double m, double c) { super(w, h, d, m); // call superclass constructor cost = c; } // default constructor Shipment() { super(); cost = -1; } // constructor used when cube is created Shipment(double len, double m, double c) { super(len, m); cost = c; }} class DemoShipment { public static void main(String args[]) { Shipment shipment1 =new Shipment(10, 20, 15, 10, 3.41); Shipment shipment2 =new Shipment(2, 3, 4, 0.76, 1.28); double vol; vol = shipment1.volume(); System.out.println("Volume of shipment1 is " + vol); System.out.println("Weight of shipment1 is "+ shipment1.weight); System.out.println("Shipping cost: $" + shipment1.cost); System.out.println(); vol = shipment2.volume(); System.out.println("Volume of shipment2 is " + vol); System.out.println("Weight of shipment2 is "+ shipment2.weight); System.out.println("Shipping cost: $" + shipment2.cost); }} The output of this program is shown here: Volume of shipment1 is 3000.0 Weight of shipment1 is 10.0 Shipping cost: $3.41 Volume of shipment2 is 24.0 Weight of shipment2 is 0.76 Shipping cost: $1.28