import java.io.Console;
import java.util.ArrayList;
public class IteratorEx5 {
public static void main(String[] args) {
Console console=System.console();
String movie="";
String Subscriber="";
String movieType="";
ArrayList<Subscriber> sub=new ArrayList<Subscriber>();
String stop;
BlockBuster dvd= new BlockBuster();
while(true){
System.out.println("Enter the movies name");
movie=console.readLine();
System.out.println("Enter the movies name");
Subscriber=console.readLine();
System.out.println("Enter the movies name");
movieType=console.readLine();
System.out.println("Enter the movies name");
System.out.println("if you want to stop type "+" Stop "+ "if not type Continue");
stop=console.readLine();
if(stop.equals("Stop"))
return;
sub.add(new Subscriber(movie, Subscriber,movieType));
} // end of while loop
Tape iterator=dvd.iterator();// problem it says the code is not reachable. why does it even care?
while (iterator.hasNext()) {
Subscriber person = (Subscriber) iterator.next();
}
}
}
///interfaces definitions////////////////////////////////////////////////////////////
interface DVD{
public Tape iterator();
}
interface Tape{
public boolean hasNext();
public Subscriber next();
}
///////outer and inner classes and iterator methods/////////////
class BlockBuster implements DVD{
ArrayList<Subscriber> sub=new ArrayList<Subscriber>();
class MovieShop implements Tape{
int index;
@Override
public Subscriber next() {
// TODO Auto-generated method stub
return sub.get(index++);
}
@Override
public boolean hasNext() {
// TODO Auto-generated method stub
return index<sub.size();
}
}
@Override
public Tape iterator() {
return new MovieShop();
}
public void print(){
System.out.println(sub);
}
}
/////////my subscriber class////////////////////////////////////////////
class Subscriber{
String movie;
String Subscriber;
String movieType;
public Subscriber(String movie, String subscriber, String movieType) {
super();
this.movie = movie;
Subscriber = subscriber;
this.movieType = movieType;
}
@Override
public String toString() {
return "Subscriber [Subscriber=" + Subscriber + ", movie=" + movie
+ ", movieType=" + movieType + "]";
}
}
so the problem is due to lack of visibility. i want to create types of subscribers (let the user type the info) and send those type to an arraylist called "sub". then i want to print that arraylist.. problem is it says "the code is not reachable"
at the line indicated after the while loop