Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
එක පැකේජ් එකයි මාසෙටම Unlimited Internet. තාමත් DATA CARD දාන්න සල්ලි වියදම් කරනවද? අඩුම මිලට අපෙන්.
sayuru bandara
Updated:
Tuesday at 12:30 PM
Ad icon
ඉන්ටර්නෙට් එකෙන් හරියටම සල්ලි හොයන්න සහ Success වෙන්න කැමතිද? 🚀 (E-Money & Success Stories)
siri sumana
Updated:
Saturday at 11:44 PM
Gemini AI PRO 18 months Offer
Hawaka
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
Education
Java Code Help!!!
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="amilabanuka" data-source="post: 17867405" data-attributes="member: 5836"><p>Issue 1:</p><p>* you just print the array object in the main method. that will contain the the results of last player. </p><p></p><p>solution: add getter and print or add a method to skater to return the correct string. second solution is the best one but for the simplicity I have added 1st solution. </p><p></p><p>Issue 2:</p><p>*In Line 17 and 18, you initialize the array.</p><p>*Once the array is filled with individual's scores you create the skater instance passing the array references. but for the next skater, you reuse the same array. the content of the array is overridden.</p><p>* so at the end of reading all the skater objects will have same two arrays and it will contain the results of last read</p><p>* you'll get the results of the last read.</p><p></p><p></p><p>a solution</p><p>initialize the array for each iteration.</p><p></p><p></p><p>[CODE]</p><p>import java.io.*;</p><p>import java.util.Scanner;</p><p>public class testSkaters {</p><p></p><p> private static final int NUMBER_OF_JUDGES = 8;</p><p></p><p> public static void main(String[] args) throws IOException {</p><p></p><p></p><p></p><p> Skaters [] arrSkaters = new Skaters [50];</p><p></p><p> File myFile = new File ("Pairs.txt");</p><p></p><p> Scanner input = new Scanner (myFile);</p><p></p><p> int countSkaters = 0;</p><p> String name1;</p><p> String name2;</p><p> String country;</p><p> double [] arr1 = null;</p><p> double [] arr2 = null;</p><p></p><p></p><p> while (input.hasNext())</p><p></p><p> {</p><p></p><p> name1 = input.nextLine();</p><p> name2 = input.nextLine();</p><p> country = input.nextLine();</p><p> arr1=new double[8];</p><p> for (int i = 0; i < NUMBER_OF_JUDGES; i++)</p><p></p><p> arr1[i] = input.nextDouble();</p><p></p><p> arr2=new double[8];</p><p> for (int j =0; j < NUMBER_OF_JUDGES; j++)</p><p></p><p> arr2[j] = input.nextDouble();</p><p></p><p></p><p> Skaters s1 = new Skaters (name1, name2, country, arr1, arr2);</p><p></p><p> arrSkaters[countSkaters] = s1;</p><p></p><p> countSkaters++;</p><p></p><p> input.nextLine();</p><p></p><p> }</p><p></p><p></p><p></p><p> for (int t = 0; t < countSkaters; t++)</p><p></p><p> {</p><p> System.out.println("Name 1: " + arrSkaters[t].getName1());</p><p></p><p> System.out.println("Name 2: " + arrSkaters[t].getName2());</p><p></p><p> System.out.println("Country: " + arrSkaters[t].getCountry());</p><p> printArray(arrSkaters[t].getArrTech());</p><p></p><p> }</p><p></p><p></p><p> }</p><p></p><p></p><p> public static void printArray (double [] arr3)</p><p> {</p><p> for (int r = 0; r < arr3.length;r++)</p><p></p><p> System.out.print(arr3[r]);</p><p> System.out.println("");</p><p></p><p></p><p> }</p><p></p><p>}</p><p>[/CODE]</p></blockquote><p></p>
[QUOTE="amilabanuka, post: 17867405, member: 5836"] Issue 1: * you just print the array object in the main method. that will contain the the results of last player. solution: add getter and print or add a method to skater to return the correct string. second solution is the best one but for the simplicity I have added 1st solution. Issue 2: *In Line 17 and 18, you initialize the array. *Once the array is filled with individual's scores you create the skater instance passing the array references. but for the next skater, you reuse the same array. the content of the array is overridden. * so at the end of reading all the skater objects will have same two arrays and it will contain the results of last read * you'll get the results of the last read. a solution initialize the array for each iteration. [CODE] import java.io.*; import java.util.Scanner; public class testSkaters { private static final int NUMBER_OF_JUDGES = 8; public static void main(String[] args) throws IOException { Skaters [] arrSkaters = new Skaters [50]; File myFile = new File ("Pairs.txt"); Scanner input = new Scanner (myFile); int countSkaters = 0; String name1; String name2; String country; double [] arr1 = null; double [] arr2 = null; while (input.hasNext()) { name1 = input.nextLine(); name2 = input.nextLine(); country = input.nextLine(); arr1=new double[8]; for (int i = 0; i < NUMBER_OF_JUDGES; i++) arr1[i] = input.nextDouble(); arr2=new double[8]; for (int j =0; j < NUMBER_OF_JUDGES; j++) arr2[j] = input.nextDouble(); Skaters s1 = new Skaters (name1, name2, country, arr1, arr2); arrSkaters[countSkaters] = s1; countSkaters++; input.nextLine(); } for (int t = 0; t < countSkaters; t++) { System.out.println("Name 1: " + arrSkaters[t].getName1()); System.out.println("Name 2: " + arrSkaters[t].getName2()); System.out.println("Country: " + arrSkaters[t].getCountry()); printArray(arrSkaters[t].getArrTech()); } } public static void printArray (double [] arr3) { for (int r = 0; r < arr3.length;r++) System.out.print(arr3[r]); System.out.println(""); } } [/CODE] [/QUOTE]
Insert quotes…
Verification
Dawasata paya keeyak thibeda?
Post reply
Top
Bottom