⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 book.java

📁 java lab4 图书馆程序 有两个class分别是book和library object book需要添加到library中
💻 JAVA
字号:
import java.io.*;
public class Book implements Cloneable{
	private String[] title;
	private int[] id;
	private float price;
	
	public Book()
	{
		for(int i=0;i<title.length;i++)
		{
			title[i]="";
		}
		for(int i=0;i<id.length;i++)
		{
			id[i]=0;
		}
		price=0;
	}
	public Book(String title_of_book,String author_of_book,int id_number,int year,float price)
	{
		title=new String[2];
		title[0]=title_of_book;
		title[1]=author_of_book;
		id=new int[2];
		id[0]=id_number;
		id[1]=year;
		this.price=price;
	}
	public String getTitle_of_book()
	{
		return this.title[0];
	}
	public void setTitle_of_book(String title_of_book)
	{
		this.title[0]=title_of_book;
	}
	public String getAuthor_of_book()
	{
		return this.title[1];
	}
	public void setAuthor_of_book(String author_of_book)
	{
		this.title[1]=author_of_book;
	}
	public int getID_number()
	{
		return this.id[0];
	}
	public void setID_number(int ID_number)
	{
		this.id[0]=ID_number;
	}
	public int getYear()
	{
		return this.id[1];
	}
	public void setYear(int year)
	{
		this.id[1]=year;
	}
	public float getPrice()
	{
		return this.price;
	}
	public void setPrice(float price)
	{
		this.price=price;
	}
	public boolean Smaller_title(Book book)
	{
		if(this.title[0].compareTo(book.title[0])<0)
			return true;
		else
			return false;
	}
	public boolean Smaller_author(Book book)
	{
		if(this.title[1].compareTo(book.title[1])<0)
			return true;
		else
			return false;
	}
	public boolean Smaller_id_number(Book book)
	{
		if(this.id[0]<book.id[0])
			return true;
		else
			return false;
	}
	public boolean Smaller_year(Book book)
	{
		if(this.id[1]<book.id[1])
			return true;
		else
			return false;
	}
	public boolean Smaller_price(Book book)
	{
		if(this.price<book.price)
			return true;
		else
			return false;
	}
	public void WriteToFile(BufferedWriter out) throws IOException
	{
		String end="\n";
		out.write(title[0]+end);
		out.write(title[1]+end);
		out.write(id[0]+end);
		out.write(id[1]+end);
		out.write(price+end);	
		
	}
	public void ReadFromFile(BufferedReader in)throws IOException 
	{
		title[0]=in.readLine();
		title[1]=in.readLine();
		id[0]=Integer.parseInt(in.readLine().trim());
		id[0]=Integer.parseInt(in.readLine().trim());
		price=Float.parseFloat(in.readLine().trim());
	}
	public Object clone()
	{
		try{
		Book cloned=(Book)super.clone();
		cloned.id=(int[])id.clone();
		cloned.title=(String[])title.clone();
		return cloned;
		}catch(CloneNotSupportedException e){}
		return null;
	}
	public String toString()
	{
		String out="";
		out +="id="+id[0]+" author:"+title[1]+"\n";
		out +="title:"+title[0]+"\n";
		out +="year="+id[1]+" price="+price+"$"+"\n";
		return out;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -