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="Tulip_Doll" data-source="post: 17864565" data-attributes="member: 525365"><p><span style="font-size: 12px"><u>Here is the Question:</u></span></p><p><span style="font-size: 12px"><u></u></span> </p><p>The international Olympics Committee has asked you to write a program to process the data and determine the medal winners for the pairs figure skating. You will be given the following file:</p><p>Pairs.txt</p><p></p><p>Which contains the data for each pair of skaters. The data consists of each skater’s name, their country and the score from each of eight judges on the technical aspects and on the performance aspects. A typical record would be as follows:</p><p></p><p>Smith</p><p>Jones</p><p>Australia</p><p>5.0 4.9 5.1 5.2 5.0 5.1 5.2 4.8</p><p>4.3 4.7 4.8 4.9 4.6 4.8 4.9 4.5</p><p></p><p>The final score for each skater is the sum of the average of the two categories of score. </p><p></p><p>Design a class to hold the above data and the final score. Read the data in from the file and calculate the final score for each pair. Sort the array of objects , and display the results on the screen in order, giving special prominence to the medal winners.</p><p></p><p><span style="font-size: 15px"><u>Here is my Class:</u></span></p><p><span style="font-size: 15px"><u></u></span></p><p></p><p>[CODE]</p><p>public class Skaters {</p><p></p><p> private String name1;</p><p> private String name2;</p><p> private String country;</p><p> private double [] arrTech = new double [8];</p><p> private double [] arrArt = new double [8];</p><p> private double score;</p><p> </p><p> </p><p>public Skaters (String n1, String n2, String c1, double [] arrT, double [] arrA) </p><p></p><p>{</p><p> this.name1 = n1;</p><p> this.name2 = n2;</p><p> this.country = c1;</p><p> this.arrTech = arrT;</p><p> this.arrArt = arrA;</p><p> </p><p> </p><p>}</p><p> public void setName1(String n1)</p><p> </p><p> {</p><p> name1 = n1;</p><p> }</p><p> </p><p> public void setName2(String n2)</p><p> </p><p> {</p><p> name2 = n2;</p><p> }</p><p> </p><p> public void setCountry(String c1)</p><p> </p><p> {</p><p> country = c1;</p><p> }</p><p></p><p> public void setArrTech (double [] arrT)</p><p> </p><p> {</p><p> arrTech = arrT; </p><p> }</p><p> </p><p> public void setArrArt(double [] arrA)</p><p> </p><p> {</p><p> arrArt = arrA;</p><p> }</p><p> </p><p> public String getName1()</p><p> </p><p> {</p><p> return name1;</p><p> }</p><p> </p><p> public String getName2()</p><p> </p><p> {</p><p> return name2;</p><p> }</p><p> </p><p> public String getCountry()</p><p> </p><p> {</p><p> return country;</p><p> }</p><p> </p><p> </p><p> public double getScore()</p><p> </p><p> {</p><p> double sum = 0, avg1, avg2;</p><p> </p><p> for (int r = 0; r < arrTech.length; r++)</p><p> </p><p> sum += arrTech[r];</p><p> </p><p> avg1 = sum/arrTech.length;</p><p> </p><p> sum = 0;</p><p> </p><p> for (int s = 0; s < arrArt.length; s++)</p><p> </p><p> sum += arrArt[s];</p><p> </p><p> avg2 = sum/arrArt.length;</p><p> </p><p> return (avg1 + avg2);</p><p> }</p><p> </p><p> </p><p> </p><p> </p><p>}</p><p>[/CODE]</p><p></p><p><u><span style="font-size: 15px">This is my main: </span></u></p><p></p><p>[CODE]import java.io.*;</p><p>import java.util.Scanner;</p><p>public class testSkaters {</p><p></p><p> public static void main(String[] args) throws IOException { </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 = new double [8];</p><p> double [] arr2 = new double [8];</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> </p><p> for (int i = 0; i < arr1.length; i++)</p><p> </p><p> arr1[i] = input.nextDouble();</p><p> </p><p> for (int j =0; j < arr2.length; 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> </p><p> printArray(arr1);</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></p><p></p><p>[/CODE]</p><p></p><p>This thing is when i print it from the file, it prints the same score for everyone but its different in the file. </p><p></p><p>This is how its in the file</p><p></p><p>Smith</p><p>Jones</p><p>Australia</p><p><span style="color: Red">5.0 4.9 5.1 5.2 5.0 5.1 5.2 4.8</span></p><p><span style="color: Red">4.3 4.7 4.8 4.9 4.6 4.8 4.9 4.5</span></p><p></p><p>i want to print those two lines for every pair of skaters!(there's 10 pairs) but its not working! <img src="/styles/default/xenforo/smilies/default/confused.gif" class="smilie" loading="lazy" alt=":confused:" title="Confused :confused:" data-shortname=":confused:" /></p><p></p><p><span style="color: Red"><span style="font-size: 15px">PLEASE HELP!!!!! Text file is attached!</span></span> <img src="/styles/default/xenforo/smilies/default/confused.gif" class="smilie" loading="lazy" alt=":confused:" title="Confused :confused:" data-shortname=":confused:" /> <img src="/styles/default/xenforo/smilies/default/sad.gif" class="smilie" loading="lazy" alt=":(" title="Sad :(" data-shortname=":(" /> <img src="/styles/default/xenforo/smilies/default/sorry.gif" class="smilie" loading="lazy" alt=":sorry:" title="Sorry :sorry:" data-shortname=":sorry:" /></p></blockquote><p></p>
[QUOTE="Tulip_Doll, post: 17864565, member: 525365"] [SIZE="3"][U]Here is the Question: [/U][/SIZE] The international Olympics Committee has asked you to write a program to process the data and determine the medal winners for the pairs figure skating. You will be given the following file: Pairs.txt Which contains the data for each pair of skaters. The data consists of each skater’s name, their country and the score from each of eight judges on the technical aspects and on the performance aspects. A typical record would be as follows: Smith Jones Australia 5.0 4.9 5.1 5.2 5.0 5.1 5.2 4.8 4.3 4.7 4.8 4.9 4.6 4.8 4.9 4.5 The final score for each skater is the sum of the average of the two categories of score. Design a class to hold the above data and the final score. Read the data in from the file and calculate the final score for each pair. Sort the array of objects , and display the results on the screen in order, giving special prominence to the medal winners. [SIZE="4"][U]Here is my Class: [/U][/SIZE] [CODE] public class Skaters { private String name1; private String name2; private String country; private double [] arrTech = new double [8]; private double [] arrArt = new double [8]; private double score; public Skaters (String n1, String n2, String c1, double [] arrT, double [] arrA) { this.name1 = n1; this.name2 = n2; this.country = c1; this.arrTech = arrT; this.arrArt = arrA; } public void setName1(String n1) { name1 = n1; } public void setName2(String n2) { name2 = n2; } public void setCountry(String c1) { country = c1; } public void setArrTech (double [] arrT) { arrTech = arrT; } public void setArrArt(double [] arrA) { arrArt = arrA; } public String getName1() { return name1; } public String getName2() { return name2; } public String getCountry() { return country; } public double getScore() { double sum = 0, avg1, avg2; for (int r = 0; r < arrTech.length; r++) sum += arrTech[r]; avg1 = sum/arrTech.length; sum = 0; for (int s = 0; s < arrArt.length; s++) sum += arrArt[s]; avg2 = sum/arrArt.length; return (avg1 + avg2); } } [/CODE] [U][SIZE="4"]This is my main: [/SIZE][/U] [CODE]import java.io.*; import java.util.Scanner; public class testSkaters { 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 = new double [8]; double [] arr2 = new double [8]; while (input.hasNext()) { name1 = input.nextLine(); name2 = input.nextLine(); country = input.nextLine(); for (int i = 0; i < arr1.length; i++) arr1[i] = input.nextDouble(); for (int j =0; j < arr2.length; 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(arr1); } } public static void printArray (double [] arr3) { for (int r = 0; r < arr3.length;r++) System.out.print(arr3[r]); System.out.println(""); } } [/CODE] This thing is when i print it from the file, it prints the same score for everyone but its different in the file. This is how its in the file Smith Jones Australia [COLOR="Red"]5.0 4.9 5.1 5.2 5.0 5.1 5.2 4.8 4.3 4.7 4.8 4.9 4.6 4.8 4.9 4.5[/COLOR] i want to print those two lines for every pair of skaters!(there's 10 pairs) but its not working! :confused: [COLOR="Red"][SIZE="4"]PLEASE HELP!!!!! Text file is attached![/SIZE][/COLOR] :confused: :( :sorry: [/QUOTE]
Insert quotes…
Verification
Hata thunen beduwama keeyada? (60 bedeema thuna)
Post reply
Top
Bottom