좋아요, 제가 bluej를 사용하는 자바 프로젝트를하고 있습니다. 라이브러리 시스템을 작성해야합니다. 어떻게 작성합니까? 도서관 수업 시간에 새로운 회원이나 책을 만들 때 배열 목록에 추가 할 수 있습니까? 아마도 무언가는 정말 간단하지만 난 그걸 알아낼 수 없습니다.회원 번호 또는 도서관 정보를 추가 하시겠습니까?
여기 누군가가 그 잘 밖으로 설정하지 않으면 내가 사과보고 싶은 생각한다면 내 코드입니다 그러나 이것은 처음 내가 포럼에 게시 한 시간입니다 : 내가 다른 두를 할
import java.util.*;
/**
* The library class represents an enrolment list for a library. It stores
* the library name, address and members of the library, as well as the libraries opening times.
*
* @author Kelvin Goodram
* @version 2014.11.01
*/
public class Library
{
//name of library to be written as a string ("" "")
private String libraryName;
//address of library to be written as a string ("" "")
private String address;
//opening times of library to be written as a string ("" "")
private String openingTimes;
private List<Member> members;
private List<Book> books;
//the member ID to be written as a whole integer number
private int capacity;
//the member ID to be written as a whole integer number
private int bookCapacity;
//the memebers fullname to be written as a string ("" "")
private String name;
//the member ID to be written as a whole integer number
private int id;
//members contact number to be written as a string ("" "")
private String tele;
//books author to be written as a string ("" "")
private String author;
//books title to be written as a string ("" "")
private String title;
//books reference number to be written as a whole integer number
private int refNum;
//books genre to be written as a string ("" "")
private String genre;
/**
* Create a Library with an option to input a maximum number of members & books. All other details
* are set to default values.
*/
public Library(int maxNumberOfMembers, int maxNumberOfBooks)
{
libraryName = "Bolton Central Library";
address = "110-119 Le Mans Cresent Bolton BL1 1SE";
openingTimes = "Open Monday - Friday (8am-7pm)";
members = new ArrayList<Member>();
books = new ArrayList<Book>();
capacity = maxNumberOfMembers;
bookCapacity = maxNumberOfBooks;
}
/**
* Add a member to this Library.
*/
public void addMember(String fullName, String telephoneNumber)
{
// if the member capacity has been reached
if(members.size() == capacity) {
// do this
System.out.println("The Library is not currently taking new members as we are full, please enroll at a different library.");
}
//otherwise do this:
else {
name = fullName;
tele = telephoneNumber;
id = 0;
}
}
/**
* Add a book to this Library.
*/
public void addBook(String bookAuthor, String bookTitle, int bookRef, String bookGenre)
{
// if the book capacity has been reached
if(books.size() == capacity) {
//do this
System.out.println("The Library currently does not have space for new books.");
}
//otherwise do this:
else {
author = bookAuthor;
title = bookTitle;
refNum = bookRef;
genre = bookGenre;
}
}
/**
* Return the number of members currently enrolled in this Library.
*/
public int numberOfMembers()
{
return members.size(); //returns an integer number of how many members are in the arrayList <Member>
}
/**
* Return the number of books currently registered in this Library.
*/
public int numberOfBooks()
{
return books.size(); //returns an integer number of how many books are in the arrayList <Book>
}
/**
* Set the Name for this Library.
*/
public void changeLibraryName(String LibName)
{
libraryName = LibName; //enter a string value to mutate the library name
}
/**
* alter the opening times for this Library. The parameter should define the opening hour
* and the closing time, such as "open Mon - Friday: 10am - 5pm".
*/
public void changeOpeningTimes(String timeAndDayString)
{
openingTimes = timeAndDayString; //enter a string value to mutate the library opening times
}
/**
* Alter the street address of the library.
*/
public void changeAdress(String streetAddress)
{
address = streetAddress; //enter a string value to mutate the library treet address
}
/**
* Print out a member list to the standard
* terminal.
*/
public void printMemberList()
{
System.out.println("***************************"); //header
System.out.println("LibraryName " + libraryName);
System.out.println("Address:" + address);
System.out.println("Opening Times:" + openingTimes);
System.out.println("-------------------------------"); //break
System.out.println("Member list:");
for(Member member : members) {
member.print();
}
System.out.println("Number of members: " + numberOfMembers());
System.out.println("***************************"); //footer
}
/**
* Print out a book list to the standard
* terminal.
*/
public void printBookList()
{
System.out.println("***************************"); //header
System.out.println("LibraryName " + libraryName);
System.out.println("Address:" + address);
System.out.println("Opening Times:" + openingTimes);
System.out.println("-------------------------------"); //break
System.out.println("Book list:");
for(Book book : books) {
book.print();
}
System.out.println("Number of books: " + numberOfBooks());
System.out.println("***************************"); //footer
}
}
클래스 책 하나는 다음과 같습니다
/**
* A class that maintains information on a book.
*
*
* @author (Insert your name here.)
* @version (Insert today's date here.)
*/
class Book
{
// The fields.
private String author;
private String title;
private String genre;
private int refNum;
/**
* Set the author, title fields and reference number when this object
* is constructed.
*/
public Book(String bookAuthor, String bookTitle, int bookRef, String bookGenre)
{
author = bookAuthor;
title = bookTitle;
refNum = bookRef;
genre = bookGenre;
}
/**
* Print the author's name, book title, ref number and genre to the o utput terminal.
*/
public void print()
{
System.out.println("Author = " +author);
System.out.println("Title = " +title);
System.out.println("Book Reference = " +refNum);
System.out.println("This book can be found in the " +genre + " section");
System.out.println("----------------------------------------------------");
}
}
나는 내 대답을 업데이트했다. – MMrj