Write a java program to read the aircraft details from the user, and find the distinct aircraft manufacturers.
Span a thread to find the aircrafts of each manufacturer and display them.
Create a main class Main.java
Create a Aircraft class with the following attributes.
• name – String
• manufacturerName – String
create a constructor for Aircraft class with two arguments name,manufacturerName
Create another class Manufactuer with following attribute
• aircraft -List<aircraft>
• manufacturerAircraftMap - HashMap<String,List<string>>
In the manufacturerAircraftMap hashMap, Key is the manufacturer name and the value is a list of Strings which corresponds to the aircraft names.
The keys should be sorted in ascending order, and the values list also should be sorted in alphabetical order.
Extend Thread class and override the run method.
In the main class read the input from the user and create a thread for manufactuer to find the distinct aircraft manufacturers and display the details
Input and Output Format :
Refer sample input and output for formatting specifications.
[All text in bold corresponds to input and the rest corresponds to output]
Sample Input/Output:
Enter the number of aircrafts
6
Enter the aircraft 1 details
A320
AirAsia
Enter the aircraft 2 details
A318
AirAsia
Enter the aircraft 3 details
A321
AirAsia
Enter the aircraft 4 details
737
Boeing
Enter the aircraft 5 details
777
Boeing
Enter the aircraft 6 details
BD500
Bombardier
Manufacturer Details
AirAsia
A320
A318
A321
Boeing
737
777
Bombardier
BD500
What I have tried:
public class Main {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
HashMap<String , List<string>> manufacturerAircraftMap = new HashMap<>();
sc.nextLine();
String name , manufacturerName;
for(int i = 0 ; i<m ;i++)
{
System.out.print("Enter the aircraft " + i + "details :");
name = sc.nextLine();
manufacturerName = sc.nextLine();
manufacturerAircraftMap.put(name , (List<string>) new Aircraft( manufacturerName));
}
}
}
class Aircraft
{
private String name;
private String manufacturerName;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getManufacturerName() {
return manufacturerName;
}
public void setManufacturerName(String manufacturerName) {
this.manufacturerName = manufacturerName;
}
public Aircraft(String name , String manufacturerName)
{
this.setName(name);
this.setManufacturerName(manufacturerName);
}
}
class Manufacturer extends Thread
{
private List<aircraft> aircraft;
public void run()
{
}
public List<aircraft> getAircraft() {
return aircraft;
}
public void setAircraft(List<aircraft> aircraft) {
this.aircraft = aircraft;
}
}