السلام عليكم و رحمة الله وبركاته ...
اولاً :: أعتذر عن تجاوزي للقوانين في الموضوع السابق ... وأعد بأن لا يتكرر ذلك الشي / :)
والان ... وبعد عمل البرنامج كامل ... وظهور المخرجات / لم يتبق سوى فقرة واحد فقط أحتاج للمساعده فيها بعد إذنكم
البرنامج عباره عن قريه صغيرة .. بها مكتبتان .. المكتبه الأولى بها 4 من الكتب والمكتبه الثانيه خالية
البرنامج يجب ان يبحث في الكتب ليتيح للزبون استعارة كتاب اذا كان لم يستعار من قبل ... وارجاع الكتاب .. وطباعة الكتب المتوفرة " اي التي لم تستعار "
الملف الأول :
اقتباسpublic class Book
{
String title; // variable type string " array of char "
boolean borrowed; // variable with type boolean " true or false , zero and one "
Book() { // zero argument constrocure
title = null;
borrowed = false ;
}
// Creates a new Book
public Book(String bookTitle) // constructor with arguments'
{
title = bookTitle;
borrowed = false ;
}
// Marks the book as rented
public void borrowed(String bookTitle) {
borrowed = true ;
}
// Marks the book as not rented
public void returned()
{
borrowed = false ;
}
// Returns true if the book is rented, false otherwise
public boolean isBorrowed() {
if ( borrowed == true )
return true ;
else
return false ;
}
// function i found it call in the main , when the book is borrowed it will be = to true
public void retnted ()
{
borrowed = true ;
}
// Returns the title of the book
public String getTitle() { // get method for the title
return title ;
}
الملف الثاني :
اقتباسpublic class Library // new class
{
String adress;
int counter;
Book arraybooks[] = new Book[5]; // an array of type book which is a class with a MAXIMUM size 5
private Library(String LibraryAdress) { // .... constructor with argument
adress = LibraryAdress;
counter = 0;
for (int i = 0; i < arraybooks.length; i++) { // to make the array !
arraybooks = new Book();
}
}
private void Library() { // zero argument constructor
adress = null;
counter = 0;
for (int i = 0; i < arraybooks.length; i++) {
arraybooks = new Book();
}
}
static void printOpeningHours() // function prints the Library hours
{
System.out.println(" Libraries are open daily from 9am to 5pm");
}
public void printAvailableBooks() // function to print the available books " which is not borrowed "
{ if ( counter == 0 )
System.out.println("No book in catalog"); // if there is no book print this !
else
{
for ( int n=0 ; n<counter;n++) // search in all the aray
{
if (arraybooks[n].isBorrowed()) // if the function isBorrowed return true DO NOTHING ;
;
else
System.out.println(arraybooks[n].getTitle());// IF THE FUNCTION ISBORROWED RETURN FAALES PRINT THE NAME OF THE BOOK;
}
}
}
public void borrowBook(String bookTitle) // Function to marke the book as borrow
{
for ( int j=0 ;j<counter; j++ )
{
if (bookTitle.equals(arraybooks[j].getTitle()))
{
if ( arraybooks[j].isBorrowed()) // if it's already borrowed print the statment below
System.out.println("Sorry, this book is already borrowed");
else
{
arraybooks[j].borrowed(bookTitle); // if it's not borrowed marke it as abrrowed and print the statment below
System.out.println("You successfully borrowed"+bookTitle);
}
}
else // if you did not find it print this ,
System.out.println("Sorry, this book is not in our catalog.");
}
}
public void printAddress() // print the argument which we put it in the constructor and give it an initial value when i make the object .
{
System.out.println(adress);
}
// this function search about the book Title and make it as available instead of borrowed
public void returnBook(String bookTitle)
{
for ( int j=0 ;j<counter; j++ )
{
if (bookTitle.equals(arraybooks[j].getTitle()))
{
arraybooks[j].returned();
System.out.println("You successfully returned"+ bookTitle);
}
}
}
private void addBook(Book newbook) { // function to add new books
arraybooks[counter] = newbook;
counter++;
}
/// main ---------------------------------------------------------------------------------------
public static void main(String[] args) {
// Create two libraries
Library firstLibrary = new Library("10 Main St.");
Library secondLibrary = new Library("228 Liberty St.");
// Add four books to the first library
firstLibrary.addBook(new Book("The Da Vinci Code"));
firstLibrary.addBook(new Book("Le Petit Prince"));
firstLibrary.addBook(new Book("A Tale of Two Cities"));
firstLibrary.addBook(new Book("The Lord of the Rings"));
// Print opening hours and the addresses
System.out.println("Library hours:");
printOpeningHours();
System.out.println();
System.out.println("Library addresses:");
firstLibrary.printAddress();
secondLibrary.printAddress();
System.out.println();
// Try to borrow The Lords of the Rings from both libraries
System.out.println("Borrowing The Lord of the Rings:");
firstLibrary.borrowBook("The Lord of the Rings");
firstLibrary.borrowBook("The Lord of the Rings");
secondLibrary.borrowBook("The Lord of the Rings");
System.out.println();
// Print the titles of all available books from both libraries
System.out.println("Books available in the first library:");
firstLibrary.printAvailableBooks();
System.out.println();
System.out.println("Books available in the second library:");
secondLibrary.printAvailableBooks();
System.out.println();
// Return The Lords of the Rings to the first library
System.out.println("Returning The Lord of the Rings:");
firstLibrary.returnBook("The Lord of the Rings");
System.out.println();
// Print the titles of available from the first library
System.out.println("Books available in the first library:");
firstLibrary.printAvailableBooks();
}
}
في الملف الثاني ... يوجد داله بأسم borrowBook وهي تبحث عن كتاب معين ... وهذا الكتاب هناك من يريد استعارته
لو كان الكتاب مستعار مسبقاً تطبع جمله ان الكاتب مستعار .. نعتذر
لو لم يكن مستعار مسبقاً تجعله مستعار وتطبع جمله انه تم استعارة الكتاب بنجاح
واذا لم يكن موجود في المكتبه تطبع جمله ان الكتاب غير موجود في المكتبه
لقد كتبت جميع ماذكر ولكن مازال هناك خطأ في المخرجات ... هل من يستطيع المساعده الأن ؟
بناء على ما كتبت في الـ main
يجب ان تكون المخرجات هكذا لهذه الداله :
Borrowing, The Lord of the Rings:
You successfully borrowed The Lord of the Rings
Sorry, this book is already borrowed.
Sorry, this book is not in our catalog.
وليس كما هو الأن :
Sorry, this book is not in our catalog.
Sorry, this book is not in our catalog.
Sorry, this book is not in our catalog.
You successfully borrowedThe Lord of the Rings
Sorry, this book is not in our catalog.
Sorry, this book is not in our catalog.
Sorry, this book is not in our catalog.
Sorry, this book is already borrowed
شكراً مقدماً ... وأعتذر مره أخرى / اتمنى ان لا اكون قد ارتكبت اي اخطاء في هذا الموضوع :) :)