¿ALGUIEN ME PD AYUDAR?

laury19
30 de Agosto del 2004
HOLA.. ESTE ES UN PROGRAMA QUE HE HEXO YO... Y M DAN MUXISISISISIMOS ERRORES..... ALGUIEN M PD DECIR COMO LOS PD KITAR.... XFA XFA

<<ESTE ES MI PROGRAMA>>

import java.io.*;
import java.util.*;

class Publicacion {


BufferedReader leer = new BufferedReader
(new InputStreamReader(System.in));

//VARIABLES DE EJEMPLAR

protected String tipo;
private String titulo;
private String materia;
protected int año;

//METODO CONSTRUCTOR
public Publicacion(String titulo,String materia,
int año) {

this.titulo=titulo;
this.materia=materia;
this.año=año;
tipo="Publicacion";

}

//MÉTODOS DE SERVICIOS

public String dev_materia() {
return materia;
}

public String dev_tipo(){
return tipo;
}

public String dev_titulo() {
return titulo;
}

public int dev_año(){
return año;
}

public String toString(){
return "TIPO DE PUBLICACION: "+dev_tipo()+"n"+"TITULO :"+
dev_titulo()+"n"+"MATERIA: "+dev_materia();
}
}

abstract class No_Periodica extends Publicacion {
//VARIABLES DE EJEMPLAR
protected String[] autores;
//METODO CONSTRUCTOR
public No_Periodica(String titulo, String materia,
int año, String[] autores) {
super(titulo,materia,año);
this.autores=autores;
tipo="No_periodica";
}
//METODO DE SERVICIO
public String toString(){
System.out.println(super.toString());

return "AÑO DE PUBLICACION: "+dev_año();
}

//METODO ABSTRACTO
abstract public String dev_autores();

public void leer_por_teclado(){
boolean salir;
int num_autores=0;
do{
try{
System.out.println("n");
System.out.println("INTRODUZCA EL NUMERO DE AUTORES:");
num_autores=Integer.parseInt(leer.readLine());
}
catch(NumberFormatException e){
System.out.println("ERROR, INTRODUZCA UN NUMERO");
salir=true;
}
}while(salir);

String[] autores=new String [num_autores];

for(int i=0;i<num_autores;i++){
System.out.println("n");
do{
salir=false;
try{
System.out.println("INTRODUZCA EL AUTOR "+(i+1)+":");
autores[i]=leer.readLine();
if(autores[i].equals("")){
throw new NadaEscritoException();
}
}
catch(NadaEscritoException e){
salir=true;
}
}while(salir);
}

//AÑO PUBLICACIÓN
do{
salir=false;//variable control errores
try{
System.out.println();
System.out.println("AÑO DE PUBLICACION");

año=Integer.parseInt (leer.readLine());
if (año>2004||año<0){
throw new ErrorAñoException();
}
}

catch(ErrorAñoException e){
System.out.println("EL AÑO TIENE QUE ESTAR COMPRENDIDO ENTRE 0000-2004");
salir=true;
}
catch(NumberFormatException e){
System.out.println("ERROR, INTRODUZCA UN NUMERO");
salir=true;
}

}while(salir);
}
public void lectura_fichero(RandomAccessFile fichero) {
boolean salir;
do {
try {
salir=true;
super.lectura_fichero(fichero);
autores=fichero.readUTF();
año=fichero.readInt();
}
catch (IOException e){
System.out.println("ERROR EN LA E/S DE DATOS");
salir=false;
}
}while (!salir);
}
public void escritura_fichero(RandomAccessFile fichero) {
boolean salir;
do {
try {
super.escritura_fichero(fichero);
salir = true;
fichero.writeUTF(autores);
fichero.writeInt(año);
}catch (IOException e){
System.out.println("ERROR, EN LA E/S DE DATOS");
salir=false;
}// final del bloque try-catch

}while(!salir);
}

}//fin clase No_Periodica

class Periodica extends Publicacion {
//VARIABLES DE EJEMPLAR
private int volumen;
int []fecha;
//METODO CONSTRUCTOR
public Periodica(String titulo, String materia, int[] fecha,
int volumen) {
super(titulo,materia,fecha[2]);
this.fecha=fecha;
this.volumen=volumen;
tipo="Periodica";
}
//METODOS SERVICIOS
public int dev_volumen() {
return volumen;
}

public String toString() {
System.out.println(super.toString());

return "VOLUMEN: "+dev_volumen()+"n"+
"FECHA DE EDICION: "+dev_fecha();

}

public String dev_fecha() {
return fecha[0]+" - "+fecha[1]+" - "+fecha[2];
}
public void leer_por_teclado() {

//** DECLARACION DE VARIABLES **//

boolean lectura;
String titulo="",materia="";
int volumen=0;
int[]fecha={0,0,0};
boolean error=false;

do{
error=false;//** CONTROL DE ERRORES **//

try{
System.out.println();
System.out.println("INTRODUZCA EL TITULO: ");
titulo=leer.readLine();
if(titulo.equals("")){
throw new VacioException();
}
}
catch(VacioException e){//** SI NO SE ESCRIBE NADA **//
error=true;
}
}while(error);

//MATERIA
do{
error=false;//** CONTROL DE ERRORES **//

try{
System.out.println();
System.out.println("INTRODUZCA LA MATERIA: ");
materia=leer.readLine();
if(materia.equals("")){
throw new NadaEscritoException();
}
}
catch(NadaEscritoException e){//** NO SE INTRODUCE NADA **//
error=true;
}
}while(error);

//VOLUMEN
do{
error=false;//** CONTROL DE ERRORES **//

try{
System.out.println();
System.out.println("INTRODUZCA EL VOLUMEN: ");
volumen=Integer.parseInt(leer.readLine());
}
catch(NumberFormatException e){//** SE HAN ESCRITO LETRAS
// EN LUGAR DE NUMEROS **//
System.out.println("POR FAVOR, INTRUDUZCA UN NUMERO");
error=true;
}
}while(error);

//FECHA
System.out.println();
System.out.println("INTRODUZCA LA FECHA DE EDICION:");
//año
do{
error=false;
try{
System.out.println("AGNO");
fecha[2]=Integer.parseInt(leer.readLine());
if (fecha[2]>2004||fecha[2]<0){

error=true;
throw new MalFechaException(1);
}
}//fin try

catch(MalFechaException e){
error=true;
}
catch(NumberFormatException e){//** SE HAN ESCRITO LETRAS
// EN LUGAR DE NUMEROS **//
System.out.println("POR FAVOR, INTRUDUZCA UN NUMERO");
error=true;
}


}while(error);

//mes
do{
error=false;//** CONTROL DE ERRORES **//

try{
System.out.println();
System.out.println("MES(en numeros)");
fecha[1]=Integer.parseInt(leer.readLine());
if(fecha[1]>12||fecha[1]<0){

error=true;
throw new MalFechaException(2);
}
}
catch(MalFechaException e){
error=true;
}

catch(NumberFormatException e){//** SE HAN ESCRITO LETRAS
// EN LUGAR DE NUMEROS **//
System.out.println("POR FAVOR, INTRUDUZCA UN NUMERO");
error=true;
}
}while(error);

//dia
do{
error=false;//** CONTROL DE ERRORES **//

try{
System.out.println();
System.out.println("DIA");
fecha[0]=Integer.parseInt (leer.readLine());

//*** MESES CON 31 DIAS ***//

if (fecha[1] == 1){
System.out.println("ENERO");
}
if (fecha[1] == 3){
System.out.println("MARZO");
}
if (fecha[1] == 5){
System.out.println("MAYO");
}
if (fecha[1] == 7){
System.out.println("JULIO");
}
if (fecha[1] == 8){
System.out.println("AGOSTO");
}
if (fecha[1] == 10){
System.out.println("OCTUBRE");
}
if (fecha[1] == 12){
System.out.println("DICIEMBRE");
}
if(fecha[0]>31||fecha[0]<0){
error=true;
throw new MalFechaException(3);

}

// *** MESES CON 30 DIAS ***//
if (fecha[1] == 4){
System.out.println("ABRIL");
}
if (fecha[1] == 6){
System.out.println("JUNIO");
}
if (fecha[1] == 9){
System.out.println("SEPTIEMBRE");
}
if (fecha[1] == 11){
System.out.println("NOVIEMBRE");
}
if(fecha[0]>30||fecha[0]<0){
error=true;
throw new MalFechaException(3);

}


// *** LA EXCEPCION DE FEBRERO (AÑO BISIESTO) ***//

if (fecha[1] == 2){
System.out.println("FEBRERO");
}
if(fecha[2]%4==0){
//* CADA 4 AÑOS AÑO BISIESTO *//
//* ES DECIR, FEBRERO TIENE 29 DIAS*//

if(fecha[0]>29||fecha[0]<0){
error=true;
throw new MalFechaException(3);
}
}else{
if(fecha[0]>28||fecha[0]<0){
error=true;
throw new MalFechaException(3);

}
}

}//fin try

catch(MalFechaException e){
error=true;
}

catch(NumberFormatException e){

//** SE HAN ESCRITO LETRAS EN LUGAR DE NUMEROS **//

System.out.println("POR FAVOR, INTRUDUZCA UN NUMERO");
error=true;
}
}while(error);
}
public void lectura_fichero (RandomAccessFile fichero) {
//Este metodo va a leer el fichero
boolean salir;
do {
try {
super.lectura_fichero(fichero);
salir = true;
volumen = fichero.readInt();
fecha = fichero.readUTF();
}catch (IOException e){
System.out.println("ERROR EN LA E/S DE DATOS");
salir=false;
}// final bloque try-catch
}while(!salir);
}

public void escribir_fichero (RandomAccessFile fichero) {
//Este es un metodo para enscribir en el fichero
boolean salir;
do {
try {
super.escritura_fichero(fichero);
salir = true;
fichero.writeInt(volumen);
fichero.writeUTF(fecha);
}catch (IOException e){
System.out.println("ERROR, EN LA E/S DE DATOS");
salir=false;
}// final del bloque try-catch
}while(!salir);

}
}//fin clase Periodica

class Libro extends No_Periodica {
//VARIABLES DE EJEMPLAR
private long ISBN;
private String editorial;
//METODO CONSTRUCTOR
public Libro(String titulo, String materia, int año,
String[] autores, long ISBN, String editorial) {
super(titulo,materia,año,autores);
this.ISBN=ISBN;
this.editorial=editorial;
tipo="Libro";
}

//METODOS SERVICIOS
public long dev_ISBN() {
return ISBN;
}

public String dev_editorial() {
return editorial;
}

public String toString() {

System.out.println(super.toString());

return "EDITORIAL: "+dev_editorial()+
"n"+"AUTORES :"+dev_autores()+"n"+"ISBN :"+dev_ISBN();
}

public String dev_autores() {
String autores=" ";

for (int i=0;i<this.autores.length;i++){
autores=this.autores[i]+","+autores;
}

return autores;
}

public void leer_por_teclado (){
//DECLARACION DE VARIABLES E INICIALIZACION
String titulo="",materia="",editorial="";
int año=0,num_autores=0;
long ISBN=0;
boolean error=false;

//TITULO
do{
error=false;//variable control errores

try{
System.out.println();
System.out.println("INTRODUZCA EL TITULO: ");
titulo=leer.readLine();
if(titulo.equals("")){
throw new NadaEscritoException();
}
}
catch(NadaEscritoException e){//no se ha introducido nada
error=true;
}
}while(error);

//MATERIA
do{
error=false;//variable control errores

try{
System.out.println();
System.out.println("INTRODUZCA LA MATERIA: ");
materia=leer.readLine();
if(materia.equals("")){
throw new NadaEscritoException();
}
}
catch(NadaEscritoException e){//no se ha introducido nada
error=true;
}
}while(error);

//EDITORIAL
do{
error=false;//variable control errores

try{
System.out.println("n");
System.out.println("INTRODUZCA LA EDITORIAL: ");
editorial=leer.readLine();
if(editorial.equals("")){
throw new NadaEscritoException();
}
}
catch(NadaEscritoException e){//no se ha introducido nada
error=true;
}
}while(error);

//AUTORES
do{
error=false;//variable control errores

try{
System.out.println();
System.out.println("INTRODUZCA EL NUMERO DE AUTORES:");
num_autores=Integer.parseInt (leer.readLine());
}
catch(NumberFormatException e){//error letras en integer
System.out.println("ERROR, INTRODUZCA UN NUMERO");
error=true;
}
}while(error);

String[] autores=new String [num_autores];

for(int i=0;i<num_autores;i++){
System.out.println("n");
do{
error=false;
try{
System.out.println("INTRODUZCA EL AUTOR "+(i+1)+":");
autores[i]=leer.readLine();
if(autores[i].equals("")){
throw new NadaEscritoException();
}
}
catch(NadaEscritoException e){//no se ha introducido nada
error=true;
}
}while(error);
}

//ISBN
do{
error=false;//variable control errores

try{
System.out.println();
System.out.println("INTRODUZCA EL ISBN:(10 digitos) ");
ISBN=Long.parseLong(leer.readLine());
String aux="";//variable auxiliar para consultar nº dígitos
if (aux.valueOf(ISBN).length()!=10){//+de 10 dígitos
throw new ISBNfueraLimitesException();
}
}//fin try
catch(NumberFormatException e){
System.out.println("ERROR, INTRODUZCA UN NUMERO");
error=true;
}
catch(ISBNfueraLimitesException e){//no se han introducido
//10 digitos
System.out.println("ERROR, HAS INTRODUCIDO MAS DE 10 DIGITOS");
error=true;
}
}while(error);

//AÑO PUBLICACIÓN
do{
error=false;
try{
System.out.println();
System.out.println("AÑO DE PUBLICACION");
año=Integer.parseInt(leer.readLine());
if (año>2004||año<0){
throw new ErrorAñoException();
}
}

catch(ErrorAñoException e){
System.out.print("EL AÑO TIENE QUE ESTAR COMPRENDIDO ");
System.out.println ("ENTRE 0000-2004 ");
error=true;
}
catch(NumberFormatException e){
System.out.println("ERROR, INTRODUZCA UN NUMERO");
error=true;
}

}while(error);
}

public void lectura_fichero(RandomAccessFile fichero) {
boolean salir;
do {
try {
super.lectura_fichero(fichero);
salir = true;
editorial = fichero.readUTF();
ISBN = fichero.readInt();
}catch (IOException e){
System.out.println("ERROR, EN LA E/S DE DATOS");
salir=false;
}// final bloque try-catch
}while(!salir);
}//fin metodo leer_fichero

public void escritura_fichero(RandomAccessFile fichero) {
boolean salir;
do {
try {
super.escritura_fichero(fichero);
salir = true;
fichero.writeUTF(editorial);
fichero.writeInt(ISBN);
}catch (IOException e){
System.out.println("ERROR, EN LA E/S DE DATOS");
salir=false;
}// final try-catch
}while(!salir);
}//fin metodo escribir_fichero
}//fin clase Libro

abstract class TrabajoInvestigacion extends No_Periodica {
//VARIABLES DE EJEMPLAR
private String departamento;
//METODO CONSTRUCTOR
public TrabajoInvestigacion(String titulo, String materia,
int año, String[] autores, String departamento) {
super(titulo,materia,año,autores);
this.departamento=departamento;
tipo="Trabajo de Investigacion";
}
//METODOS SERVICIOS
public String dev_departamento() {
return departamento;
}
//EXISTE EL METODO ABSTRACTO (dev_autores) AUNQUE NO ESTE EXPLICITO
//SE HEREDA DE LA CLASE NO PERIODICA

}//fin clase TrabajoInvestigacion

class InformeTecnico extends TrabajoInvestigacion {
//VARIABLES EJEMPLARES
private String peticionario;
//METODO CONSTRUCTOR
public InformeTecnico(String titulo, String materia, int año,
String[] autores, String departamento, String peticionario) {
super(titulo,materia,año,autores,departamento);
this.peticionario=peticionario;
tipo="Informe Tecnico";
}
//METODOS SERVICIOS
public String toString() {
System.out.println(super.toString());
return "DEPARTAMENTO: "+dev_departamento()+
"n"+"AUTORES :"+dev_autores()+"n"+
"ENTIDAD QUE LO ENCARGA: "+dev_entidad_encarga();
}

public String dev_entidad_encarga() {
return entidad_encarga;
}

public String dev_autores() {
String autores=" ";

for (int i=0;i<this.autores.length;i++){
autores=this.autores[i]+","+autores;
}
return autores;
}

public static void leer_por_teclado(){
//DECLARACION DE VARIABLES E INICIALIZACION
String titulo="",materia="",departamento="",entidad_encarga="";
int año=0,num_autores=0;
boolean error=false;
//TITULO
do{
error=false;
try{
System.out.println();
System.out.println("INTRODUZCA EL TITULO: ");
titulo=leer.readLine();
if(titulo.equals("")){
throw new NadaEscritoException();
}
}
catch(NadaEscritoException e){
error=true;
}
}while(error);
//MATERIA
do{
error=false;
try{
System.out.println("n");
System.out.println("INTRODUZCA LA MATERIA: ");
materia=leer.readLine();
if(materia.equals("")){
throw new NadaEscritoException();
}
}
catch(NadaEscritoException e){
error=true;
}
}while(error);
//DEPARTAMENTO
do{
error=false;
try{
System.out.println();
System.out.println("INTRODUZCA EL DEPARTAMENTO: ");
departamento=leer.readLine();
if(departamento.equals("")){
throw new NadaEscritoException();
}
}
catch(NadaEscritoException e){
error=true;
}
}while(error);

//ENTIDAD QUE LO ENCARGA
do{
error=false;
try{
System.out.println("n");
System.out.println("INTRODUZCA LA ENTIDAD QUE LO ENCARGA: ");
entidad_encarga=leer.readLine();
if(entidad_encarga.equals("")){
throw new NadaEscritoException();
}
}
catch(VacioException e){//no se ha introducido nada
error=true; }
}while(error);
//AUTORES
do{
error=false;
try{
System.out.println();
System.out.println("INTRODUZCA EL NUMERO DE AUTORES:");
num_autores=Integer.parseInt(leer.readLine());
}
catch(NumberFormatException e){
System.out.println("ERROR, INTRODUZCA UN NUMERO");
error=true;
}
}while(error);
String[] autores=new String [num_autores];
for(int i=0;i<num_autores;i++){
System.out.println();
do{
error=false;
try{
System.out.println("INTRODUZCA EL AUTOR "+(i+1)+":");
autores[i]=leer.readLine();
if(autores[i].equals("")){
throw new NadaEscritoException();
}
}
catch(NadaEscritoException e){//no se ha introducido nada
error=true;
}
}while(error);
}

//AÑO PUBLICACION
do{
error=false;
try{
System.out.println();
System.out.println("AÑO DE PUBLICACION");
año=Integer.parseInt(leer.readLine());
if (año>2004||año<0){
throw new ErrorAñoException();
}
}
catch(ErrorAñoException e){
System.out.print("EL AÑO TIENE QUE ESTAR COMPRENDIDO ");
System.out.println("ENTRE 0000-2004");
error=true;
}
catch(NumberFormatException e){
System.out.println("ERROR, INTRODUZCA UN NUMERO");
error=true;
}
}while(error);
}
public void lectura_fichero(RandomAccessFile fichero) {
boolean salir;
do {
try {
super.lectura_fichero(fichero);
salir = true;
departamento = fichero.readUTF();
entidad_encarga = fichero.readInt();
}catch (IOException e){
System.out.println("ERROR EN LA E/S DE DATOS");
salir=false;
}
}while(!salir);
}//fin metodo leer_fichero

public void escritura_fichero(RandomAccessFile fichero) {
boolean salir;
do {
try {
super.escritura_fichero(fichero);
salir = true;
fichero.writeUTF(departamento);
fichero.writeInt(entidad_encarga);
}catch (IOException e){
System.out.println("ERROR EN LA E/S DE DATOS");
salir=false;
}
}while(!salir);
}
}//fin clase InformeTecnico

class TesisDoctoral extends TrabajoInvestigacion {
//VARIABLES EJEMPLAR
private String director;
private String calificacion;
//METODO CONSTRUCTOR
public TesisDoctoral(String titulo, String materia, int año,
String[] autores, String departamento, String director,
String calificacion) {
super(titulo,materia,año,autores,departamento);
this.director=director;
this.calificacion=calificacion;
tipo="Tesis Doctoral";
}
//METODOS SERVICIOS
public String dev_director() {
return director;
}

public String dev_calificacion() {
return calificacion;
}

public String dev_autores() {
return autores[0];
}

public String toString() {

System.out.println(super.toString());

return "DEPARTAMENTO: "+dev_departamento()+
"n"+"AUTOR: "+dev_autores()+"n"+"MATERIA: "+dev_materia()
+"n"+"DIRECTOR: "+dev_director()+
"n"+"CALIFICACION: "+dev_calificacion();
}

public static void leer_por_teclado()throws IOException{
//DECLARACION DE VARIABLES
String titulo="",materia="",departamento="",
director="",calificacion="";
int año=0;
boolean error;
String[] autores=new String [1];
//TITULO
do{
error=false;//variable control errores

try{
System.out.println();
System.out.println("INTRODUZCA EL TITULO: ");
titulo=leer.readLine();
if(titulo.equals("")){
throw new NadaEscritoException();
}
}
catch(NadaEscritoException e){//no se ha introducido nada
error=true;
}
}while(error);

//MATERIA
do{
error=false;//variable control errores

try{
System.out.println();
System.out.println("INTRODUZCA LA MATERIA: ");
materia=leer.readLine();
if(materia.equals("")){
throw new NadaEscritoException();
}
}
catch(NadaEscritoException e){//no se ha introducido nada
error=true;
}
}while(error);

//DEPARTAMENTO
do{
error=false;
try{
System.out.println();
System.out.println("INTRODUZCA EL DEPARTAMENTO: ");
departamento=leer.readLine();
if(departamento.equals("")){
throw new NadaEscritoException();
}
}
catch(NadaEscritoException e){
error=true;
}
}while(error);

//DIRECTOR
do{
error=false;
try{
System.out.println("n");
System.out.println("INTRODUZCA EL DIRECTOR: ");
director=leer.readLine();
if(director.equals("")){
throw new NadaEscritoException();
}
}
catch(NadaEscritoException e){//no se ha introducido nada
error=true;
}
}while(error);
//CALIFICACION
do{
error=false;
try{
System.out.println();
System.out.println("INTRODUZCA LA CALIFICACION(en letra): ");
calificacion=leer.readLine();
if(calificacion.equals("")){
throw new NadaEscritoException();
}
}
catch(NadaEscritoException e){//no se ha introducido nada
error=true;
}
}while(error);

//AUTOR
do{
error=false;
try{
System.out.println();
System.out.println("INTRODUZCA EL AUTOR: ");
autores[0]=leer.readLine();
if(autores[0].equals("")){
throw new NadaEscritoException();
}
}
catch(NadaEscritoException e){//no se ha introducido nada
error=true;
}
}while(error);

//AÑO PUBLICACIÓN
do{
error=false;
try{
System.out.println();
System.out.println("AÑO DE PUBLICACION");
año=Integer.parseInt(leer.readLine());
if (año>2004||año<0){
throw new ErrorAñoException();
}
}

catch(ErrorAñoException e){
System.out.print("EL AÑO TIENE QUE ESTAR COMPRENDIDO ");
System.out.println ("ENTRE 0000-2004 ");
error=true;
}
catch(NumberFormatException e){
System.out.println("ERROR, INTRODUZCA UN NUMERO");
error=true;
}

}while(error);
}

public void lectura_fichero (RandomAccessFile fichero) {
boolean salir;
do {
try {
super.leer_fichero(fichero);
salir = true;
calificacion = fichero.readUTF();
departamento = fichero.readUTF();
director = fichero.readUTF();
}catch (IOException e){
System.out.println("ERROR EN LA E/S DE DATOS");
salir=false;
}// final bloque try-catch
}while(!salir);
}// fin metodo leer_fichero
public void escritura_fichero (RandomAccessFile fichero) {
boolean salir;
do {
try {
super.escritura_fichero(fichero);
salir = true;
fichero.writeUTF(calificacion);
fichero.writeUTF(departamento);
fichero.writeUTF(director);
}catch (IOException e){
System.out.println("ERROR EN LA E/S DE DATOS");
salir=false;
}//final bloque try-catch
}while(!salir);
}// fin metodo escribir_fichero
}//fin clase TesisDoctoral

class Biblioteca{
private Publicacion []deposito=new Publicacion [500];
//MATRIZ DE OBJETOS POLIFORMICOS
private int total_publicaciones=0;
public void añadir(Publicacion objeto1){
//CON LA REFERENCIA ANTERIOR, APUNTAMOS AL OBJETO QUE SE LE PASA
//COMO PARAMETRO DE CLASE HIJA
deposito[total_publicaciones()]=objeto1;
total_publicaciones++;
}

public int total_publicaciones(){
return total_publicaciones;
}


public void imprimir_datos(int indice){
System.out.println(deposito[indice].toString());
}

public int[] consulta_año(String tipo,int año)
throws IOException{
int[] indices=new int[100];
int j=0;

try{
indices[0]=-1;
//BUSCA HASTA QUE ENCUENTRA LA EXCEPCION
for(int i=0;i<deposito.length;i++){
if((deposito[i].dev_tipo()==(tipo))&&(deposito[i].dev_año()>año)){
indices[j]=i;
j++;
}
}//fin for
}//fin try
catch(NullPointerException e){//apuntando a null
}
return indices;
}

public int[] consulta_materia(String materia)
throws IOException{
int[]indices=new int[100];
int j=0;
try{
indices[0]=-1;
//BUSCA HASTA QUE SE PRODUCE LA EXCEPCION
for (int i=0;i<deposito.length;i++){
if(deposito[i].dev_materia()==materia){
indices[j]=i;
j++;
}
}
}
catch(NullPointerException e){
}
return indices;
}
public int calcular_ntipo(String tipo){
int total=0;
try{
for (int i=0;i<deposito.length;i++){
if (deposito[i].dev_tipo()==(tipo)){
total++;
}
}
}
catch(NullPointerException e){
}
// SI NO SE ENCUENTRA NINGUN OBJETO, TOTAL=0
return total ;
}
}
class Programa_principal {
RandomAccessFile fichero;
BufferedReader leer = new BufferedReader
(new InputStreamReader(System.in));
//METODO CONSTRUCTOR
public Programa_principal() throws IOException {
fichero = new RandomAccessFile("datos", "rw");
}

// MENU PRINCIPAL (donde se hace la presentacion del programa)

public static void presentacion (){
BufferedReader leer= new BufferedReader
(new InputStreamReader(System.in));
int opcion;
boolean incorrecto=true;

System.out.println("--------- BIBLIOTECA---------");
System.out.println();
System.out.println();
System.out.println("¿QUE DESEA HACER?");
System.out.println("REALIZAR ALGUNA OPERACION, PULSE 1");
System.out.println("SALIR DEL PROGRAMA, PULSE 2");
do{
opcion=Integer.parseInt(leer.readLine());
if (opcion!=1 && opcion!=2){
System.out.println("ERROR,INTENTELO DE NUEVO");
}
else{
incorrecto=false;
if (opcion==1){
siguiente_menu();
}
if (opcion==2){
salir_programa();
}
}
}while(incorrecto);
}
public static void siguiente_menu(){
BufferedReader leer= new BufferedReader
(new InputStreamReader(System.in));
int opcion2;
boolean incorrecto=true;

System.out.println();
System.out.println("OPCIONES: ");
System.out.println();
System.out.println("CATALOGAR NUEVAS INCORPORACIONES,PULSE 1");
System.out.println();
System.out.println("CONSULTAR EXISTENCIAS,PULSE 2");
System.out.println();
System.out.println("SALIR, PULSE 3");
System.out.println();
do{
opcion2=Integer.parseInt (leer.readLine());
if (opcion2 !=1 && opcion2!=2 && opcion2!=3){
System.out.println("ERROR, INTENTELO DE NUEVO");
}
else{
incorrecto=false;
if (opcion2 == 1){
nuevas_incorporaciones();
}
if (opcion2 == 2){
existencias();
}
if (opcion2 == 3){
salir_programa();
}
}
}while(incorrecto);
}
public static void nuevas_incorporaciones(){
BufferedReader leer= new BufferedReader
(new InputStreamReader(System.in));
int opcion3;
boolean incorrecto=true;

System.out.println();
System.out.print(" SELECCIONE EL TIPO DE PUBLICACION ");
System.out.println("QUE DESEA INCLUIR");
System.out.println();
System.out.println();
System.out.println("1.Periodica");
System.out.println("2.Libro");
System.out.println("3.Tesis Doctoral");
System.out.println("4.Informe Tecnico");
System.out.println("5.Volver mené anterior");
System.out.println("6.Salir");
System.out.println();
do{
opcion3=Integer.parseInt (leer.readLine());
if (opcion3!=1&&opcion3!=2 &&opcion3!=3 &&opcion3!=4&&
opcion3!=5 &&opcion3!=6){
System.out.println("ERROR,INTENTELO DE NUEVO");
}
else{
incorrecto = false;

if (opcion3==1){
incluir_periodica();
}
if (opcion3==2){
incluir_libro();
}
if (opcion3==3){
incluir_tesis();
}
if (opcion3==4){
incluir_informe();
}
if (opcion3==5){
siguiente_menu();
}
if (opcion3==6){
salir_programa();
}
}
}while(incorrecto);
}

public static void existencias()throws IOException{
BufferedReader leer= new BufferedReader
(new InputStreamReader(System.in));

int opcion4,año;
boolean incorrecto=true;

System.out.println();
System.out.println("OPCIONES: ");
System.out.println();
System.out.println();
System.out.println("1. CONSULTA DE PUBLICACIONES EN GENERAL");
System.out.println("2. CONSULTA POR EL AÑO DE PUBLICACION");
System.out.println("3. CONSULTA POR MATERIA");
System.out.println("4. CONSULTA POR TIPO");
System.out.println("5. VOLVER AL MENU ANTERIOR");
System.out.println("6. SALIR");
do{
opcion4=Integer.parseInt(leer.readLine());
if (opcion4!=1&&opcion4!=2&&opcion4!=3
&&opcion4!=4&& opcion4!=5&&opcion4!=6){
System.out.println("ERROR, INTENTELO DE NUEVO");
}
else{
incorrecto=false;
if (opcion4==1){
consulta_publicaciones();
}
if (opcion4==2){
System.out.println("INTRODUZCA EL AÑO DE PUBLICACION ");
año=Integer.parseInt(leer.readLine());
consulta_año_publicacion(año);
}
if (opcion4==3){
System.out.println("INTRODUZCA LA MATERIA ");
materia=leer.readLine();
consulta_materia(materia);
}
if (opcion4==4){
consulta_tipo();
}
if (opcion4==5){
siguiente_menu();
}
if (opcion4==6){
salir_programa();
}
}
}while(incorrecto);
}

public void incluir_libro() throws IOException{
libro libr = new libro();
libr.leer_por_teclado();
fichero.seek(fichero.length());
fichero.writeChar('L');
libr.escritura_fichero(fichero);
}

public void incluir_informe() throws IOException{
informe info = new informe();
info.leer_por_teclado();
fichero.seek(fichero.length());
fichero.writeChar('I');
info.escritura_fichero(fichero);
}

public void incluir_tesis() throws IOException{
tesis tesi = new tesis();
tesi.leer_por_teclado();
fichero.seek(fichero.length());
fichero.writeChar('T');
tesi.escritura_fichero(fichero);
}
public void incluir_periodica() throws IOException{
periodica peri = new periodica();
peri.leerteclado();
fichero.seek(fichero.length());
fichero.writeChar('P');
peri.escritura_fichero(fichero);
}
public void consulta_publicaciones() throws IOException{
fichero.seek(0);
boolean fin_fichero = false;
char letra;
do {
try{
letra = fichero.readChar();
if (letra == 'L'){
libro libr =new libro();
libr.lectura_fichero(fichero);
System.out.println(libr.toString());
}
if (letra == 'I'){
informe info=new Informe();
info.lectura_fichero(fichero);
System.out.println(info.toString());
}
if (letra== 'T'){
tesis tesi = new tesis();
tesi.lectura_fichero(fichero);
System.out.println(tesi.toString());
}
if (letra == 'P'){
periodica peri =new periodica();
peri.lectura_fichero(fichero);
System.out.println(peri.toString());
}
}catch (EOFException e) {
fin_fichero = true;
}

}while(!fin_fichero);
}

public void consulta_libros() throws IOException{
fichero.seek(0);
boolean fin_fichero = false;
char letra;
do {
try{
letra = fichero.readChar();
if (letra == 'L'){
libro libr =new libro();
libr.lectura_fichero(fichero);
System.out.println(libr.toString());
}
if (letra== 'I'){
informe info = new informe();
info.lectura_fichero(fichero);
System.out.println(info.toString());
}
if (letra== 'T'){
tesis tesi =new tesis();
tesi.lectura_fichero(fichero);
System.out.println(tesi.toString());
}
if (letra == 'P'){
periodica peri = new periodica();
peri.lectura_fichero(fichero);
System.out.printn(peri.toString());
}
}catch (EOFException e) {
fin_fichero = true;
}//fin try-catch
}while (!fin_fichero);
}//fin del metodo listadoLibros

public void consulta_materia(String materia) throws IOException{
fichero.seek(0);
boolean fin_fichero = false;
char letra;
do{
try{
letra = fichero.readChar();
if (letra == 'L'){
libro libr =new libro();
libr.lectura_fichero(fichero);
System.out.println(libr.toString());
}
if (letra== 'I'){
informe info = new informe();
info.lectura_fichero(fichero);
System.out.println(info.toString());
}
if (letra== 'T'){
tesis tesi =new tesis();
tesi.lectura_fichero(fichero);
System.out.println(tesi.toString());
}
if (letra == 'P'){
periodica peri = new periodica();
peri.lectura_fichero(fichero);
System.out.printn(peri.toString());
}
}catch (EOFException e) {
fin_fichero = true;
}
}while(!fin_fichero);
}

public void consulta_año(String año) throws IOException{
fichero.seek(0);
boolean fin_fichero = false;
char letra;
do {
try{
letra = fichero.readChar();
if (letra == 'L'){
libro libr =new libro();
libr.lectura_fichero(fichero);
System.out.println(libr.toString());
}
if (letra== 'I'){
informe info = new informe();
info.lectura_fichero(fichero);
System.out.println(info.toString());
}
if (letra== 'T'){
tesis tesi =new tesis();
tesi.lectura_fichero(fichero);
System.out.println(tesi.toString());
}
if (letra == 'P'){
periodica peri = new periodica();
peri.lectura_fichero(fichero);
System.out.printn(peri.toString());
}
}catch (EOFException e) {
fin_fichero = true;
}
}while(!fin_fichero);
}

public void consulta_tipo() {
//CONSULTAS INDIVIDUALES//
int elige;
boolean incorrecto=true;
System.out.println("ELIGE UNA DE LAS SIGUIENTES CONSULTAS");
System.out.println();
System.out.println(" 1. CONSULTA POR LIBROS");
System.out.println(" 2. CONSULTA POR INFORMES");
System.out.println(" 3. CONSULTA POR TESIS");
System.out.println(" 4. CONSULTA POR PUBLICACIONES PERIODICAS");
System.out.println(" 5. VOLVER AL MENU ANTERIOR");
System.out.println(" 6. SALIR DEL PROGRAMA");
do{
elige = Integer.parseInt(leer.readLine());
if (elige!=1&&elige!=2&&elige!=3&&elige!=4&&elige!=5
&&elige!=6){
System.out.println("ERROR, INTENTELO DE NUEVO");
}
else{
incorrecto=false;
if(elige == 1){
lista_de_libros();
}
if (elige == 2){
lista_de_informes();
}
if (elige == 3){
lista_de_tesis();
}
if (elige == 4){
lista_de_periodica();
}
if (elige == 5){
siguiente_menu();
}
if (elige == 6){
salir_programa();
}
}
}while(incorrecto);
}//fin del metodo listado por tipo

public void lista_de_libros() throws IOException{
fichero.seek(0);
boolean fin_fichero = false;
char letra;
do {
try{
letra = fichero.readChar();
if (letra == 'L'){
libro libr =new libro();
libr.lectura_fichero(fichero);
System.out.println(libr.toString());
}
if (letra== 'I'){
informe info = new informe();
info.lectura_fichero(fichero);
System.out.println(info.toString());
}
if (letra== 'T'){
tesis tesi =new tesis();
tesi.lectura_fichero(fichero);
System.out.println(tesi.toString());
}
if (letra == 'P'){
periodica peri = new periodica();
peri.lectura_fichero(fichero);
System.out.printn(peri.toString());
}
}catch (EOFException e) {
fin_fichero = true;
}//fin try-catch
}while (!fin_fichero);
}//fin del metodo listadoLibros

public void lista_de_informes() throws IOException{
fichero.seek(0);
boolean fin_fichero = false;
char letra;

while (!fin_fichero) {

try{

letra = fichero.readChar();

switch (letra) {

case 'L':
Libro libr = new Libro();
libr.leer_fichero(fichero);
break;

case 'I':
Informe info = new Informe();
info.leer_fichero(fichero);
System.out.println(info.toString());
break;

case 'T':
Tesis tesi = new Tesis();
tesi.leer_fichero(fichero);
break;

case 'P':
Periodicos peri = new Periodicos();
peri.leer_fichero(fichero);
break;

}//fin del switch

}catch (EOFException e) {

fin_fichero = true;

}//fin try-catch

}// fin del while

}//fin del metodo listadoInforme



public void lista_de_tesis() throws IOException{
fichero.seek(0);
boolean fin_fichero = false;
char letra;
do{
try{
letra = fichero.readChar();
if (letra == 'L'){
libro libr =new libro();
libr.lectura_fichero(fichero);
System.out.println(libr.toString());
}
if (letra== 'I'){
informe info = new informe();
info.lectura_fichero(fichero);
System.out.println(info.toString());
}
if (letra== 'T'){
tesis tesi =new tesis();
tesi.lectura_fichero(fichero);
System.out.println(tesi.toString());
}
if (letra == 'P'){
periodica peri = new periodica();
peri.lectura_fichero(fichero);
System.out.printn(peri.toString());
}
}catch (EOFException e) {
fin_fichero = true;
}//fin try-catch
}while (!fin_fichero);
}
public static void salir_programa(){
System.out.print("HA DECIDIDO SALIR DEL PROGRAMA");
System.out.println(" GRACIAS POR SU VISITA");
}
}

class FechaImposibleException extends Exception{
public FechaImposibleException(int n){
switch(n){
case 1://año
System.out.println("El agno introducido es incorrecto");
System.out.println("Intentelo de nuevo");
break;
case 2://mes
System.out.println("El mes introducido es incorrecto");
System.out.println("Intentelo de nuevo");
break;
case 3://dia
System.out.println("El dia introducido es incorrecto");
System.out.println("Intentelo de nuevo");

}
}
}

class NadaEscritoException extends Exception{
public NadaEscritoException(){
System.out.println("No ha introducido nada");
System.out.println("Intentelo de nuevo");
}
}
























GRACIAS D ANTEMANO