covert this code to GUI

covert this code to GUI

import java.util.*;

class Author{

public String name;

public BookList<Book>books=new BookList<Book>();

public Author(){


}

public boolean equals(Object node){

return name.equals(((Author)node).name);


}

public void display(){

System.out.println(name);

books.display();


}

}

class Book {

public String title;

public Patron patron=null;

public Book(){


}

public boolean equals(Object node){

return title.equals(((Book)node).title);

}

public String toString(){

return " *"+title+(patron !=null?" -checked out to " +patron.name:"")+ "\n";

}

}

class CheckedOutBook{

public Author author= null;

public Book book=null;

public CheckedOutBook(){


}

public boolean equals(Object node){

return book.title.equals(((CheckedOutBook)node).book.title)&& 

author.name.equals(((CheckedOutBook)node).author.name);


}

public String toString(){

return " *"+author.name+","+book.title+"\n";


}

}

class Patron {

public String name;

public BookList<CheckedOutBook>books=new BookList<CheckedOutBook>();

public Patron (){


}

public boolean equals(Object node){

return name.equals(((Patron)node).name);

}

public void display(){

if(!books.isEmpty()){

System.out.println(name + "has the following books:");

books.display();


}

else System.out.println(name+ "has no books ");


}

} 

class AuthorList extends LinkedList<Author>{

static final long serialVersionUID=123;

public AuthorList(){

super();

}

public void display(){

Object[] authors=toArray();

for(int i=0;i<authors.length;i++)

((Author)authors[i]).display();

}

}

class BookList<T> extends LinkedList<T>{

static final long serialVersionUID=124;

public BookList(){

super();

}

public void display(){

for(int i = 0; i<size();i++)

System.out.println(get(i));

}

}

class PatronList extends LinkedList<Patron>{

static final long serialVersionUID=125;

public PatronList(){

super();

}

public void display(){

for(java.util.Iterator it = iterator();it.hasNext(););


}

}


class Library{

private ArrayList<AuthorList>

catalog= new ArrayList<AuthorList>('z'+1);

private ArrayList<PatronList>

people= new ArrayList<PatronList>('z'+1);

private String input;

Scanner kb= new Scanner(System.in);

public Library(){

for(int i =0; i<='z';i++){

catalog.add(i, new AuthorList());

people.add(i, new PatronList());


}


}

private String getString(String msg){

System.out.print(msg + " ");

System.out.flush();

input= kb.nextLine();

return input.substring(0,1).toUpperCase()+input.substring(1);

}

private void status(){

System.out.println("Library has the following books:\n ");

for(int i='A';i <='z';i++)

if (catalog.get(i).size()>0)

catalog.get(i).display();

}

private void includeBook(){

Author newAuthor= new Author();

int oldAuthor;

Book newBook= new Book();

newAuthor.name=getString("Enter Author's name: ");

newBook.title=getString("Enter the title of the book: ");

oldAuthor=catalog.get(newAuthor.name.charAt(0)).indexOf(newAuthor);

if(oldAuthor==-1){

newAuthor.books.add(newBook);

catalog.get(newAuthor.name.charAt(0)).add(newAuthor);

}

else( catalog.get(newAuthor.name.charAt(0)).get(oldAuthor)).

books.add(newBook);


}

private void checkedOutBook(){

Patron patron= new Patron(), patronRef;

Author author= new Author(), authorRef= new Author();

Book book= new Book();

int patronIndex, bookIndex= -1, authorIndex=-1;

patron.name=getString("Enter patron's names:");

while(authorIndex==-1){

author.name= getString("Enter author's name:");

authorIndex= catalog.get(author.name.charAt(0)).indexOf(author);

if(authorIndex==-1)

System.out.println("Misspelled author's name");


}

while(bookIndex==-1){

book.title=getString("Enter the title of the book: ");

authorRef=catalog.get(author.name.charAt(0)).get(authorIndex);

bookIndex=authorRef.books.indexOf(book);

if(bookIndex==-1)

System.out.println("Misspelled title:");

}

Book bookRef= authorRef.books.get(bookIndex);

CheckedOutBook bookToCheckOut=new CheckedOutBook();

bookToCheckOut.author=authorRef;

bookToCheckOut.book=bookRef;

patronIndex=people.get(patron.name.charAt(0)).indexOf(patron);

if(patronIndex==-1){

patron.books.add(bookToCheckOut);

people.get(patron.name.charAt(0)).add(patron);

bookRef.patron=people.get(patron.name.charAt(0)).getFirst();

}

else{

patronRef=people.get(patron.name.charAt(0)).get(patronIndex);

patronRef.books.add(bookToCheckOut);

bookRef.patron=patronRef;

}

}

private void returnBook(){

Patron patron=new Patron();

Book book= new Book();

Author author=new Author(),authorRef=new Author();

int patronIndex=-1 ,authorIndex=-1,bookIndex=-1;

while(patronIndex == -1){

patron.name=getString("Enter patron's name:");

patronIndex=people.get(patron.name.charAt(0)).indexOf(patron);

if(patronIndex==-1)

System.out.println("Patron's name misspelled");

}

while(authorIndex==-1){

author.name=getString("Enter author's name: ");

authorIndex=catalog.get(author.name.charAt(0)).indexOf(author);

if(authorIndex==-1)

    System.out.println("Patron's name misspelled");

    }


while(bookIndex==-1){

    book.title=getString("Enter the title of the book: ");

    authorRef=catalog.get(author.name.charAt(0)).get(authorIndex);

    bookIndex=authorRef.books.indexOf(book);

    if(bookIndex==-1)

    System.out.println("Misspelled title:");


    }

CheckedOutBook checkedOutBook=new CheckedOutBook();

checkedOutBook.author=authorRef;

checkedOutBook.book=authorRef.books.get(bookIndex);

(authorRef.books.get(bookIndex)).patron=null;

(people.get(patron.name.charAt(0)).get(patronIndex)).

books.remove(checkedOutBook);

}

public void run(){

while(true){

char option=getString("\nEnter one of the following options:\n"+"1. Include a book in the 

catalog\n"+"2. Check Out a Book\n"+"3. Return a Book\n"+"4. Status\n"+"5. Exit\n"+"Your 

Option:").charAt(0);

switch(option){

case'1': includeBook(); break;

case'2': checkedOutBook(); break;

case'3': returnBook(); break;

case'4': status(); break;

case'5': return; 

default: System.out.println("Wrong option, try again");

}

}

}

public static void main(String[]args){

(new Library()).run();

}

}
View Answers









Related Tutorials/Questions & Answers:
covert this code to GUI
covert this code to GUI  import java.util.*; class Author{ public String name; public BookList<Book>books=new BookList<Book>(); public Author(){ } public boolean equals(Object node){ return
covert this code to GUI
covert this code to GUI  import java.util.*; class Author{ public String name; public BookList<Book>books=new BookList<Book>(); public Author(){ } public boolean equals(Object node){ return
Advertisements
Convert the code to GUI
GUI code  GUI code
Convert the code to GUI
GUI Example  GUI Example code to learn
Convert the code to GUI
How to Convert the code to GUI   How to convert a code into GUI
Convert the code to GUI
Java Code to GUI   can any one convert My code to GUI code
how to covert JPG format to Binary formart using java code..
how to covert JPG format to Binary formart using java code..  convert JPG format to Binary formart How can i convert JPG format to Binary format using java code plz help me out
Convert the code to GUI
Convert the code   How to convert a code to GUI look alike
Convert the code to GUI
Is it possible to convert a code into GUI  Is it possible to convert a code into GUI
Convert the code to GUI
GUI Application example  GUI Application example
Convert the code to GUI
Java GUI Class Example  Java GUI Class Example
Convert the code to GUI
GUI Java JSP application  GUI Java JSP application
Convert the code to GUI
GUI Application Development   GUI Application Development
Convert the code to GUI
Java and GUI application Example  Java and GUI application Example
Convert the code to GUI
Write a GUI Application  best way to write a GUI based application
Convert the code to GUI
How to create GUI application in Java   How to create GUI application in Java
Java GUI code
Java GUI code  Write a GUI program to compute the amount of a certificate of deposit on maturity. The sample data follows: Amount deposited... the following code: import java.awt.*; import javax.swing.*; import java.awt.event.
Convert the code to GUI ??
Convert the code to GUI ??  hi >> can anyone help me to conver this code to GUI ?? /** * @(#)RegistorClass.java * *. * @author...("*** Invalid operation code ***"); halt= true; // break
Convert the code to GUI
Convert the code to GUI   can any one convert My code to GUI code...: System.out.println("*** Invalid operation code... ??? System.out.println(); } } `print("code sample");` thanks
Convert the code to GUI
GUI example for beginners  GUI example for beginners  sory ,, I will posted my code again import java.util.Scanner; public class...; default: System.out.println("*** Invalid operation code
HOW TO CONVERT THIS CODE INTO GUI
HOW TO CONVERT THIS CODE INTO GUI   System.out.println("\n\t UGANDA CHRISTIAN UNIVERSITY\n"); System.out.println("\n\tFACULTY OF SCIENCE AND TECHNOLOGY\n"); System.out.println("\n BACHELOR OF SCIENCE IN COMPUTER
convert this code to GUI
convert this code to GUI  hello.. this is my code.. import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks
convert this code to GUI
convert this code to GUI  hello.. this is my code.. import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks
convert this code to GUI
convert this code to GUI  hello.. this is my code.. import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks
convert this code to GUI
convert this code to GUI  import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks; //"this" keyword
convert this code to GUI
convert this code to GUI  import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks; //"this" keyword
convert this code to GUI
convert this code to GUI  import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks; //"this" keyword
convert this code to GUI
convert this code to GUI  import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks; //"this" keyword
convert this code to GUI
convert this code to GUI  import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks; //"this" keyword
convert this code to GUI
convert this code to GUI  import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks; //"this" keyword
convert this code to GUI
convert this code to GUI  import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks; //"this" keyword
convert this code to GUI
convert this code to GUI  import java.util.*; class Author{ public String name; public BookList<Book>books=new BookList<Book>(); public Author(){ } public boolean equals(Object node){ return name.equals
convert this code to GUI
convert this code to GUI  import java.util.*; class Author{ public String name; public BookList<Book>books=new BookList<Book>(); public Author(){ } public boolean equals(Object node){ return name.equals
Rental Code GUI - Java Beginners
Rental Code GUI  dear sir... i would like to ask some code of java GUI form that ask the user will choose the menu to input Disk #: type: title: record company: price: director: no. of copies
Java GUI code- creating a circle
Java GUI code- creating a circle  My assignment is to write a program..., and area. I did my code but I can't seem to figure out the mathematical code...; //GUI components JLabel lClx, lCly, lCircumrx, lCircumry, lRadius
Convert this code to GUI - Java Beginners
Convert this code to GUI  I have written this.i need to convert the following code to GUI:- import java.awt.*; import java.applet.*; import...); } }  hi friend, We have convert your code into GUI
How to convert this Java code into GUI?
How to convert this Java code into GUI?   import java.util.Scanner; public class StudentMarks { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks
Catching Exceptions in GUI Code - Java Tutorials
.style1 { text-align: center; } Catching uncaught exception in GUI In this section, we will discuss how to catch uncaught exceptions in GUI. Lets see the given below code to identify the uncaught exception : import
"Urgent" convert this code to GUI - Swing AWT
"Urgent" convert this code to GUI   please convert for me this code to GUI THE CODES ARE BELOW, CLASS ATMCaseStudy is the driver class that runs all the other classes. its very urgent. //CLASS CashDispenser public class
please convert for me this code to GUI - Swing AWT
please convert for me this code to GUI    THE CODES ARE BELOW, CLASS ATMCaseStudy is the driver class that runs all the other classes. its very urgent. // class ATM import javax.swing.*; import java.awt.*; public
please convert for me this code to GUI - Swing AWT
please convert for me this code to GUI  THE CODES ARE BELOW, CLASS ATMCaseStudy is the driver class that runs all the other classes. its very urgent. // class ATM import javax.swing.*; import java.awt.*; public class ATM
Covert Bool to String - NSString
Covert Bool to String - NSString  HI, I was trying to cornet the BOOL value to NSString using following code: BOOL test = TRUE; NSString *strTest..." : @"False"; Hope the above code will help you. Check more iPhone Programming
covert the following using java
covert the following using java  how to convert (for eg : 2.89) . this decimal to binary in java
GUI
GUI  How to GUI in Net-beans ... ??   Please visit the following link: http://www.roseindia.net/java/java-tips/background/30java_tools/netbeans.shtml
GUI
GUI  Write a GUI application for the WebBuy Company that allows a user to compose the three parts of a complete email message: the â??To:â??, â??Subject:â?? and â??Message:â?? text. The â??To:â??, and â??Subject:â?? Text areas
How to solve this java code by adding the student marks not in the list of the table. For example -10 and 156 in GUI?
How to solve this java code by adding the student marks not in the list of the table. For example -10 and 156 in GUI?  import java.awt.*; import javax.swing.*; import java.awt.event.*; public class MarkStudent { double
gui question
gui question  design a gui application for me and write its code in which the user enters a no. in a textfield and onn clicking the button the sum of the digits of the no. should be displayed. hint: suppose the user enters 12
GUI framework
GUI framework  what do u mean by GUI framework
java gui
java gui   friends... good day.. i have doubt in java gui. ? i created 1 java gui application. That has two text fields jtext1,jtext2. case: user... must go to the next text field(jtext2). How can i arrange this. which code can i
GUI component
GUI component  How can a GUI component handle its own events

Ads