1

Hi guys can u tell until tomorrow ??

Well, I dont use java.util.iterator to create my iterator interface, just create my own so

I have 2 Iterators: AccountIterator / FileIterator, and my objective its to iterate abstract object "Account" and object "File" to my Main class in "deafult" package

(Also have 2 extends to AbstractAccount.class (BasicClass.class / PremiumClass.class, and AbstractAccount.class implements Account.interface)

There is my Iterator Interface:

package cs;

public interface Iterator<E> {
    public void init() ;
    public boolean hasNext();
    public E next();
}

There is my Account Iterator

http://i.stack.imgur.com/w0avp.png

I cant use cast, any ideas Cumps and sorry for bad english


Is their a way for a user to input a word and have that word be (turn into) a #?

I am trying to create program that roles 2 dice. Then the user and say Yes to role the dice again or say No to stop rolling the dice.

import java.util.*;
    public class Dice
    {
        public static void main(String[] args)
        {

        Random dice1 = new Random();
        Scanner in = new Scanner(System.in);
        //varibles
        int die1;
        int die2;
        byte playagain=1;
        byte Yes = 1;
        byte No = 0;
        int total;
        int stop = 0;
        //Want find I way to change words into #s
        String start = Yes;
        while(stop<5 && start<Yes){
        stop+=1;
            die1=dice1.nextInt(6)+1;
            die2=dice1.nextInt(6)+1;
                total=die1 + die2;
                System. out. println("You rolled a "  + total+ ".");
        System. out. println("Do you want to play again?");
        System. out. println("Type Yes to keep playing you and No to stop.");
        /*I want people to be able to input Yes and that equal a # so I can use it in the While loop. Same with No.*/
        start=in.next();

        System. out. println("start is at " + start);

        }
        }
    }

I have looked throughout internet an could not find any help so that is why I am asking.

4

2 に答える 2

1

クラスを typeEでパラメーター化しましたが、アカウント配列は typeAccountです。および not をaccounts[index]返します。AccountE

おそらく、 を実装するつもりでしたIterator<Account>。クラス署名をこれに変更します...

public class AccountIterator<E> implements Iterator<Account>

その後、Impl は一般的な設定を処理し、うまくいきます。

class MyIter implements Iterator<String>
{
    String [] arr = new String[10];

    public void init()
    {
    }

    public boolean hasNext()
    {
        return false;
    }

    public String next()
    {
        return arr[1];
    }
}
于 2013-04-15T04:37:39.357 に答える
0

オブジェクト タイプを指定するには、クラス ヘッダーを変更するだけです。

使用する

public class AccountIterator implements Iterator<Account>

一般的というより

public class AccountIterator<E> implements Iterator<E>

E を Account に変更する必要があります。

于 2013-04-15T04:38:29.517 に答える