Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

COSC 2 1 5 : Homework # 2 Write a simple airline ticket reservation program. The program should display a menu with the following options:

COSC 215: Homework #2
Write a simple airline ticket reservation program. The program should display a menu with the following options: reserve a ticket, cancel a reservation, check whether a ticket is reserved for a particular person, display the passengers, and exit the program. The information should be
maintained on an alphabetized linked list of names that uses the Linked List implementation that we wrote together in class.
Although you are permitted to include additional classes as you see fit, you must at minimum create a class named HW2 where is your last name and use this as the class in which you write your main method. For example, if I were doing this assignment, my
class be named BerdikHW2. Violating this naming convention will result in a two-point
deduction from your grade.
Your work must be submitted on Canvas by the specified due date. Since your submissions will
be tested using the LinkedList implementation that we wrote together, you should not modify it
and there is no need for you to include it in your Canvas submission. SLL.java CLASS public class SLL {
SLLNode head, tail;
void insertAtHead(T t){
if (head == null){
head = new SLLNode(t);
tail = head;
}
else {
SLLNode newHead = new SLLNode(t, head);
head = newHead;
}
}
void insertAtTail(T t){
if (tail == null){
tail = new SLLNode(t);
head = tail;
}
else {
SLLNode newTail = new SLLNode(t);
tail.next = newTail;
tail = newTail;
}
}
T deleteFromHead(){
if (head == null){// If this list is empty
return null;
}
T headInfo = head.info;
head = head.next;
if (head == null){
tail = null;
}
return headInfo;
}
T deleteFromTail(){
if (tail == null){// If the list is empty
return null;
}
T tailInfo = tail.info;
if (head == tail){// If the list only has one node
head = null;
tail = null;
return tailInfo;
}
SLLNode newTail = null;
for (SLLNode node = head; node.next != null; node = node.next){
newTail = node;
}
newTail.next = null;
tail = newTail;
return tailInfo;
} SLLNode.java class public class SLLNode {
T info;
SLLNode next;
public SLLNode(T info, SLLNode next){
this.info = info;
this.next = next;
}
public SLLNode(T info){
this.info = info;
next = null;
}
public SLLNode(){
info = null;
next = null;
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Different formulas for mathematical core areas.

Answered: 1 week ago

Question

Organize and support your main points

Answered: 1 week ago

Question

Move smoothly from point to point

Answered: 1 week ago

Question

Outlining Your Speech?

Answered: 1 week ago