クラス Library{} と Book{} を含むパッケージ mylib を作成しています。
ライブラリ クラス:
package mylib;
import java.util.*;
class Library {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Book[] MyBooks = new Book[3];
Book x;
MyBooks[0] = new Book("The Lover's Dictionary", "Levithan, D.", 211, "AVAILABLE");
MyBooks[1] = new Book("White Tiger", "Adiga, A.", 304, "AVAILABLE");
MyBooks[2] = new Book("Thirteen R3asons Why", "Asher, J.", 336, "AVAILABLE");
System.out.println("\n***** BOOK LISTING *****");
for(int i = 0; i < MyBooks.length; i++) {
x = MyBooks[i];
System.out.println("[" + (i + 1) + "] " + x.sTitle + "\nAuthor: " +
x.sAuthor + "\nPages: " + x.iPages + "\nStatus: " + Book.AVAILABLE);
System.out.print("\r\n");
}
System.out.println("***** SELECT ACTION *****");
System.out.println("B - Borrow a book");
System.out.println("R - Reserve a book");
System.out.println("I - Return a book");
System.out.println("X - Exit program");
System.out.print("\nEnter command: ");
char cAction = input.nextLine().charAt(0); // Read single char
switch(cAction) {
case 'B':
break;
case 'R':
break;
case 'I':
break;
case 'X':
Book book = new Book();
book.exitProgram();
break;
default:
System.out.println("INVALID INPUT!");
break;
}
}
}
ブッククラス:
package mylib;
class Book {
int iPages;
String sTitle, sAuthor;
String sBorrowedBy, sReservedBy;
String sDueDate, sReturnDate;
String sStatus;
public static final String BORROWED = "BORROWED", AVAILABLE = "AVAILABLE", RESERVED = "RESERVED";
// Constructor
public Book(String title, String author, int pages, String status) {
this.sTitle = title;
this.sAuthor = author;
this.iPages = pages;
this.sStatus = status;
}
/*
void borrowBook() {
}
void reserveBook() {
}
void returnBook() {
}
*/
void exitProgram() {
System.exit(0);
}
}
クラスでは、クラスからメソッドLibrary
を呼び出すスイッチを介してプログラムを終了しようとしています。1 個のエラーが表示されますexitProgram()
Book
constructor x in class x...
どんな助けでも大歓迎です。