当前位置:文档之家› java实验报告

java实验报告

数学与计算机学院实验报告(2010/2011 学年第1 学期)课程名称 Java程序设计课程代码8421991任课教师指导教师学生姓名学号32年级2008级专业软件工程综合成绩程序代码;public class Publication{protected String name;protected String isbn;protected String publisher;protected double price;protected String author;protected Publication(){}public Publication(String name,String isbn,String author,String publisher,double price){=name;=isbn;=author;=publisher;=price;}public String getName(){return name;}public String getIsbn(){return isbn;}public String getAuthor(){return author;}public String getPublisher(){return publisher;}public double getPrice(){return price;}public void setName(String name){=name;}public void setIsbn(String isbn){=isbn;}public void setAuthor(String author){=author;}public void setPublisher(String publisher){=publisher;}public void setPrice(double price){=price;}public static String readString(String s) throws IOException{": ");BufferedReader buf=new BufferedReader(new InputStreamReader);return ();}public static Double readDouble(String s) throws IOException,NumberFormatException{": ");BufferedReader buf=new BufferedReader(new InputStreamReader);String line=();return (line);}public static int readInt(String s) throws IOException,NumberFormatException{": ");BufferedReader buf=new BufferedReader(new InputStreamReader);String line=();return (line);}public void setInfo(String name,String isbn,String author,String publisher,double price){=name;=isbn;=author;=publisher;=price;}public String toString(){return "出版物名字:"+name+" ISBN:"+isbn+" 编者:"+author+" 出版社:"+publisher+" 单价:"+price;}public void print(){ name:import .*;public class Book extends Publication{public Book(){super();}public Book(String name,String isbn,String author,String publisher,double price){super(name,isbn,author,publisher,price);}public String toString(){return "书名:"+name+" ISBN:"+isbn+" 作者:"+author+" 出版社:"+publisher+" 单价:"+price;}public Book addBook() throws IOException{Book book=new Book(readString("书名"),readString("ISBN"),readString("作者"),readString("出版社"),readDouble("价格"));return book;}public void print(){ name:import .*;public class Periodical extends Publication{protected int No;public Periodical(){super();}public Periodical(String name,String isbn,String author,String publisher,double price,int No){super(name,isbn,author,publisher,price);=No;}public void setNo(int No){=No;}public int getNo(){return No;}public void setInfo(String name,String isbn,String author,String publisher,double price,int No){(name,isbn,author,publisher,price);=No;}public String toString(){return "期刊名称:"+name+" ISBN:"+isbn+" 主编:"+author+" 发行社:"+publisher+" 单价:"+price+" 第"+No+"期";}public Periodical addPeriodical() throws IOException{Periodical per=new Periodical(readString("期刊名称"),readString("ISBN"),readString("主编"),readString("发行社"),readDouble("单价"),readInt("期数"));return per;}public void print(){ name:import .*;public class Newspaper extends Publication{protected String date;public Newspaper(){super();}public Newspaper(String name,String isbn,String author,String publisher,double price,String date){super(name,isbn,author,publisher,price);=date;}public void setDate(String date){=date;}public String getDate(){return date;}public void setInfo(String name,String isbn,String author,String publisher,double price,String date){(name,isbn,author,publisher,price);=date;}public String toString(){return "报纸名称:"+name+" ISBN:"+isbn+" 总主编:"+author+" 报社:"+publisher+" 单价:"+price+" 日期"+date;}public Newspaper addNewspaper() throws IOException{Newspaper nep=new Newspaper(readString("报纸名称"),readString("ISBN"), readString("总主编"),readString("报社"),readDouble("单价"),readString("日期"));return nep;}public void print(){ name:import .*;import .*;public class Operating{static LinkedList list=new LinkedList();int index,len,No;Publication pb;int ch;String name,isbn,author,publisher,date;double price;Scanner in=new Scanner;public void add() throws IOException{try{"请按以下选项提示选择你将进行添加的出版物信息:");"1. 书籍 2. 期刊 3. 报纸 0. 返回上一级");ch=();int flag;switch(ch){case 1:Book book=new Book();"按依次分别按以下格式添加出版物信息,当输入非0时继续添加,输入0时结束添加:");flag=1;while(flag!=0){());"书籍信息添加成功!是否继续");flag=();}break;case 2:Periodical perd=new Periodical();"按依次分别按以下格式添加出版物信息,当输入非0时继续添加,输入0时结束添加:");flag=1;while(flag!=0){());"期刊信息添加成功!是否继续");flag=();}break;case 3:Newspaper nep=new Newspaper();"按依次分别按以下格式添加出版物信息,当输入非0时继续添加,输入0时结束添加:");flag=1;while(flag!=0){());"报纸信息添加成功!是否继续");flag=();}break;}}catch(InputMismatchException e){}}public void Print(){len=();for(int i=0;i<len;i++)}public int search(String isbn){len=();for(int i=0;i<len;i++){if(((Publication)(i)).getIsbn().equals(isbn)) {index = i;return index;}}return -1;}public void update(String isbn){short choice;index=search(isbn);if(index!=-1){"你将要修改的出版物的原始信息如下:");((Publication)(index)).print();"请确认是否修改 1:修改,0:不修改");choice=();if(choice==1){"出版物名称:");name=();"出版物ISBN:");isbn=();"出版物作者:");author=();"出版物出版社:");publisher=();"出版物价格:");price=();((Publication)(index)).setInfo(name,isbn,author,publisher,price); return;}else return;}else"请核实你所修改的出版物是否存在,修改失败!");}public void delet(String isbn){for(int i=0;i<len;i++){index=search(isbn);if(index!=-1){(index);break;}else{"请核实你所修改的出版物是否存在,删除失败!");break;}}}public void sort(){int i,j,k,t,len=();ListIterator alist=();Publication p,p1=(Publication)(0),q=p1,r;p=(Publication)(0);for(i=0;i<len-1;i++){k=i;for(j=i+1;j<len;j++)if(((Publication)(j)).getPrice()<((Publication)(k)).getPrice()) k=j;if(k>i){Object tem=(i);(i)=(k);(k)=tem;}}}};import .*;public class TestMiniBMS extends Operating{public static void Menu(){"**********Welcomecome To MiNi Book Management System!**********"); "1.信息添加 4.信息更新");"2.信息打印 5.信息删除");"3.信息查询 6.信息排序");" 0.退出系统");}public static void main(String[] args){Scanner in=new Scanner;int choice;String isbn;Operating op=new Operating();while(true){Menu();choice=();switch(choice){case 1:"出版物信息添加,请输入正确的操作代码进行操作");try{();}catch(IOException e){"输入输出出错:"+e);}break;case 2:"信息打印——系统中现有的出版物的信息如下:");();break;case 3:"信息查询\n请输入你将要查询的出版物的ISBN号"); isbn=();int i=(isbn);if(i!=-1){"你所查询的图书出版物信息如下:");((Publication) break; }"请核实你所查找的出版物是否存在,查找信息失败!"); break;case 4:"信息更新\n请输入你将要更新的出版物的ISBN号"); isbn=();(isbn);break;case 5:"信息删除\n请输入你将要删除的出版物的ISBN号"); isbn=();(isbn);break;case 6:"信息按价格由低到高排序:");();break;case 0:(0);}}}}。

相关主题