Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Im having issues in creating the main class in java import java.util.Arrays; import java.util.ArrayList; import java.util.Collections; class Country { //declare variables private String name; private

Im having issues in creating the main class in java image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

import java.util.Arrays; import java.util.ArrayList; import java.util.Collections;

class Country { //declare variables private String name; private String player; private int age; private double [] dArray; //other constructor public Country (String name, String player, int age, double [] dArray) { this.name = name; this.player = player; this.age = age; this.dArray = dArray; } public Country (String name, String player, int age) { this.name = name; this.player = player; this.age = age; this.dArray = new double[] {}; } //accessor method public String getName () { return name; } public String getPlayer () { return player; } public int getAge () { return age; } public double [] getDArray () { return dArray; } //mutator method public void setInfo (String name, String player, int age, double [] dArray) { this.name = name; this.player = player; this.age = age; this.dArray = dArray; } //display info public void displayInfo () { System.out.printf ("%s%t%s%t", name, player, age); for (double d : dArray) { System.out.printf ("%-5d", d); } } }

class Diving { public static final int SIZE = 7; //declare private variables private Country name; private double [] score; private double difficulty; private double cf; private double fs; //other constructor public Diving (Country name, double [] score, double difficulty, double cf) { this.name = name; this.score = score; this.difficulty = difficulty; this.cf = cf; getTotalScore (); } //accessor methods public Country getCountry() { return name; } public double getDifficulty () { return difficulty; } public double getCarriedForward () { return cf; } public double getFinalScore () { return fs; } //mutator method public void setDifficulty (double difficulty) { this.difficulty = difficulty; } //private methods private ArrayList getSortedList () { //create dummy array double [] dummyList = new double [Diving.SIZE]; dummyList = score; Arrays.sort (dummyList); ArrayList scorelist = new ArrayList (); for( int i = 0; i Each judge rates the dive from 0 ("completely failed") to 10 ("excellent"). This is based on how well the diver performs, from his starting position to entry into the water. The judges do not take difficulty into account for this score. - Example: a diver receives execution scores of 6.5, 7.0, 7.0, 7.5, 7.5, 8.0, and 8.0. Note that the score is either .0 or .5( is from 0 to 10), maximum is 10.0 Cross out the outliers: So cross out two scores on each end: 6.5,7.9,7.0,7.5,7.5, 8.9, and 8.0, i.e., remove the two top and two bottom scores Add the rest together. Find the sum of the remaining scores. -Example: 7.0+7.5+7.5=22.0 Multiply by the degree of difficulty (DD). Each attempted dive has a degree of difficulty calculated in advance. This is based on many factors, such as the number of twists and somersaults and the take-off and entry positions. Multiply your last sum by the degree of difficulty to get the final score for this dive. - Example: Let's say the diver attempted an inward 21/2 somersault dive in the 10 meters competition, in the pike position. This has a difficulty score of 2.8. Multiply this by the execution score to get the final score: 22.0x 2.8=61.6. Note that the degree of difficulty has only one decimal point, i.e., *.\# (* is 1,2,3,4, very seldom 5 , \# is 0 to 9 ). In a competition, divers need to dive a few rounds, normally 5 rounds. The degrees of difficulty, for each round, are usually pre-determined before the beginning of the competition. Let us look at a simple UML diagram for this assignment: Two important classes: Country class, Diving class; and a main class that we will define it later. Convenient to your design, additional class(es) is / are allowed. Let us now look at the detail of each class. Basically each class has private instance variables, constructors, accessor methods, mutator methods and some other methods 2 related to the class(es). Methods are either public or private; instance variables must be private. Let us start with the Country class: It consists of four private instance variables: name (of a country), player (name of a player), age (of the player) and dArray (an array of difficulty). A constructor to initialize the instance variables, some accessor methods, a mutator method and a display info method. Additional methods are allowed. Additional instance variables or any change to instance variables are not allowed. Usually a player participates in a diving competition, he / she needs to declare the level of diving difficulties before the competition. The competition usually consists of 5 rounds. This array stores 5 real number representing the degree of difficulties of each round. The display Info method displays the info of a participant, for example, Thailand Name 2 152.12.52.64.44.5 Note that this array (dArray) is "pre" sorted before comstructing a Count ry object. Next, let us look at the Diving class which is the most important class of this assignment: This class has a constant SIZE indicating the number of judges, usually is 7 . It consists of 5 instance variables: name (a Country object), score (an array, scores given by judges), difficulty (level of difficuly of each dive), cf (carried forward derived from the previous round, obviously round 1 has no carried forward score, i.e. 0 and is (the final score of the current round). Most of the methods are obvious in definition. The getSortedList stores the stores the scores in a list (a dummy list) and sort it; you can use it to retrieve the highest, second highest etc. scores. This method is optional, you can find your own way to solve the problem. The display info method displays the result of a participant according to the following format: (you will see order of printing during the runtime interactions and displays): Thailand 0.5 8.3.50.59.0.58. 2.1 8.00 25.20 25.20 Now our main class to drive the whole application. Let us look at the UML diagram: We define a constant to store the number of rounds for a competition. I may ask you to change the value of this constant during demo; just make sure that you produce a general design. We define a string array of countries (Countries) to be used in the design. A country can send more than one participant. We usually use, for example, China 1, China 2 if China sends two participants. A few important tasks to be done in the main class. Let us look at the runtime interactions and display before we look the methods used in the main class: Upon execution, the system firstly displays the information of each participant: Now, the display of round 1 : Followed by the ranking of round 1 : Some notes to round 1 (and hence for each round), the level of difficulties is extracted from the array of difficulties (i.e., dArray) and the result of each round is sorted. I will show you my way of sorting even we did not cover any sorting topics in lessons 3 . Also note that the carried forward score for each participant is 0.00 as we are in round 1 ; and round 2 onward will copy the total scores obtained from the previous round to the carried forward score; and we will use an array to store the carried forward scores for all the participants. Now look at the interactions and display of round 2 : The ranking for round 2 : Note that the starting positions for each round remain unchanged except participants have different degree of difficulties. If you look at the degree of difficulties in round 2 for each of the participant, actually they are listed under the column D 2 (see page 5). Let you see one round, round 3 : The result after round 3 : Your system must continue the number rounds according to a constant specified in the main class, i.e., NO_ROUNDS. Now let me tell you how I designed this system. Note that you can have your own idea in doing this assignment provided you use the two specified classes to achieve the same target. Let us look at the methods in the following UML diagram: - getscore method receives an array score as parameter and update the scores for all the judges - getCountry method receives two parameters, a list of Diving objects and a value of the final result; determines and returns the name of the country that has the given result. Of course, a few countries may have the same result, you just return any one of them. You can do some more refinements for uniqueness, to me, is optional, you will not be penalized with this minor logical error. - displaysortedList receives a list of diving objects and display the sorted results. - getdifficuly generates and returns a real number in between 2.0 to 5.0 with only one decimal digit. - getDarray constructs and returns an array of degree of difficulties for a participant. - getAge method generates and returns an age of a participant, reasonable age younger than me - displayCountry Info displays a Country object. displayGameInfo displays the game info, i.e., the starting position for each round. displayResultinfo method displays the results for each round I defined a carry forward array (cfArray of double type) to store the carry forward scores for each participant. UpdateCFArray method is to do this task

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Rules In Database Systems Third International Workshop Rids 97 Sk Vde Sweden June 26 28 1997 Proceedings Lncs 1312

Authors: Andreas Geppert ,Mikael Berndtsson

1997th Edition

3540635165, 978-3540635161

More Books

Students also viewed these Databases questions