java多媒体继承_第1页
java多媒体继承_第2页
java多媒体继承_第3页
java多媒体继承_第4页
java多媒体继承_第5页
已阅读5页,还剩19页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

昆 明 理 工 大 学 理 学 院信息与计算科学专业 操作性实验报告年级: 09级 姓名: 陈龙飞 学号: 1 指导教师: 朱志宁 实验课程名称: java程序设计 开课实验室: 理学院机房216 实验成绩:学风(5)观察能力(15)操作能力(30)调试能力(50)其它总分实验内容:1实验/作业题目: 面向对象程序设计1、22实验/作业课时:各2学时,共4学时 3实验过程(包括实验环境、实验内容的描述、完成实验要求的知识或技能): 实验环境:eclipse 实验内容:编写一个简单的程序,利用数组保存书(Book),cd(CompactDisk),磁带(Tape)信息,并能实现插入、删除、查找功能。注意使用面向对象的思想进行程序设计。 完成实验要求的知识或技能:通过这个实验,能用eclipse来编写java程序,掌握java数组的使用和面向对象的编程思想。4程序结构(程序中的函数调用关系图。5算法描述、流程图或操作步骤:6实验数据和实验结果(用屏幕图形表示,可另加附页):1)、父类与子类定义与继承:package medea1;public class Media private String name;private String type;private float price;public String getname()return name;public void setname(String name) = name;public String gettype()return type;public void settype(String type)this.type = type;public float getprice()return price;public void setprice(float price)this.price = price;class CompactDisk extends Mediaprivate int size;/光盘容量public int getsize()return size;public void setsize(int size)this.size = size;public String getweight() / TODO Auto-generated method stubreturn null;class Book extends Mediaprivate int weight;/书的重量public int getweight()return weight;public void setweight(int weight)this.weight = weight;class Tape extends Mediaprivate String autor; /出厂厂家public String getautor()return autor;public void setautor(String autor)this.autor = autor;2) 、3个子类的函数定义:CompactDisk类:package medea1;public class CompactDiskMain public CompactDisk getCompactDiskByKey(CompactDisk CompactDiskb,CompactDisk searchc)for(CompactDisk compactDisk:CompactDiskb)if(compactDisk = null)continue;if (compactDisk.getname().equals(searchc.getname() return compactDisk;if (compactDisk.gettype().equals(searchc.gettype() return compactDisk;if (compactDisk.getprice() = searchc.getprice()return compactDisk;if (compactDisk.getsize() = searchc.getsize()return compactDisk;return null;public boolean add(CompactDisk CompactDiskb, CompactDisk addP) for (int i = 0; i CompactDiskb.length; i+) if (CompactDiskbi = null) CompactDiskbi = addP;return true;return false;public boolean delete(CompactDisk CompactDiskb, String name) for (int i = 0; i CompactDiskb.length; i+) if (CompactDiskbi.getname().equals(name) CompactDiskbi = null;return true;return false;public Book getBookByKey(CompactDisk compactDiskb, CompactDisk searchb) / TODO Auto-generated method stubreturn null;Book类package medea1;public class BookMain public Book getBookByKey(Book Bookb,Book p)for(Book book:Bookb)if(book = null)continue;if (book.getname().equals(p.getname() return book;if (book.gettype().equals(p.gettype() return book;if (book.getprice() = p.getprice()return book;if (book.getweight() = p.getweight()return book;return null;public boolean add(Book Bookb, Book addP) for (int i = 0; i Bookb.length; i+) if (Bookbi = null) Bookbi = addP;return true;return false;public boolean delete(Book Bookbb, String name) for (int i = 0; i Bookbb.length; i+) if (Bookbbi.getname().equals(name) Bookbbi = null;return true;return false;Tape类package medea1;public class TapeMain public Tape getTapeByKey(Tape Tapeb,Tape p)for(Tape tape:Tapeb)if(tape = null)continue;if (tape.getname().equals(p.getname() return tape;if (tape.gettype().equals(p.gettype() return tape;if (tape.getprice() = p.getprice()return tape;if (tape.getautor() = p.getautor()return tape;return null;public boolean add(Tape Tapeb, Tape addP) for (int i = 0; i Tapeb.length; i+) if (Tapebi = null) Tapebi = addP;return true;return false;public boolean delete(Tape Tapeb, String name) for (int i = 0; i Tapeb.length; i+) if (Tapebi.getname().equals(name) Tapebi = null;return true;return false;3) 、主函数编写:package medea1;import java.io.IOException;import java.util.Scanner;public class MediaMain private static final CompactDisk Searchc = null;private static final Tape Tapeb = null;public Media getMediabykey(Media Mediab,Media p)for(Media media:Mediab)if(media = null)continue;if (media.getname().equals(p.getname() return media;if (media.gettype().equals(p.gettype() return media;if (media.getprice() = p.getprice()return media;return null;public boolean add(Media mediab, Media addP) for (int i = 0; i mediab.length; i+) if (mediabi = null) mediabi = addP;return true;return false;public boolean delete(Media mediab, String name) for (int i = 0; i mediab.length; i+) if (mediabi.getname().equals(name) mediabi = null;return true;return false;/public static void main(String args) throws IOException MediaMain test = new MediaMain();Media mediab = new Media100;int choose = -1;while(choose != 0) System.out.println(请输入对应的数字进行操作); System.out.println(1.对Media进行操作 2.对CompactDisk进行操作 3.对Book进行操作 4.对Tay进行操作 0 + 退出系统); System.out.println(请选择:); Scanner omm = new Scanner(System.in); choose = omm.nextInt(); / if(choose = 1)int op = -1;try do System.out.println(1.添加 2.查找 3.删除 0.退出);System.out.println(请选择:);Scanner cin=new Scanner(System.in);op = cin.nextInt();switch( op ) case 0:System.out.println(系统退出!);/return; break;case 1:Media p = new Media();System.out.println(请输入播放器名称:);p.setname(cin.next();System.out.println(请输入播放器品牌:);p.settype(cin.next();System.out.println(请输入播放器价格:);p.setprice(cin.nextFloat();boolean flagadd = test.add(mediab,p);if (flagadd)System.out.println(添加成功!);elseSystem.out.println(添加失败!);break;case 2:Media searchP = new Media();int search = -1;String key = ;System.out.println(请输入查询内容:1.按名称 2.按类型 3.按价格 4.列出所有产品);search = cin.nextInt();if (search = 1) System.out.println(请输入播放器名称:);searchP.setname(cin.next();Media resultP = test.getMediabykey(mediab,searchP);if (resultP != null) System.out.println(名称: + resultP.getname() + ,类型: + resultP.gettype() + ,价格: + resultP.getprice(); else System.out.println(没有匹配播放器!); else if (search = 2) System.out.println(请输入播放器类型:);searchP.settype(cin.next();Media resultP = test.getMediabykey(mediab,searchP);if (resultP != null) System.out.println(名称: + resultP.getname() + ,类型: + resultP.gettype() + ,价格: + resultP.getprice(); else System.out.println(没有匹配播放器!); else if (search = 3) System.out.println(请输入播放器价格:);searchP.setprice(cin.nextFloat();Media resultP = test.getMediabykey(mediab,searchP);if (resultP != null) System.out.println(名称: + resultP.getname() + ,类型: + resultP.gettype() + ,价格: + resultP.getprice(); else System.out.println(没有匹配播放器!); else if (search = 4) for (Media product : mediab) if (product != null) System.out.println(名称: + product.getname() + ,类型: + product.gettype() + ,价格: + product.getprice();break;case 3:System.out.println(请输入要删除的播放器名称:);String name = cin.next();boolean flagdel = test.delete(mediab, name);if (flagdel)System.out.println(删除成功!);elseSystem.out.println(删除失败!);break; while (op != 0); catch (Exception e) System.out.println(输入了无效值!系统退出!);e.printStackTrace(); /else if(choose = 2)CompactDiskMain text1 = new CompactDiskMain();CompactDisk CompactDiskb = new CompactDisk100;int tp = -1;trydoSystem.out.println(1.添加 2.查找 3.删除 0.退出);System.out.println(请输入);Scanner cin = new Scanner(System.in);tp = cin.nextInt();switch(tp)case 0:System.out.println(系统退出);break;case 1:CompactDisk b = new CompactDisk();System.out.println(请输入光盘名称);b.setname(cin.next();System.out.println(请输入光盘的品牌);b.settype(cin.next();System.out.println(请输入光盘的价格);b.setprice(cin.nextFloat();System.out.println(请输入光盘的容量);b.setsize(cin.nextInt();boolean flagadd = text1.add(CompactDiskb,b);if(flagadd)System.out.println(添加成功!);elseSystem.out.println(添加失败!);break;case 2:CompactDisk Searchc = new CompactDisk();int search = -1;String key1 = ;System.out.println(请输入查询内容:1.按名称 2.按类型 3.按价格 4.按容量 5.列出所有产品);search = cin.nextInt();if(search = 1)System.out.println(请输入光盘的名称:);Searchc.setname(cin.next();CompactDisk resultb = text1.getCompactDiskByKey(CompactDiskb, Searchc);if(resultb != null)System.out.println(名称: + resultb.getname() + ,品牌: + resultb.gettype() + ,价格: + resultb.getprice() + ,容量: + resultb.getsize();elseSystem.out.println(没有匹配的光盘!);else if(search = 2)System.out.println(请输入光盘的类型:);Searchc.settype(cin.next();CompactDisk resultb = text1.getCompactDiskByKey(CompactDiskb, Searchc);if(resultb != null)System.out.println(名称: + resultb.getname() + ,品牌: + resultb.gettype() + ,价格: + resultb.getprice() + ,容量: + resultb.getsize();elseSystem.out.println(没有匹配的光盘!);else if(search = 3)System.out.println(请输入光盘的价格:);Searchc.setprice(cin.nextInt();CompactDisk resultb = text1.getCompactDiskByKey(CompactDiskb, Searchc);if(resultb != null)System.out.println(名称: + resultb.getname() + ,品牌: + resultb.gettype() + ,价格: + resultb.getprice() + ,容量: + resultb.getsize();elseSystem.out.println(没有匹配的光盘!);else if(search = 4)System.out.println(请输入光盘的容量:);Searchc.setsize(cin.nextInt();CompactDisk resultb = text1.getCompactDiskByKey(CompactDiskb, Searchc);if(resultb != null)System.out.println(名称: + resultb.getname() + ,品牌: + resultb.gettype() + ,价格: + resultb.getprice() + ,容量: + resultb.getsize();elseSystem.out.println(没有匹配的光盘!);break;case 3:System.out.println(请输入要删除光盘的光盘名);String name = cin.next();boolean flagde1 = text1.delete(CompactDiskb, name);if(flagde1)System.out.println(删除成功!);elseSystem.out.println(删除失败!);break;while(tp != 0); catch (Exception e1) System.out.println(输入了无效值!系统退出!);e1.printStackTrace(); /else if(choose = 3)BookMain text1 = new BookMain();Book Bookb = new Book100;int tp = -1;trydoSystem.out.println(1.添加 2.查找 3.删除 0.退出);System.out.println(请输入);Scanner cin = new Scanner(System.in);tp = cin.nextInt();switch(tp)case 0:System.out.println(系统退出);break;case 1:Book b = new Book();System.out.println(请输入书名);b.setname(cin.next();System.out.println(请输入书的类别);b.settype(cin.next();System.out.println(请输入书的价格);b.setprice(cin.nextFloat();System.out.println(请输入书的重量);b.setweight(cin.nextInt();boolean flagadd = text1.add(Bookb,b);if(flagadd)System.out.println(添加成功!);elseSystem.out.println(添加失败!);break;case 2:Book Searchb = new Book();int search = -1;String key1 = ;System.out.println(请输入查询内容:1.按名称 2.按类型 3.按价格 4.按重量 5.列出所有产品);search = cin.nextInt();if(search = 1)System.out.println(请输入书的名称:);Searchb.setname(cin.next();Book resultb = text1.getBookByKey(Bookb, Searchb);if(resultb != null)System.out.println(名称: + resultb.getname() + ,类型: + resultb.gettype() + ,价格: + resultb.getprice() + ,重量: + resultb.getweight();elseSystem.out.println(没有匹配的书!);else if(search = 2)System.out.println(请输入书的类型:);Searchb.settype(cin.next();Book resultb = text1.getBookByKey(Bookb, Searchb);if(resultb != null)System.out.println(名称: + resultb.getname() + ,类型: + resultb.gettype() + ,价格: + resultb.getprice() + ,重量: + resultb.getweight();elseSystem.out.println(没有匹配的书!);else if(search = 3)System.out.println(请输入书的价格:);Searchb.setprice(cin.nextInt();Book resultb = text1.getBookByKey(Bookb, Searchb);if(resultb != null)System.out.println(名称: + resultb.getname() + ,类型: + resultb.gettype() + ,价格: + resultb.getprice() + ,重量: + resultb.getweight();elseSystem.out.println(没有匹配的书!);else if(search = 4)System.out.println(请输入书的重量:);Searchb.setweight(cin.nextInt();Book resultb = text1.getBookByKey(Bookb, Searchb);if(resultb != null)System.out.println(名称: + resultb.getname() + ,类型: + resultb.gettype() + ,价格: + resultb.getprice() + ,重量: + resultb.getweight();elseSystem.out.println(没有匹配的书!);break;case 3:System.out.println(请输入要删除书的书名);String name = cin.next();boolean flagde1 = text1.delete(Bookb, name);if(flagde1)System.out.println(删除成功!);elseSystem.out.println(删除失败!);break;while(tp != 0); catch (Exception e1) System.out.println(输入了无效值!系统退出!);e1.printStackTrace(); /else if(choose = 4) TapeMain text1 = new TapeMain(); Tape Bookb = new Tape100;int tp = -1;trydoSystem.out.println(1.添加 2.查找 3.删除 0.退出);System.out.println(请输入);Scanner cin = new Scanner(System.in);tp = cin.nextInt();switch(tp)case 0:System.out.println(系统退出);break;case 1:Tape b = new Tape();System.out.println(请输入磁带名);b.setname(cin.next();System.out.println(请输入磁带的类别);b.settype(cin.next();System.out.println(请输入磁带的价格);b.setprice(cin.nextFloat();System.out.println(请输入磁带的厂家);b.setautor(cin.next();boolean flagadd = text1.add(Tapeb,b);if(flagadd)System.out.println(添加成功!);elseSystem.out.println(添加失败!);break;case 2:Tape Searchb = new Tape();int search = -1;String key2 = ;System.out.println(请输入查询内容:1.按名称 2.按类型 3.按价格 4.按出厂厂家 5.列出所有产品);search = cin.nextInt();if(search = 1)System.out.println(请输入磁带的名称:);Searchb.setname(cin.next();Tape resultb = text1.getTapeByKey(Tapeb, Searchb);if(resultb != null)System.out.println(名称: + resultb.getname() + ,类型: + resultb.gettype() + ,价格: + resultb.getprice() + ,厂家: + resultb.getautor();elseSystem.out.println(没有匹配的磁带!);else if(search = 2)System.out.println(请输入磁带的类型:);Searchb.settype(cin.next();Tape resultb = text1.getTapeByKey(

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论