У меня небольшие проблемы с обработкой данных. Вот топи c:
1.Ввод данных Разрешить пользователю вводить элемент бронирования. При работе экран выглядит следующим образом: Введите код автобуса: Введите код клиента: Введите количество мест, которые необходимо забронировать:
После того, как пользователь введет bcode и ccode, программа проверяет и действует следующим образом: - Если bcode нет найден в списке шин или код не найден в списке клиентов, данные не принимаются. - Если в списке бронирования есть и bcode, и ccode, то данные не принимаются. - Если bcode и ccode найдены в списках автобусов и клиентов, но забронированы = места, то сообщите пользователю, что автобус исчерпан. - Если найден bcode или ccode и в списке автобусов забронировано <место, а k - введенное место, то если k <= забронировано место, то данные принимаются и добавляются в конец списка бронирования. </p>
Кто-нибудь поможет меня. пожалуйста! <Моя проблема - это класс BookingList - ввод бронирования, и, возможно, вы можете использовать функцию searchByCode>
Вот мой код:
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 прибытие / время) {this.bCode = bCode; this.bName = bName; this.seat = место; this.booked = забронировано; this.departTime = отправление; this.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;
}
}
* / publi c 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);
}
}
Пожалуйста, помогите мне! Я очень благодарен за это