Click here to Skip to main content
13,766,741 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
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;
}


}
Posted 5 days ago
Comments
Richard MacCutchan 5 days ago
   
What is the problem?
Member 14050314 5 days ago
   
there is a error in this line
manufacturerAircraftMap.put(name , (List<string>) new Aircraft( manufacturerName));
and can u help me to sort on basis of name and manufacturer name both key and values
Richard MacCutchan 5 days ago
   
What error?
Richard MacCutchan 5 days ago
   
You cannot do that. You are trying to tell the compiler that a new object of the Aircraft class is actually a List<string>, which it patently is not.
Patrice T 5 days ago
   
and you have a question ?
OriginalGriff 5 days ago
   
And?
What does it do that you didn't expect, or not do that you did?
Where are you stuck?
What help do you need?
Member 14050314 5 days ago
   
there is a error in this line
manufacturerAircraftMap.put(name , (List<string>) new Aircraft( manufacturerName));
and can u help me to sort on basis of name and manufaturer name both key and values
OriginalGriff 5 days ago
   
What error?
When?
What do you do to get the error?
Are there any error messages?
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.181114.1 | Last Updated 10 Nov 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100