ElaKiri Programmer's Club

markhaloce

Member
Mar 7, 2013
10,298
677
0
17
The Real North
ko dan meke hitapu set eka :dull:

මැරුණ
මලාට පස්සෙ නැගිට්ට
නැගිටල කන්න මිනිස්සුන්ව හොයාගෙන ආව
එද්දි හම්බවෙන්නෙත් මොක්කුද ඉතිං ප්‍රෝග්‍රෑමර්ස්ලනෙ
උන් C++ වල අර ++ කෑලි වලිං ගැහුව මොලේ කඩාගෙන යන්න
නැගිට්ට මැරිච්ච උන් ඔක්කොම දෙවනි පාරටත් මැරුණ
ඉවරයි :baffled:
 

Tulip_Doll

Member
Feb 6, 2015
208
13
0
Florida
Help!!!!!!!!

Here is the Question:

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.

Here is my Class:


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);
	}
	
	
	
	
}

This is my main:

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("");

			
}

}

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
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


i want to print those two lines for every pair of skaters!(there's 10 pairs) but its not working! :confused:

PLEASE HELP!!!!! :confused: :( :sorry:
 
  • Like
Reactions: thomian

Tulip_Doll

Member
Feb 6, 2015
208
13
0
Florida
Here is the Question:

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.

Here is my Class:


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);
	}
	
	
	
	
}

This is my main:

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("");

			
}

}

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
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


i want to print those two lines for every pair of skaters!(there's 10 pairs) but its not working! :confused:

PLEASE HELP!!!!! :confused: :( :sorry:


HELP BUMP!! :(
 

Voltage

Well-known member
  • Feb 6, 2012
    21,723
    1
    15,120
    113
    Link two comboBoxes

    වැඩ්ඩනි පොඩි help එකක් ඕනි

    JAVA

    ComboBox 2ක් link කරගන්න ඕනෙ. එකක තියෙන්නේ itemCategory ටික. අනිකේ තියෙන්නේ ඒ ඒ category එකට තියෙන item ටික.

    2076byb.png


    Item Category ටික තියෙන්නේ වෙනම table එකක. Item ටික තියෙන්නේ වෙනම table එකක.

    2wgzwq1.png


    මං form එක Load වෙද්දී itemCategory ටික මුල් combo එකට එන්න code එක ලියාගත්තා.

    Code:
     void loadcomboCatInv(){
            try {
                ResultSet rs = db.getData("SELECT cat_name FROM itemcategory");
                    Vector v = new Vector();
                    while(rs.next()){
                        v.add(rs.getString("cat_name"));
                        comboCatInv.setModel(new DefaultComboBoxModel(v));
                    }

    දැන් ඕනෙ මුල් combo එකෙන් category එක තේරුවාම ඒ categoryID එක තියෙන item ටික යට combo එකෙන් එන්න ඕනෙ. මට අවුල තියෙන්නේ මුල් combo එකෙන් මං තෝරන්නේ item category එක text එකක් විදියට. එතකොට පලවෙනි combo එකෙ උඩ click උනාම මට ඕනෙ ඒ select කරපු category text එකට අදාල categoryID එක තියෙන item ටික දෙවෙනි combo එකෙන් ගන්න. ටිකක් අවුල් වගේ අප්පා. පොඩි help එකක් දෙනවද :sorry:
     
    Last edited: