java - Read a string file as ints into an array? -


i need write program takes input file name, age, , score information of golfer (practice.txt). file should compare scores par scores specific age group. example: manny 14, follows par scores 12-15 age group. manny shot 5 on hole one, made par. i'm having trouble understanding how compare between file , array? code or ideas me on way great.

input file practice.txt:

jay 57 4 3 2 3 5 3 2 3 4

gloria 39 4 4 3 4 3 4 3 3 5

manny 14 5 6 4 6 5 6 4 4 6

joe 3 9 8 8 7 6 6 7 5 7

par scores chart:

                           holes age             1   2   3   4   5   6   7   8   9  4 , under     8   8   9   7   5   7   8   5   8 5 – 7           7   7   8   6   5   6   7   5   6 8 – 11          6   5   6   5   4   5   5   4   5 12 – 15         5   4   4   4   3   4   3   3   4 16 , on     4   3   3   3   2   3   2   3   3 

what have:

import java.io.file; import java.util.scanner; import java.util.list; import java.io.filenotfoundexception; import java.util.arraylist;  public class imtryinghere {  public static void main (string[] args) throws filenotfoundexception   {       int [][] agegroups =      {        {4},        {7},        {11},        {15},        {100},     };      int[][] holepars=     {       {8,8,9,7,5,7,8,5,8},       {7,7,8,6,5,6,7,5,6},       {6,5,6,5,4,5,5,4,5},       {5,4,4,4,3,4,3,3,4},       {4,3,3,3,2,3,2,3,3},    };     } } 

try this.

// put age , par scores map static map<integer, list<integer>> ageparslist = new linkedhashmap<integer, list<integer>>() {     {put(4,  new linkedlist<integer>(arrays.aslist(8, 8, 9, 7, 5, 7, 8, 5, 8)));}     {put(7,  new linkedlist<integer>(arrays.aslist(7, 7, 8, 6, 5, 6, 7, 5, 6)));}     {put(11, new linkedlist<integer>(arrays.aslist(6, 5, 6, 5, 4, 5, 5, 4, 5)));}     {put(15, new linkedlist<integer>(arrays.aslist(5, 4, 4, 4, 3, 4, 3, 3, 4)));}     {put(-1, new linkedlist<integer>(arrays.aslist(4, 3, 3, 3, 2, 3, 2, 3, 3)));} };  public static list<integer> getparscoreslist(int age) {      int targetage = -1;     (integer key : ageparslist.keyset()) {         if (age <= key) {             targetage = key;             break;         }     }      return ageparslist.get(targetage);       }  public static class player {     string name;     int age;     list<integer> scorelist;      public player(string name, int age, list<integer> scorelist) {         this.name = name;         this.age  = age;         this.scorelist = scorelist;     } }  private static list<player> getplayerscore() {     scanner scan = null;     try{           file file = new file(_path_to_file_);           scan = new scanner(file);             list<player> playerlist = new arraylist<player>();            while (scan.hasnext()) {               string name = scan.next();               int age = scan.nextint();               list<integer> scorelist = new linkedlist<integer>();               (int = 0; < 9; i++) {                   scorelist.add(scan.nextint());               }               scan.nextline(); // last line must have newline character.                player player = new player(name, age, scorelist);               playerlist.add(player);           }                       return playerlist;     } catch(filenotfoundexception e){         system.out.println(e);         return null;     } {         if (scan != null) {             scan.close();         }     } }  public static void main (string[] args) {     list<player> playerlist = getplayerscore();      (player player : playerlist) {         list<integer> parscoreslist = getparscoreslist(player.age);          (int = 0; < 9; i++) {             int score = player.scorelist.get(i);             int par   = parscores.get(i);              // compare player's score , par score here.         }     } } 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -