• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Generics IO using input from console

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

//I can make an interface and a javabean with getters and setters, but with the code below not able to get movie out to console after entering director name.

import java.io.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;

import java.io.IOException;
import java.sql.Connection;
import java.util.Enumeration;



public class ChosenDirector {


//Create a buffered reader to read
//each line from the keyboard.

static ArrayList<String> chosendirector=new ArrayList<String>();

public static void main(String args[]) throws IOException {
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(ir);
String director=" "; // Note: here we are assuming Director could
String movie= " "; // or will be different for each user.
String FILE_NAME = "Directormovies.txt";
String s;
//////////////////////////////////////////////////////////
// read the DIRECTOR information from the console, and
//when director name is entered his movie should come from FILE_NAME Wild at Heart, The Muppets, Jurassic Park, Batman, and RockyVI
//////////////////////////////////////////////////////////
System.out.println ("Enter Director name to get Movie : David Lynch, Jim Henson, Stephen Spielberg, Tim Burton or, Aki Kaurismaki");

//StringBuffer stdin = StringBuffer;{

System.out.print("NAME OF DIRECTOR: \n" );
s = in.readLine();
try {

} catch (SecurityException se) {

// read the Director and Movie information from the file
//System.out.println("About to read Director info from file "
// + FILE_NAME);
File srcFile = new File(FILE_NAME);

//print out the Director name and his movie
File c = srcFile;

for(String c1: chosendirector)
{
String[] temp = c1.split(":");
//now we should have temp[0] = "director" and temp[1] = "movie"
chosendirector.add(c1);
}

while (director.split(movie)!=null) {
String[] tokens = director.split("[:]+");

System.out.println("Name of Director is: "+ director + "and movie is:"+ movie);

}

}
}
}














 
this is supposed to be a surprise, but it smells like a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic