Create a class hierarchy for a space exploration simulator.
-
Create a class called
SpaceShip
with the following properties:private String name
: The name of the spaceship. 🚀private final int maxCrew
: The maximum number of crew members the spaceship can accommodate. 👥private int currentCrew
: The current number of crew members on board. 👨🚀👩🚀private double fuelLevel
: The current fuel level of the spaceship. ⛽
-
Implement getter and setter methods for the
name
,currentCrew
, andfuelLevel
properties. -
Create two constructors for the
SpaceShip
class:- A constructor that accepts the
name
andmaxCrew
as parameters and initializes thecurrentCrew
andfuelLevel
to 0. - A constructor that accepts the
name
,maxCrew
,currentCrew
, andfuelLevel
as parameters.
- A constructor that accepts the
-
Create a class called
CrewMember
with the following properties:private String name
: The name of the crew member. 😄private String role
: The role of the crew member (e.g., Captain, Engineer, Scientist). 👨✈️ 👩🔬
-
Implement getter and setter methods for the
name
androle
properties of theCrewMember
class. -
In the
SpaceShip
class, add a method calledaddCrewMember
that accepts aCrewMember
object and adds it to the spaceship if there is available space. If the spaceship is full, print a message indicating that no more crew members can be added. 🚫 -
Create a
main
method to instantiate aSpaceShip
object and add someCrewMember
objects to it. Print the details of the spaceship and its crew members. 📜
Implement interfaces for different shapes and calculate their properties.
-
Create an interface called
Shape
with the following methods:double calculateArea()
: Calculates the area of the shape. 📏double calculatePerimeter()
: Calculates the perimeter of the shape. 📐
-
Create a class called
Rectangle
that implements theShape
interface with the following properties:private double length
: The length of the rectangle. 📏private double width
: The width of the rectangle. 📏
-
Implement the
calculateArea()
andcalculatePerimeter()
methods in theRectangle
class according to the rectangle's formula. ➕🔢 -
Create a class called
Circle
that implements theShape
interface with the following property:private double radius
: The radius of the circle. 🔵
-
Implement the
calculateArea()
andcalculatePerimeter()
methods in theCircle
class according to the circle's formula. 🔢➗ -
Create a
main
method to instantiate objects of theRectangle
andCircle
classes and calculate their areas and perimeters. 📊
Implement algorithms to analyze a music playlist.
-
Create a class called
PlaylistAnalyzer
with the following methods:-
public static String[] findLongSongs(String[] songs, double[] durations, double threshold)
: Accepts an array of song titles (songs
) and an array of their corresponding durations (durations
) in minutes. Returns an array containing the titles of the songs that exceed the giventhreshold
duration. 🎵⏰ -
public static double calculateTotalPlaytime(double[] durations)
: Accepts an array of song durations (durations
) in minutes and calculates the total playtime of the playlist. ⏱️
-
-
Implement the
findLongSongs
method by iterating over thesongs
anddurations
arrays, comparing each song's duration with thethreshold
, and storing the titles of the songs that exceed the threshold in a new array. 🔍🎧 -
Implement the
calculateTotalPlaytime
method by iterating over thedurations
array and summing up all the durations. ➕⏰ -
Create a method called
public static void printSongs(String[] songs)
that accepts an array of song titles and prints them in a formatted manner. 🖨️🎶 -
In the
main
method, create an array of sample song titles and their corresponding durations. Call thefindLongSongs
method with a specific threshold value and store the result in a new array. Print the long songs using theprintSongs
method. Then, call thecalculateTotalPlaytime
method and print the total playtime of the playlist.▶️ 🎵
Implement algorithms to manipulate arrays in a weather data analysis system.
-
Create a class called
WeatherDataAnalyzer
with the following method:public static double[] calculateAverageTemperature(double[][] temperatures)
: Accepts a 2D array of temperatures, where each row represents a day and each column represents an hour. Calculate and return an array containing the average temperature for each day. 🌡️📅
-
Implement the
calculateAverageTemperature
method by iterating over the 2D array, calculating the average temperature for each day, and storing the results in a new array. 🔢🌡️ -
Create a method called
public static void printTemperatures(double[] temperatures)
that accepts an array of temperatures and prints them in a formatted manner. 🖨️📊 -
In the
main
method, create a 2D array of sample temperature data and call thecalculateAverageTemperature
method. Then, print the results using theprintTemperatures
method. 📈