OOP two class version of the same program /* * Read in a text file with delimiters * Two class - OOP version */ package textfileoop; public class SixASideTextOOPUI { public static void main(String[] args) { SixASideManager sm = new SixASideManager(); sm.displayAll(); } } ============================================================== /* * OOP version. * Reading in a text file with three separate values per line * Example: Comet#red and yellow#2776.56 * Display all method to display the contents of the 3 arrays */ package textfileoop; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import javax.swing.JOptionPane; public class SixASideManager { // One array for the team name, one for the colours and one for funds String [] teamName = new String[20]; String [] teamColours = new String[20]; double [] teamFunds = new double[20]; int size = 0; double totalFunds = 0.0; SixASideManager(){ // Populate the three arrays // Reads in a text file and separates the values, each into their own // array try { Scanner scFile = new Scanner(new File("SixASideBeachTextB.txt")); while (scFile.hasNext()) { String line = scFile.nextLine(); Scanner scLine = new Scanner(line).useDelimiter("#"); teamName[size] = scLine.next(); teamColours[size] = scLine.next(); teamFunds[size] = scLine.nextDouble(); size++; } } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(null, "Error! File not found"); System.exit(0); } System.out.println("Success"); } // end constructor public void displayAll() { for (int i = 0; i < size; i++ ) { System.out.println(teamName[i] + "\t" + "\t"+ teamColours[i] + "\t" + "\t" + teamFunds[i]); totalFunds = totalFunds + teamFunds[i]; } System.out.println(); System.out.println("============================================="); System.out.println("Total amount of funds raised by the teams is R" + totalFunds); } } // end class ================================================================================== OUTPUT - Do not worry about neat columns at this stage Mercury red and green 1767.99 Venus red 1565.34 Mars green 2316.39 Jupiter white 1452.12 Saturn white and black 2198.19 Uranus green stripes 1554.98 Neptune yellow and orange 1567.76 Astroid orange 1784.87 Comet red and yellow 2776.56 Rhea blue 1655.45 Callisto blue stripes 1589.34 Io light blue 2578.54 Europa purple and orange 1686.66 Ceres blue and black 2686.44 Luna purple 1654.34 Titan black and red 1876.98 Hyperion green and dark red 2876.34 Janus grey and red 1879.45 Oberon black and yellow 1879.53 Ariel black stripes 2876.34 ============================================= Total amount of funds raised by the teams is R40223.61