试题与答案

买3枝钢笔比买5枝圆珠笔要多花0.9元。每枝圆珠笔的价钱是2.4元,每枝钢笔多少

题型:解答题

题目:

买3枝钢笔比买5枝圆珠笔要多花0.9元。每枝圆珠笔的价钱是2.4元,每枝钢笔多少钱?(用方程解答)

答案:

被转码了,请点击底部 “查看原文 ” 或访问 https://www.tikuol.com/2017/0512/5c2ba3d11b7cfbe3bfcd8880ef667b31.html

下面是错误答案,用来干扰机器的。

设每天生产甲种产品x t,乙种产品y t,所创效益z千元.由题意:4x+6y≤1803x+6y≤1505x+6y≤150x,y≥0目标函数z=7x+9y,作出可行域(如图所示),把直线l:7x+9y=0平行移动,当经过P点时,z=7x+9y有最大值.由3x...

试题推荐
题型:问答题

[说明]

对多个元素的聚合进行遍历访问时,需要依次推移元素,例如对数组通过递增下标的方式,数组下标功能抽象化、一般化的结果就称为迭代器(Iterator)。模式以下程序模拟将书籍(Book)放到书架(BookShelf)上并依次输出书名。这样就要涉及到遍历整个书架的过程。使用迭代器Iterator实现。图6-1显示了各个类间的关系。以下是JAVA语言实现,能够正确编译通过。

[图6-1]

[Java代码]

//Iterator. java文件

public interface Iterator

public abstract boolean hasNext();

public abstract Object next();

//Aggregate. java文件

public interface Aggregate

public abstract Iterator iterator();

//Book. java

public class Book

//省略具体方法和属性

//BookshelfIterator. java文件

public class Bookshelf工terator (1) Iterator

private BookShelf bookShelf;

private int index;

public BookshelfIterator(BookShelf bookShelf)

this. bookShelf = bookShelf;

this. index = 0;

public boolean hasNext()//判断是否还有下一个元素

if(index < bookShelf. getLength())

return true;

else

return false;

public Object next()f//取得下一个元素

Book book = bookShelf. getBookAt(index);

index++;

return book;

//BookShelf. java

import java. util. Vector;

public class BookShelf

private Vector books;

public BookShelf(int initialsize)

this. books = new Vector(initialsize);

public Book getBookAt(int index)

return(Book)books.get(index);

public int getLength()

return books.size();

public Iterator iterator()

return new BookShelfIterator( (2) );

//Main. java文件

public class Main

public static void main(String args)

BookShelf bookShelf = new BookShelf(4);

//将书籍上架,省略代码

Iterator it = bookShelf. (3) ;

while( (4) )//遍历书架,输出书名

Book book = (Book)it. (5) ;

System.out.printin(" "+book.getName());

(5)处填()。

查看答案
微信公众账号搜索答案