class Buch
{
	String autor;
	String titel;
	String ISBN="0 0000 0000 0";
	int jahr;
	String zustand;
	String ort;
	
	public Buch()
	{
		titel = "ohne titel";
		zustand = "Neuwertig";
		ort = "Regal";
	}
	
	public Buch(String tit, String isbn)
	{
		titel = tit;
		//if (testISBN(isbn)) 
		ISBN = isbn;
		zustand = "Neuwertig";
		ort = "Regal";
	}
	
	public Buch(String aut, String tit, String isbn)
	{
		autor = aut;
		titel = tit;
		//if (testISBN(isbn)) 
		ISBN = isbn;
		zustand = "Neuwertig";
		ort = "Regal";
	}
	
	public Buch(String aut, String tit, String isbn, int ersch)
	{
		autor = aut;
		titel = tit;
		if (testISBN(isbn)) ISBN = isbn;
		jahr = ersch;
		zustand = "Neuwertig";
		ort = "Regal";
	}
	
		void ausleihen(String ausl)
	{
		ort = ausl;
	}
	
	void zurueckbekommen()
	{
		ort= "Regal";
		if(zustand.equals("Neuwertig"))
			zustand = "Gebraucht";
		else if(zustand.equals("Gebraucht"))
			zustand = "Altpapier";
	}
	
	public String toString()
	{
		String eigen = "Autor: " + autor + " , Titel: " + titel + " , ISBN: " + ISBN + " , Erscheinungsjahr: " + jahr + " , Zustand: " + zustand + " , Ort: " + ort;
		return eigen;
	}
	
	public boolean equals(Object a)
	{
		boolean test = false;
		if(a instanceof Buch)
		{
			Buch b= new Buch();
			b= (Buch) a;
			if(ISBN.equals(b.ISBN))
				test = true;
		}
		return test;
	}
	
	public String getZustand()
	{
		String get;
		get = "Zustand: " + zustand;
		return get;
	}
	
	public String getOrt()
	{
		String get;
		get = "Ort: " + ort;
		return get;
	}
	
	public String getAutor()
	{
		String get;
		get = "Autor(en): " + autor;
		return get;
	}
	
	public String getTitel()
	{
		String get;
		get = "Titel: " + titel;
		return get;
	}
	
	public String getErscheinungsjahr()
	{
		String get;
		get = "Erscheinungsjahr: " + jahr;
		return get;
	}
	
	public String getISBN()
	{
		return ""+ISBN;
	}
	
	void setZustand(String set)
	{
		zustand = set;
	}
	
	void setTitel(String set)
	{
		titel = set;
	}
	
	void setAutor(String set)
	{
		autor = set;
	}
	
	void setErscheinungsjahr(int set)
	{
		jahr = set;
	}
	
	void setOrt(String set)
	{
		ort = set;
	}
	
	void setISBN(String set)
	{
		if(testISBN(set))
			ISBN = set;
	}
	
	boolean testISBN(String isbn)
	{
		boolean isISBN = false;
		boolean lengthOK = false;
		if(isbn.length() == 13)
		{
			isbn = isbn.replaceAll(" ", "");
			if(isbn.length() ==10)
				lengthOK = true;
			else if(isbn.length() == 13)
			{
				isbn = isbn.replaceAll("-","");
				if(isbn.length() ==10)
					lengthOK = true;
			}
		}
		
		if(lengthOK == true)
		{
			int zahl = Integer.parseInt(isbn.substring(0,1)) *10;
			zahl += Integer.parseInt(isbn.substring(1,2)) *9; 
			zahl += Integer.parseInt(isbn.substring(2,3)) *8; 
			zahl += Integer.parseInt(isbn.substring(3,4)) *7; 
			zahl += Integer.parseInt(isbn.substring(4,5)) *6; 
			zahl += Integer.parseInt(isbn.substring(5,6)) *5; 
			zahl += Integer.parseInt(isbn.substring(6,7)) *4; 
			zahl += Integer.parseInt(isbn.substring(7,8)) *3; 
			zahl += Integer.parseInt(isbn.substring(8,9)) *2; 
			if(isbn.endsWith("X"))
				zahl += 10;
			else
				zahl += Integer.parseInt(isbn.substring(9,10)) *1;
			if(zahl % 11 ==0)
				isISBN = true;
		}
		return isISBN;
	}
}
