Please convert this code into C language (#include Main.java import java.util.*; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); ArrayList planes = new ArrayList(); while (true) { System.out.print("\nAdd a plane (a)?\nRemove a plane (r)?\nSearch for plane (s)? \nQuit (q) \n"); String choice = sc.nextLine(); if (choice.equalsIgnoreCase("q")) break; else if (choice.equalsIgnoreCase("a")) { String pname; int nos; System.out.print("Enter name of plane: "); pname = sc.nextLine(); System.out.print("Enter num of seats in plane: "); nos = sc.nextInt(); Plane p = new Plane(nos, pname); System.out.print("Enter no. of Passengers on Monday: "); int nop = sc.nextInt(); p.addFlights(nop, "Monday"); System.out.print("Enter no. of Passengers on Tuesday: "); int not = sc.nextInt(); p.addFlights(not, "Tuesday"); System.out.print("Enter no. of Passengers on Wednesday: "); int now = sc.nextInt(); p.addFlights(now, "Wednesday"); System.out.print("Enter no. of Passengers on Thursday: "); int noth = sc.nextInt(); p.addFlights(noth, "Thursday"); System.out.print("Enter no. of Passengers on Friday: "); int nof = sc.nextInt(); p.addFlights(nof, "Friday"); System.out.print("Enter no. of Passengers on Saturday: "); int nosa = sc.nextInt(); p.addFlights(nosa, "Saturday"); planes.add(p); System.out.print("Added a new Plane!\n"); } else if (choice.equalsIgnoreCase("r")) { System.out.print("Enter name of plane to remove: "); String remP = sc.next(); for (int i = 0; i < planes.size(); i++) { if (planes.get(i).getName().equalsIgnoreCase(remP)) { planes.remove(i); System.out.print("Removed a Plane!\n"); } } } else if (choice.equalsIgnoreCase("s")) { System.out.print("Enter num of Passengers: "); int searchP = sc.nextInt(); ArrayList f; for (int i = 0; i < planes.size(); i++) { f = planes.get(i).getFlights(); for (int j = 0; j < f.size(); j++) { if (f.get(j).getNOP() == searchP) { System.out.print("\nThe plane is: " + planes.get(i).getName()); System.out.print("\nThe day is: " + f.get(j).getDay()); } } } } } } } arrow_forward Plane.java import java.util.*; public class Plane { int noOfSeats; String name; ArrayList flights; public Plane(int noOfSeats, String name) { this.noOfSeats = noOfSeats; this.name = name; flights = new ArrayList(); } public void addFlights(int nop, String day) { Flight f = new Flight(day, nop); flights.add(f); } public String getName() { return this.name; } public ArrayList getFlights() { return this.flights; } } arrow_forward Flight.java public class Flight { int noOfPassengers; String day; public Flight(String day, int noOfPassengers) { this.noOfPassengers = noOfPassengers; this.day = day; } public int getNOP() { return noOfPassengers; } public String getDay() { return day; } }
Please convert this code into
C language (#include <stdio.h>
Main.java
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<Plane> planes = new ArrayList<Plane>();
while (true) {
System.out.print("\nAdd a plane (a)?\nRemove a plane (r)?\nSearch for plane (s)? \nQuit (q) \n");
String choice = sc.nextLine();
if (choice.equalsIgnoreCase("q"))
break;
else if (choice.equalsIgnoreCase("a")) {
String pname;
int nos;
System.out.print("Enter name of plane: ");
pname = sc.nextLine();
System.out.print("Enter num of seats in plane: ");
nos = sc.nextInt();
Plane p = new Plane(nos, pname);
System.out.print("Enter no. of Passengers on Monday: ");
int nop = sc.nextInt();
p.addFlights(nop, "Monday");
System.out.print("Enter no. of Passengers on Tuesday: ");
int not = sc.nextInt();
p.addFlights(not, "Tuesday");
System.out.print("Enter no. of Passengers on Wednesday: ");
int now = sc.nextInt();
p.addFlights(now, "Wednesday");
System.out.print("Enter no. of Passengers on Thursday: ");
int noth = sc.nextInt();
p.addFlights(noth, "Thursday");
System.out.print("Enter no. of Passengers on Friday: ");
int nof = sc.nextInt();
p.addFlights(nof, "Friday");
System.out.print("Enter no. of Passengers on Saturday: ");
int nosa = sc.nextInt();
p.addFlights(nosa, "Saturday");
planes.add(p);
System.out.print("Added a new Plane!\n");
} else if (choice.equalsIgnoreCase("r")) {
System.out.print("Enter name of plane to remove: ");
String remP = sc.next();
for (int i = 0; i < planes.size(); i++) {
if (planes.get(i).getName().equalsIgnoreCase(remP)) {
planes.remove(i);
System.out.print("Removed a Plane!\n");
}
}
} else if (choice.equalsIgnoreCase("s")) {
System.out.print("Enter num of Passengers: ");
int searchP = sc.nextInt();
ArrayList<Flight> f;
for (int i = 0; i < planes.size(); i++) {
f = planes.get(i).getFlights();
for (int j = 0; j < f.size(); j++) {
if (f.get(j).getNOP() == searchP) {
System.out.print("\nThe plane is: " + planes.get(i).getName());
System.out.print("\nThe day is: " + f.get(j).getDay());
}
}
}
}
}
}
}
arrow_forward
Plane.java
import java.util.*;
public class Plane {
int noOfSeats;
String name;
ArrayList<Flight> flights;
public Plane(int noOfSeats, String name) {
this.noOfSeats = noOfSeats;
this.name = name;
flights = new ArrayList<Flight>();
}
public void addFlights(int nop, String day) {
Flight f = new Flight(day, nop);
flights.add(f);
}
public String getName() {
return this.name;
}
public ArrayList<Flight> getFlights() {
return this.flights;
}
}
arrow_forward
Flight.java
public class Flight {
int noOfPassengers;
String day;
public Flight(String day, int noOfPassengers) {
this.noOfPassengers = noOfPassengers;
this.day = day;
}
public int getNOP() {
return noOfPassengers;
}
public String getDay() {
return day;
}
}
arrow_forward
reference:
(Insert, search, delete)
It is capable of:
- accepting the number of passengers per day of the different planes owned by the company;
- displaying the number of passengers per plane per flight and per week;
- searching for which plane and which day in a week given the number of passengers;
- adding a new plane
- removing a plane
Step by step
Solved in 2 steps