ami0714
asked on
Queue
?
ASKER
ASKER
Oh my...my question gone
ASKER
CEHJ,
I'm not sure how to modify the code so that this CustomerOrder thing will work out. Perhaps you can give me some clues after seeing my code.
//QueueReference(currently only queue for Customer)
public class QueueReference implements QueueInterface{
private Customer front;
private Customer rear;
public QueueReference(){
front=null;
rear=null;
}
public boolean isEmpty(){
return front==null;
}
public void dequeueAll(){
front=null;
}
public void enqueue(Customer newCustomer){
Customer newCus = newCustomer;
if(isEmpty()){
front = newCus;
rear = newCus;
}
else{
rear.setNext(newCus);
rear = newCus;
}
}
public Customer dequeue()throws QueueException{
if(!isEmpty())
{
Customer deqCus = front;
if(front==rear)
{
front=null;
rear=null;
}
else
{
front=front.getNext();
}
return deqCus;
}
else{
throw new QueueException("Dequeue:Qu eue is empty");
}
}
public Customer peek()throws QueueException{
if(!isEmpty()){
return front;
}
else{
throw new QueueException("Peek: Queue is empty");
}
}
}
I'm not sure how to modify the code so that this CustomerOrder thing will work out. Perhaps you can give me some clues after seeing my code.
//QueueReference(currently
public class QueueReference implements QueueInterface{
private Customer front;
private Customer rear;
public QueueReference(){
front=null;
rear=null;
}
public boolean isEmpty(){
return front==null;
}
public void dequeueAll(){
front=null;
}
public void enqueue(Customer newCustomer){
Customer newCus = newCustomer;
if(isEmpty()){
front = newCus;
rear = newCus;
}
else{
rear.setNext(newCus);
rear = newCus;
}
}
public Customer dequeue()throws QueueException{
if(!isEmpty())
{
Customer deqCus = front;
if(front==rear)
{
front=null;
rear=null;
}
else
{
front=front.getNext();
}
return deqCus;
}
else{
throw new QueueException("Dequeue:Qu
}
}
public Customer peek()throws QueueException{
if(!isEmpty()){
return front;
}
else{
throw new QueueException("Peek: Queue is empty");
}
}
}
ASKER
//Customer
public class Customer {
private String cusName;
private String cusAddress;
private int cusID;
private String cusTel;
private int deposit;
private Customer next;
public Customer(){
cusName="";
cusAddress="";
cusID=0;
cusTel="";
deposit=0;
}
public void setCusName(String name){
cusName=name;
}
public void setCusAddress(String address){
cusAddress=address;
}
public void setCusID(int ID){
cusID=ID;
}
public void setCusTel(String tel){
cusTel=tel;
}
public void setDeposit(int dep){
deposit=dep;
}
public void setNext(Customer Cus){
next=Cus;
}
String getCusName(){
return cusName;
}
String getCusAddress(){
return cusAddress;
}
int getCusID(){
return cusID;
}
String getCusTel(){
return cusTel;
}
int getDeposit(){
return deposit;
}
Customer getNext(){
return next;
}
}
//Book
public class Book{
private String bookName;
private String author;
private String publisher;
private int bookID;
private String status;
private Book next;
public Book(){
bookName="";
author="";
publisher="";
bookID=0;
}
public void setBookName(String bookname){
bookName=bookname;
}
public void setAuthor(String aut){
author=aut;
}
public void setPublisher(String pub){
publisher=pub;
}
public void setBookID(int ID){
bookID=ID;
}
public void setStatus(String stat){
status=stat;
}
public void setNext(Book Bk){
next=Bk;
}
String getBookName(){
return bookName;
}
String getAuthor(){
return author;
}
String getPublisher(){
return publisher;
}
int getBookID(){
return bookID;
}
String getStatus(String stat){
return status;
}
Book getNext(){
return next;
}
}
public class Customer {
private String cusName;
private String cusAddress;
private int cusID;
private String cusTel;
private int deposit;
private Customer next;
public Customer(){
cusName="";
cusAddress="";
cusID=0;
cusTel="";
deposit=0;
}
public void setCusName(String name){
cusName=name;
}
public void setCusAddress(String address){
cusAddress=address;
}
public void setCusID(int ID){
cusID=ID;
}
public void setCusTel(String tel){
cusTel=tel;
}
public void setDeposit(int dep){
deposit=dep;
}
public void setNext(Customer Cus){
next=Cus;
}
String getCusName(){
return cusName;
}
String getCusAddress(){
return cusAddress;
}
int getCusID(){
return cusID;
}
String getCusTel(){
return cusTel;
}
int getDeposit(){
return deposit;
}
Customer getNext(){
return next;
}
}
//Book
public class Book{
private String bookName;
private String author;
private String publisher;
private int bookID;
private String status;
private Book next;
public Book(){
bookName="";
author="";
publisher="";
bookID=0;
}
public void setBookName(String bookname){
bookName=bookname;
}
public void setAuthor(String aut){
author=aut;
}
public void setPublisher(String pub){
publisher=pub;
}
public void setBookID(int ID){
bookID=ID;
}
public void setStatus(String stat){
status=stat;
}
public void setNext(Book Bk){
next=Bk;
}
String getBookName(){
return bookName;
}
String getAuthor(){
return author;
}
String getPublisher(){
return publisher;
}
int getBookID(){
return bookID;
}
String getStatus(String stat){
return status;
}
Book getNext(){
return next;
}
}
ASKER
Sorry for have to post it in 2 part
Simply do a find/replace on your code, replacing Customer in the queue class by CustomerOrder. The customer order is created with an instance of Customer and an instance of Book
ASKER
Should I make both Customer & Book extends the CustomerOrder, like this
public class Book extends CustomerOrder{}
public class Customer extends CustomerOrder{}
public class Book extends CustomerOrder{}
public class Customer extends CustomerOrder{}
No. CustomerOrder is just a container for a Book and a Customer.
ASKER
So both the Customer class and Book class are remain the same, what about the main program like the one I post earlier,
try{
readFile=input.readLine();
while(readFile!=null) {
name= input.readLine();
address = input.readLine();
readFile=input.readLine();
ID = Integer.valueOf(readFile). intValue() ;
tel = input.readLine();
readFile=input.readLine();
dep = Integer.valueOf(readFile). intValue() ;
Customer readCus = new Customer();
readCus.setCusName(name);
readCus.setCusAddress(addr ess);
readCus.setCusID(ID);
readCus.setCusTel(tel);
readCus.setDeposit(dep);
menu.enqueue(readCus);
readFile=input.readLine();
}
inputFile.close();
}
Should I change this
Customer readCus = new Customer() ==> CustomerOrder readCus = new CustomerOrder()
or keep it in the same way?
try{
readFile=input.readLine();
while(readFile!=null) {
name= input.readLine();
address = input.readLine();
readFile=input.readLine();
ID = Integer.valueOf(readFile).
tel = input.readLine();
readFile=input.readLine();
dep = Integer.valueOf(readFile).
Customer readCus = new Customer();
readCus.setCusName(name);
readCus.setCusAddress(addr
readCus.setCusID(ID);
readCus.setCusTel(tel);
readCus.setDeposit(dep);
menu.enqueue(readCus);
readFile=input.readLine();
}
inputFile.close();
}
Should I change this
Customer readCus = new Customer() ==> CustomerOrder readCus = new CustomerOrder()
or keep it in the same way?
You should change
menu.enqueue(readCus);
to
menu.enqueue(new CustomerOrder(readCus,book ));
but the problem is - where is your Book?
menu.enqueue(readCus);
to
menu.enqueue(new CustomerOrder(readCus,book
but the problem is - where is your Book?
ASKER
That part of codes is only about Customer, I have other parts concern about both objects.
Now I have problem in peek() & dequeue().
Customer C = menu.dequeue();
Customer C = menu.peek();
it says incompatible types. Could you help me change it too?
Now I have problem in peek() & dequeue().
Customer C = menu.dequeue();
Customer C = menu.peek();
it says incompatible types. Could you help me change it too?
CustomerOrder co = menu.dequeue();
CustomerOrder co = menu.peek();
CustomerOrder co = menu.peek();
ASKER
This time it says cannot resolve symbol.
here's one of the error.
Menu.java:302: cannot resolve symbol
symbol : method getCusAddress ()
location: class CustomerOrder
output.println(C.getCusAdd ress());
^
here's one of the error.
Menu.java:302: cannot resolve symbol
symbol : method getCusAddress ()
location: class CustomerOrder
output.println(C.getCusAdd
^
ASKER
oops...the error should look like this one
Menu.java:302: cannot resolve symbol
symbol : method getCusAddress ()
location: class CustomerOrder
output.println(C.getCusAdd ress());
^
Menu.java:302: cannot resolve symbol
symbol : method getCusAddress ()
location: class CustomerOrder
output.println(C.getCusAdd
^
ASKER
output.println(C.getCusAdd ress());
^
^
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
urgh...
the arrows points to the dot in C.getCusAddress()
the arrows points to the dot in C.getCusAddress()
Well i'm taking it that 'C' is variable holding a reference to a CustomerOrder object. Is that right?
ASKER
Great, it works now. you have end my suffer, another one. thanks pal! hohoho...
since the solution comes in many part of the comment, so I'll accept one of the comment as answer.
since the solution comes in many part of the comment, so I'll accept one of the comment as answer.
Glad you've got it sorted out. For good coding practices, this cheap little pocket book is valuable:
http://www.amazon.co.uk/exec/obidos/ASIN/0521777682/proteanit-20
http://www.amazon.co.uk/exec/obidos/ASIN/0521777682/proteanit-20