java - Create object from line in textfile -


i have question creating objects in java. new, doing things , hope it's working it's not, unfortunately. have create objects lines in textfile. have peace of code prints seperate lines, took me long time though it's not hard, stuck. have 5 lines, each line containing name of tv program, begin time, end time, subtitle, etcetera. how can seperate lines in different objects? objects program1, program2, program3, title , subtitle , times in object (i put them in code, know it's wrong, don't know how right). have create constructor? (i think do, put in brackets?) lot of questions, know, haha:) have (it prints lines, tried array, have lines seperately in array (line 1, line 2, 3, 4, 5) not working..:

public class split {  public static void main(string[] args) throws ioexception {      file file = new file("/users/-/documents/workspace/opdracht 2/program");  scanner scr = new scanner(file);  while (scr.hasnextline()) {      string line = scr.nextline();      string[] array = line.split("\n");      system.out.println(array);        }  split programma1 = new split(string);  split programma2 = new split(string);  split programma3 = new split(string);  split programma4 = new split(string);  split programma5 = new split(string); }   } 

thankyou!

you should first try create class have attributes title, starttime, endtime etc instance variables.

you can have constructor takes in these variables parameters or can go setter methods initialize each member independently.

1) read line file, represents tv show.

2) create object of class mentioned above.

3) either pass parameters in constructor or call setter methods depending on approach have chosen.

from way have asked question, suggest first go through basics of java instead of directly jumping , start programming. try understand concepts , find them easy apply.


Comments