1. Compile and run the program to get the output. Explain the output. 2. Draw the...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. Compile and run the program to get the output. Explain the output. 2. Draw the UML class diagram relationships for the program // Java Program to Illustrate Difference between Aggregation and Composition // Class 1 // Engine class which will be used by car // and Car class will have a field/attribute of Engine type. class Engine { // Method to starting an engine public void work() { System.out.println("Engine } // Class 2 // Engine class class Car ( // Composition private Engine engine; // Constructor Car (Engine engine) { this.engine - engine; } public void move () { of car has been started "); engine.work(); System.out.println("Car is moving "); } } // Class 3 // Main class public class Main() public static void main(String[] args) { // Making an engine by creating // an instance of Engine class. Engine engine - new Engine(); // Making a car with engine // passing a engine instance as an argument // while creating instance of Car Car car- new Car (engine); // Making car to move //by calling move () method inside main() car.move(); }} 1. Compile and run the program to get the output. Explain the output. 2. Draw the UML class diagram relationships for the program // Java Program to Illustrate Difference between Aggregation and Composition // Class 1 // Engine class which will be used by car // and Car class will have a field/attribute of Engine type. class Engine { // Method to starting an engine public void work() { System.out.println("Engine } // Class 2 // Engine class class Car ( // Composition private Engine engine; // Constructor Car (Engine engine) { this.engine - engine; } public void move () { of car has been started "); engine.work(); System.out.println("Car is moving "); } } // Class 3 // Main class public class Main() public static void main(String[] args) { // Making an engine by creating // an instance of Engine class. Engine engine - new Engine(); // Making a car with engine // passing a engine instance as an argument // while creating instance of Car Car car- new Car (engine); // Making car to move //by calling move () method inside main() car.move(); }}
Expert Answer:
Answer rating: 100% (QA)
The images youve provided depict a Java program that illustrates the difference between aggregation and composition in objectoriented programming with ... View the full answer
Related Book For
Starting Out With Java From Control Structures Through Data Structures
ISBN: 9780133957051
6th Edition
Authors: Tony Gaddis
Posted Date:
Students also viewed these programming questions
-
re Regular Languages and Finite Automata (a) Let L be the set of all strings over the alphabet {a, b} that end in a and do not contain the substring bb. Describe a deterministic finite automaton...
-
123 Compare the purely graphical properties of these two notations, and the ways in which the graphical properties of each display correspond to the information structure being defined. Describe...
-
Jaclyn Hargrove is the owner of six Pickwick Restaurants. For the past 10 years, she has always relied on her accountant to analyze her financial statements. Jaclyn feels that if she were able to...
-
Two containers hold ideal gases at the same temperature. Container A has twice the volume and half the number of molecules as container B. What is the ratio PA / PB, where PA is the pressure in...
-
The manager of a trendy downtown caf in Columbus, Ohio, collects weekly data on the number of customers it serves. A portion of the data is shown in the accompanying table. a. Use the simple...
-
What are some indicators that a digital device has been infected?
-
Sydney Company had retained earnings of $56,000 and total stockholders equity of $75,000 at the beginning of 20X1. During 20X1 the company had net income of $21,000, declared and paid cash dividends...
-
When estimating the average cash interest rate, Multiple choice question. the beginning amount of interest-bearing debt is in the denominator. the average amount of interest-bearing debt is in the...
-
? Dean and Ellen Price are married and have a manufacturing business. They bought a piece of business equipment (7-year personal property) on 4/1/2017 for $50,000. Use half-year convention to...
-
If f(x) is defined as follows, find (a) f(-1), (b) f(0), and (c) f(2). f(x) = (a) f(-1)= (b) f(0) = (c) f(2)= 2 X 0 2x+4 if x < 0 if x = 0 if x>0 (Simplify your answer.) (Simplify your answer.)...
-
3. For a particle moving along the x axis, the acceleration vs. time graph is as shown in the diagram below. What is the velocity of the particle at t= 0 if the velocity at t = 4 sis -12 m/s? tio...
-
Three identical metal spheres are hung from a ceiling on rigid non-conducting rods. Sphere 1, sphere 2, and sphere 3 have charges 65 C, -44 C, and 52 C, respectively. Each sphere is separated by 17...
-
5. A particle moving in simple harmonic motion has a period, T, of 0.5 seconds, and an amplitude of 30 cm. If it starts at its maximum positive displacement (x = +30cm) at time t = 0.09 find the...
-
A 1.4 x 104 Hz laser emits a 3.7 s pulse, 5.0 mm in diameter, with a beam energy density of 0.72 J/m 3 . The number of wavelengths in the length of the beam will be?
-
In a Compton scattering experiment the incoming X ray of 4.4MeV is scattered off weakly bound electron in the thin carbon target at the angle of 450. The recoiling electron hits the metal mesh behind...
-
What is Erotokritos?
-
7 A 29-year-old, previously healthy man suddenly collapses at a party where legal and illicit drugs are being used. Enroute to the hospital, he requires resuscitation with defibrillation to establish...
-
Declare a two-dimensional int array named grades. It should have 30 rows and 10 columns.
-
True or False: In an applet, events are handled differently than in a GUI application.
-
What fonts does Java guarantee you have?
-
If you make multiple measurements of your height, you are likely to find that the results vary by nearly half an inch in either direction due to measurement error and actual variations in he ight....
-
Loveland, Colorado, is 18 km due south of Fort Collins and 3 1 km due west of Greeley. What is the distance between Fort Collins and Greeley?
-
Migrating geese tend to travel at approximately constant speed, flying in segments that are straight lines. A goose flies 32 km south, then turns to fly 20 km west. Afterward, how far is the goose...
Study smarter with the SolutionInn App