I could use some help witht this question! The code must be a C#application. Als
ID: 3842702 • Letter: I
Question
I could use some help witht this question!
The code must be a C#application. Also please make it basic as possible as I am a beginner. MUST BE A C# console application!!! PLEASE PLEASE MAKE IT AS BASIC AS POSSIBLE AND EXPLAIN WHAT YOU ARE DOING!!!
------------------------------------------------------------------------------------------------------------------------------------------------------------------
You can use Console application for now.
A small airline has just purchased a computer for its new automated
reservations system. You have been asked to develop the new system. You’re to write an
app to assign seats on each flight of the airline’s only plane (capacity: 10 seats).
Display the following alternatives:
Please type 1 for First Class and Please type 2 for Economy.
Enter 3 to exit (this is optional, but nice to have. Look at the TemperatureConverter for your inspiration)
If the user types 1, your application should assign a seat in the first-class section (seats 1–5).
If the user types 2, your application should assign a seat in the economy section (seats 6–10).
Use a one-dimensional array of type bool to represent the seating chart of the plane.
Initialize all the elements of the array to false to indicate that all the seats are empty (actually it is default).
As each seat is assigned, set the corresponding element of the array to true to indicate that the seat is no longer available.
Your application should never assign a seat that has already been assigned!
When the economy section is full, your application should ask the user if it’s acceptable to be placed in the first-class section (and
vice versa).
But first check if seats are available in another class!
If the answer is yes, make the appropriate seat assignment. If no, display the message "Next flight
leaves in 3 hours."
Same if all seats are reserved, display the message "Next flight leaves in 3 hours."
Boolean seats:
Methods that might be helpful to implement:
public bool IsFirstClassAvailable()
public bool IsEconomyClassAvailable()
private bool[] GetAllSeats()
public bool[] GetFirstClassSeats()
public bool[] GetEconomyClassSeats()
public int ReserveFirstClassAnySeat()
public int ReserveEconomyClassAnySeat()
--------------------------------------------------------------------------
Sample of what the output should look like.
------------------------------------------------------------------------------------------------
Thanks
Explanation / Answer
using java.util.Scanner;
public class Reservation {
private static int FIRST_CLASS_NUM_SEATS = 5;
private static int ECONOMY_CLASS_NUM_SEATS = 5;
// You can have just on array for 10 seats if you prefer
private Boolean[] tseats = new Boolean[(FIRST_CLASS_NUM_SEATS + ECONOMY_CLASS_NUM_SEATS)];
private static Boolean[] fseats = new Boolean[FIRST_CLASS_NUM_SEATS];
// FIRST class seats
private static Boolean[] eseats = new Boolean[ECONOMY_CLASS_NUM_SEATS];
// ECONOMY class seats
public static Boolean IsFirstClassAvailable() {
for (int i = 0; (i < 5); i++) {
if ((fseats[i] == false)) {
return true;
}
}
return false;
}
public static Boolean IsEconomyClassAvailable() {
for (int i = 5; (i < 10); i++) {
if ((eseats[i] == false)) {
return true;
}
}
return false;
}
public Boolean[] GetAllSeats() {
Boolean[] c = new Boolean[(FIRST_CLASS_NUM_SEATS + ECONOMY_CLASS_NUM_SEATS)];
int i;
for (i = 0; (i < FIRST_CLASS_NUM_SEATS); i++) {
c[i] = fseats[i];
for (int j = 0; (j < ECONOMY_CLASS_NUM_SEATS); j++) {
c[i++] = eseats[j];
}
}
return c;
}
public static Boolean[] GetFirstClassSeats() {
Boolean[] arr = new Boolean[5];
for (int i = 0; (i < 5); i++) {
arr[i] = fseats[i];
if ((fseats[i] == false)) {
System.out.print("X ");
}
else {
System.out.print("- ");
}
}
return arr;
}
public static Boolean[] GetEconomyClassSeats() {
Boolean[] arr = new Boolean[5];
for (int i = 5; (i < 10); i++) {
arr[i] = eseats[i];
}
return arr;
}
public static int ReserveFirstClassAnySeat() {
if (Reservation.IsFirstClassAvailable()) {
Reservation.GetFirstClassSeats();
}
return 0;
}
public static int ReserveEconomyClassAnySeat() {
if (Reservation.IsEconomyClassAvailable()) {
for (int i = 5; (i < 10); i++) {
if ((eseats[i] == false)) {
eseats[i] = true;
return 1;
}
}
}
return 0;
}
public static void main(String[] args) {
Reservation.init();
System.out.println("1. Reserve First Class 2. Reserve Economy Class 3. Exit");
Scanner s = new Scanner(System.in);
int choice = s.nextInt();
if ((choice == 1)) {
// Boolean[] arr = GetFirstClassSeats();
Reservation.ReserveFirstClassAnySeat();
}
else if ((choice == 2)) {
// Boolean[] arr = GetEconomyClassSeats();
Reservation.ReserveEconomyClassAnySeat();
}
else {
Reservation.main(args);
}
}
static void init() {
for (int i = 0; (i < 5); i++) {
fseats[i] = false;
}
for (int i = 0; (i < 5); i++) {
eseats[i] = false;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.