I am having small problems in my exercise of data. Here is the topic:
1.Input data Allow a user to input booking item. When running, the screen looks like: Enter bus code: Enter customer code: Enter number of seats to be booked:
After the user enter bcode and ccode, the program check and acts as follows: - If bcode not found in the Bus list or ccode not found in the customer list then data is not accepted. - If both bcode and ccode are found in the booking list then data is not accepted. - If bcode and ccode found in Buses and customers lists but booked = seat then inform the user that the bus is exhausted. - If bcode or ccode found and in the Bus list booked < seat and k is the entered seat then if k <= seat - booked then data is accepted and added to the end of the Booking list.
Somebody help me. please! < My problem is class BookingList - Booking input and maybe you can use function searchByCode >
Here is my code:
public class Booking {
Customer c;
Bus b;
public Booking()
{
}
public Booking(Customer c, Bus b) {
this.c = c;
this.b = b;
}
}
public class Bus {
public String bCode;
public String bName;
public int seat;
public int booked;
public double departTime;
public double arrivalTime;
public Bus() {
}
public Bus(String bCode, String bName, int seat, int booked, double departTime,
double arrivalTime) { this.bCode = bCode; this.bName = bName; this.seat = seat; this.booked = booked; this.departTime = departTime; this.arrivalTime = arrivalTime; }
public double travelTime() {
double result = 0;
result = this.arrivalTime - this.departTime;
return result;
}
@Override
public String toString() {
return " " + bCode + "\t\t" + bName + "\t\t" + seat + "\t\t" + booked + "\t\t" + departTime + "\t\t" + arrivalTime;
}
}
public class Customer {
public String cCode;
public String cName;
public int phone;
public Customer()
{
}
public Customer(String cCode, String cName, int phone) {
this.cCode = cCode;
this.cName = cName;
this.phone = phone;
}
public void displayInfoCustomer() {
System.out.printf("%-15s %-15s %-10s\n", cCode, cName, phone);
}
@Override
public String toString() {
return " " + cCode + "\t\t" + cName + "\t\t" + phone;
}
}
*/ public class BookingList {
Customer infoC;
Bus infoB;
NodeBooking head, tail;
CusList cusList = new CusList();
BusList busList = new BusList();
public boolean isEmpty() {
return (head == null);
}
public void addLast(Customer c, Bus b) {
NodeBooking p = new NodeBooking(c, b);
if (isEmpty()) {
head = tail = p;
} else {
tail.next = p;
tail = p;
}
}
public void visit(NodeBooking p) {
if (p != null) {
System.out.print(p.infoC + "\t\t");
System.out.print(p.infoB);
System.out.println();
}
}
public Booking input() {
Validation v = new Validation();
String cCode, bCode;
int seat;
Scanner in = new Scanner(System.in);
Customer cus = new Customer();
Bus bus = new Bus();
// HERE IS MY PROBLEM
Booking x = new Booking( ?, ?);
return x;
}
public void traversal() {
NodeBooking p = head;
while (p != null) {
visit(p);
p = p.next;
}
System.out.println("");
}
}
public class BusList {
NodeBus head, tail;
public BusList() {
head = tail = null;
}
public boolean isEmpty() {
return (head == null);
}
public void clear() {
head = tail = null;
}
//search by bcode
public NodeBus searchByBcode(String bcode) {
NodeBus p = head;
while (p != null) {
if (p.info.bCode.equals(bcode)) {
return p;
}
p = p.next;
}
return null;
}
// delete fist
public void deleFist() {
if (isEmpty()) {
return;
}
head = head.next;
if (head == null) {
tail = null;
}
System.out.println("dele sucess");
}
// dele by bcode
public void deleByBcode(String Bcode) {
NodeBus q = searchByBcode(Bcode);
dele(q);
}
}
public class CusList {
NodeBus head, tail;
public CusList() {
head = tail = null;
}
public boolean isEmpty() {
return (head == null);
}
public void clear() {
head = tail = null;
}
//search by bcode
public NodeCus searchByBcode(String ccode) {
NodeCus p = head;
while (p != null) {
if (p.info.bCode.equals(ccode)) {
return p;
}
p = p.next;
}
return null;
}
// delete fist
public void deleFist() {
if (isEmpty()) {
return;
}
head = head.next;
if (head == null) {
tail = null;
}
System.out.println("dele sucess");
}
// dele by bcode
public void deleByBcode(String ccode) {
NodeCus q = searchByBcode(ccode);
dele(q);
}
}
public class NodeBooking {
Customer infoC;
Bus infoB;
NodeBooking next;
public NodeBooking() {
infoC = null;
infoB = null;
next = null;
}
public NodeBooking(Customer infoC, Bus infoB, NodeBooking next) {
this.infoC = infoC;
this.infoB = infoB;
this.next = next;
}
public NodeBooking(Customer infoC, Bus infoB) {
this(infoC, infoB, null);
}
}
public class NodeBus {
Bus info;
NodeBus next;
NodeBus() {
info = null;
next = null;
}
NodeBus(Bus info, NodeBus next) {
this.info = info;
this.next = next;
// this(info,next);
}
NodeBus(Bus info) {
this(info, null);
}
}
public class NodeCus {
Customer info;
NodeCus next;
NodeCus() {
info = null;
next = null;
}
NodeCus(Customer info, NodeCus next) {
this.info = info;
this.next = next;
// this(info,next);
}
NodeCus(Customer info) {
this(info, null);
}
}
Please help me! I am very thankful for that