当前位置: 首页 > news >正文

台湾省网站建设_网站建设公司_展示型网站_seo优化

建站长沙,创建wordpress主题,怎么给网站加外链,八桂职教网登录入口以前定义的IntegerStack接口#xff0c;只能用于存放Integer类型的数据。然而对于栈来说#xff0c;不管内部存放的是什么类型的数据#xff0c;基本操作与元素的具体类型无关。 1. 编写一个通用的GeneralStack接口#xff0c;接口中的操作对任何引用类型的数据都适用。 …以前定义的IntegerStack接口只能用于存放Integer类型的数据。然而对于栈来说不管内部存放的是什么类型的数据基本操作与元素的具体类型无关。 1. 编写一个通用的GeneralStack接口接口中的操作对任何引用类型的数据都适用。 一旦定义完毕只能存放一种类型的数据比如只能存放String或只能存放Integer。GeneralStack接口方法如下 push(item); //如item为null则不入栈直接返回null。 pop(); //出栈如为栈为空则返回null。 peek(); //获得栈顶元素如为空则返回null. public boolean empty();//如为空返回true public int size(); //返回栈中元素数量2.定义GeneralStack的实现类ArrayListGeneralStack 内部使用ArrayList对象存储属性名为list。 方法:public String toString()//该方法的代码为return list.toString(); 提示 不用使用top指针。直接复用ArrayList中已有的方法。pop时应将相应的元素从ArrayList中移除。代码中不要出现类型不安全的强制转换。 3.定义Car对象 属性 private int id; private String name;方法Eclipse自动生成setter/getter,toString方法。 4.main方法说明 输入选项有quit, Integer, Double, Car4个选项。如果输入quit则直接退出。否则输入整数m与n。m代表入栈个数n代表出栈个数。然后声明栈变量stack。输入Integer,打印Integer Test。建立可以存放Integer类型的ArrayListGeneralStack。入栈m次出栈n次。打印栈的toString方法。最后将栈中剩余元素出栈并累加输出。输入Double 打印Double Test。剩下的与输入Integer一样。输入Car打印Car Test。其他操作与Integer、Double基本一样。只不过最后将栈中元素出栈并将其name依次输出。 2、3、4步骤做完都要使用代码System.out.println(stack.getClass().getInterfaces()[0]);打印标识信息 特别注意如果栈为空的时候继续出栈则返回null 输入样例 Integer 5 2 1 2 3 4 5 Double 5 3 1.1 2.0 4.9 5.7 7.2 Car 3 2 1 Ford 2 Cherry 3 BYD quit输出样例 Integer Test push:1 push:2 push:3 push:4 push:5 pop:5 pop:4 [1, 2, 3] sum6 interface GeneralStack Double Test push:1.1 push:2.0 push:4.9 push:5.7 push:7.2 pop:7.2 pop:5.7 pop:4.9 [1.1, 2.0] sum3.1 interface GeneralStack Car Test push:Car [id1, nameFord] push:Car [id2, nameCherry] push:Car [id3, nameBYD] pop:Car [id3, nameBYD] pop:Car [id2, nameCherry] [Car [id1, nameFord]] Ford interface GeneralStack import java.util.*;interface GeneralStack{public Object push(Object item);public Object pop();public Object peek();public boolean empty();public int size(); }class ArrayListGeneralStack implements GeneralStack{ArrayList list new ArrayList();//重写接口的方法//Object 是 Java 中的一个预定义类它是所有类的父类。//使用 Object 类作为参数类型意味着这个方法可以接受任何类型的对象作为输入。Override//如item为null则不入栈直接返回null。public Object push(Object item){if(itemnull){return null;}else{list.add(item);return item;//入栈的同时作为输出结果}}Override//出栈如为栈为空则返回null。public Object pop(){if(list.size()0){return null;}else{return list.remove(list.size()-1);}}Override//获得栈顶元素如为空则返回null.public Object peek(){if(list.size()0){return null;}else{return list.get(list.size()-1);}}Override//如为空返回truepublic boolean empty(){if(list.size()0){return true;}else{return false;}}Override//返回栈中元素数量public int size(){return list.size();}Overridepublic String toString(){return list.toString();} }class Car{private int id;private String name;public int getId(){return id;}public String getName(){return name;}public void setName(String name){this.namename;}public void setId(int id){this.idid;}Car(int id,String name){this.idid;this.namename;}public String toString(){return Car [idid, namename];} }public class Main{public static void main(String[] args){Scanner sc new Scanner(System.in);while (true){String ssc.nextLine();if (s.equals(Double)){System.out.println(Double Test);int countsc.nextInt();int pop_timesc.nextInt();//出栈次数ArrayListGeneralStack arrayListGeneralStack new ArrayListGeneralStack();for (int i0;icount;i){System.out.println(push:arrayListGeneralStack.push(sc.nextDouble()));}for (int i0;ipop_time;i){System.out.println(pop:arrayListGeneralStack.pop());}System.out.println(arrayListGeneralStack.toString());double sum0;int sizearrayListGeneralStack.size();for (int i0;isize;i){sum(double)arrayListGeneralStack.pop();}System.out.println(sumsum);System.out.println(interface GeneralStack);}else if (s.equals(Integer)){System.out.println(Integer Test);int countsc.nextInt();int pop_timesc.nextInt();ArrayListGeneralStack arrayListGeneralStack new ArrayListGeneralStack();for (int i0;icount;i){System.out.println(push:arrayListGeneralStack.push(sc.nextInt()));}for (int i0;ipop_time;i){System.out.println(pop:arrayListGeneralStack.pop());}System.out.println(arrayListGeneralStack.toString());int sum0;int sizearrayListGeneralStack.size();for (int i0;isize;i){sum(int)arrayListGeneralStack.pop();}System.out.println(sumsum);System.out.println(interface GeneralStack);}else if (s.equals(Car)){System.out.println(Car Test);int countsc.nextInt();int pop_timesc.nextInt();ArrayListGeneralStack arrayListGeneralStack new ArrayListGeneralStack();for (int i0;icount;i){int idsc.nextInt();String namesc.next();Car car new Car(id,name);System.out.println(push:arrayListGeneralStack.push(car));}for (int i0;ipop_time;i){System.out.println(pop:arrayListGeneralStack.pop());}System.out.println(arrayListGeneralStack.toString());if (arrayListGeneralStack.size()0){int sizearrayListGeneralStack.size();for (int i0;isize;i){Car car(Car) arrayListGeneralStack.pop();System.out.println(car.getName());}}System.out.println(interface GeneralStack);}else if (s.equals(quit)){break;}}} }
http://www.lebaoying.cn/news/15566.html

相关文章:

  • 浙江怎么制作网站金融审核网站制作
  • 加强网站安全建设说明报告范文装修房子图片
  • 建设农产品网站总结pptc 网站开发需要什么
  • 织梦网站搬家数据库建企业网站教程
  • 做彩票网站要多大服务器安卓手机脚本开发工具
  • 在国外网站上买机票怎样做财务榆林尚呈高端网站建设
  • 网站 改版做软件挣钱的网站
  • 城市绿化建设英文网站网站开发维护求职信
  • 临潼网站建设浙江新东阳建设集团有限公司网站
  • 怎样开自己的网站wordpress批量添加文章
  • 网站内链建设的方法淘宝网网页版登录入口在哪里
  • 连云港新站优化网页设计及制作方法
  • 三亚做民宿的都用什么网站信誉好的电商网站建设
  • 单页网站规划设计书岚山网站建设报价
  • 网站建设如何传视频上海企业都用什么网站
  • 邢台网站优化网站开发的有关公司
  • 中铁韩城建设公司网站郑州建材网站建设
  • 中国营销传播网app织梦做的网站能做seo吗
  • 网站建设管理成本估计申请建设网站的报告书
  • 网站快速备案通道专业做网站app的公司哪家好
  • seo网站优化论文wordpress 分类信息 主题
  • 做网络传销网站犯法吗10年中文域名注册多少费用
  • 贵州省住房和城乡建设厅查询网站便宜网站建设价格
  • 建站超市网站开发总体设计
  • 在中国做网站网站违法吗建设工程安全员教育网站
  • 福建省建设人才市场网站做网站学什么软件
  • 天津企业设计网站建设网站建设前期
  • 公司网站制作都需要图片wordpress占内存
  • 做装饰材料的网站设计业务网站
  • 原创文章对网站的好处html注册登录模板