Use Netbeans to run the following decorator pattern code. Provide screenshot to prove that the code runs successfully. Design a UML class diagram to model the program and fully explain the class diagram. SpaceshipDetails.java: public interface SpaceshipDetails {void name(String name);void size(String size);void passengerCabin(int load, int unload);void laserGun(int c);void rangeFinder(int d);void hyperDriver(int dist);} EbonHawk.java: public class EbonHawk implements SpaceshipDetails {@Overridepublic void name(String name) {System.out.println("The name of the ship is: " + name);}@Overridepublic void size(String size) {System.out.println("The size of the ship Ebon Hawk is: " + size);}@Overridepublic void passengerCabin(int load, int unload) {System.out.println("Number of passengers to be loaded: " + load);System.out.println("Number of passengers to be unloaded: " + unload);}@Overridepublic void laserGun(int c) {if (c == 1) {System.out.println("The spaceship has a gun");}else {System.out.println("The spaceship does not contain a laser gun");}}@Overridepublic void rangeFinder(int d) {System.out.println("The distance of the next object: " + d);}@Overridepublic void hyperDriver(int dist) {System.out.println("The distance to the next satr: " + dist);}} Spaceship.java: import java.util.*; public class Spaceship {public static void main(String[] args) {SpaceshipDetails o = new EbonHawk();String name;int c;String size;int load, unload;int d;int distance;Scanner s = new Scanner(System.in);System.out.println("Enter the name of the spaceship: ");name = s.nextLine();System.out.println("Enter the size of the spaceship: ");size = s.next();System.out.println("Enter the number of passengers boarding and getting off "+ "of spaceship: ");load = s.nextInt();unload = s.nextInt();System.out.println("Enter 1 if spaceship has a gun, 0 otherwise: ");c = s.nextInt();System.out.println("Enter the distance of the nearest object (in light years): ");d = s.nextInt();System.out.println("Enter the distance of the star to which jump to (in light year): ");distance = s.nextInt();o.name(name);o.size(size);o.passengerCabin(load, unload);o.laserGun(c);o.rangeFinder(d);o.hyperDriver(distance);s.close();}}
Use Netbeans to run the following decorator pattern code. Provide screenshot to prove that the code runs successfully.
Design a UML class diagram to model the program and fully explain the class diagram.
SpaceshipDetails.java:
public interface SpaceshipDetails {
void name(String name);
void size(String size);
void passengerCabin(int load, int unload);
void laserGun(int c);
void rangeFinder(int d);
void hyperDriver(int dist);
}
EbonHawk.java:
public class EbonHawk implements SpaceshipDetails {
@Override
public void name(String name) {
System.out.println("The name of the ship is: " + name);
}
@Override
public void size(String size) {
System.out.println("The size of the ship Ebon Hawk is: " + size);
}
@Override
public void passengerCabin(int load, int unload) {
System.out.println("Number of passengers to be loaded: " + load);
System.out.println("Number of passengers to be unloaded: " + unload);
}
@Override
public void laserGun(int c) {
if (c == 1) {
System.out.println("The spaceship has a gun");
}
else {
System.out.println("The spaceship does not contain a laser gun");
}
}
@Override
public void rangeFinder(int d) {
System.out.println("The distance of the next object: " + d);
}
@Override
public void hyperDriver(int dist) {
System.out.println("The distance to the next satr: " + dist);
}
}
Spaceship.java:
import java.util.*;
public class Spaceship {
public static void main(String[] args) {
SpaceshipDetails o = new EbonHawk();
String name;
int c;
String size;
int load, unload;
int d;
int distance;
Scanner s = new Scanner(System.in);
System.out.println("Enter the name of the spaceship: ");
name = s.nextLine();
System.out.println("Enter the size of the spaceship: ");
size = s.next();
System.out.println("Enter the number of passengers boarding and getting off "
+ "of spaceship: ");
load = s.nextInt();
unload = s.nextInt();
System.out.println("Enter 1 if spaceship has a gun, 0 otherwise: ");
c = s.nextInt();
System.out.println("Enter the distance of the nearest object (in light years): ");
d = s.nextInt();
System.out.println("Enter the distance of the star to which jump to (in light year): ");
distance = s.nextInt();
o.name(name);
o.size(size);
o.passengerCabin(load, unload);
o.laserGun(c);
o.rangeFinder(d);
o.hyperDriver(distance);
s.close();
}
}

Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 7 images









