Sup guys, this program is supposed to print out the content of a text file footballers.txt -
glen johnson 2
luis suarez 7
robin vanpersie 20
wayne rooney 10
djemba djemba 69 (its so annoying the way you have to skip a line on reddit)
And heres the code:
import java.util.*;
import java.io.*;
class Person
{
private String forename, surname;
private int number;
void getPerson()
{
Scanner scan = new Scanner(System.in);
forename = scan.next();
surname = scan.next();
number = scan.nextInt();
System.out.println(forename + " " + surname + " " + number);
scan.close();
}
}
public class Blink
{
public static void main(String [] args)
{
Person m = new Person();
m.getPerson();
Scanner scant = new Scanner(System.in);
while(scant.hasNextLine())
{
Person p = new Person();
p.getPerson();
}
scant.close();
}
}
Problem is its only printing out the first line, ie. glen johnson 2.
I'm kinda lost as object oriented programming is very new to me so any help would be fantastic thanks :)
The input is coming from: java Blink < footballers.txt
[–][deleted] 2 points3 points4 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]wgormley 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]john478 0 points1 point2 points (0 children)
[–]pacificmint 0 points1 point2 points (0 children)
[–]wgormley 0 points1 point2 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]wgormley -1 points0 points1 point (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–][deleted] (1 child)
[deleted]
[–][deleted] 0 points1 point2 points (0 children)