Finding solution in TopCoder Arena [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
I try solve some problem in the arena, but now I can not find it there. I just have a text of solution:
DEFINITION
Class Name: MatchMaker
Method Name: getBestMatches
Paramaters: String[], String, int
Returns: String[]
Method signature (be sure your method is public):
String[] getBestMatches(String[] members, String currentUser, int sf);
PROBLEM STATEMENT
A new online match making company needs some software to help find the “perfect
couples”. People who sign up answer a series of multiple-choice questions.
Then, when a member makes a “Get Best Mates” request, the software returns a
list of users whose gender matches the requested gender and whose answers to
the questions were equal to or greater than a similarity factor when compared
to the user’s answers.
Implement a class MatchMaker, which contains a method getBestMatches. The
method takes as parameters a String[] members, String currentUser, and an
int sf. Here members contains information about all the members. Elements of members are of the form
NAME G D X X X X X X X X X X
NAME represents the member’s name
G represents the gender of the current user.
D represents the requested gender of the potential mate.
Each X indicates the member’s answer to one of the multiple-choice
questions. The first X is the answer to the first question, the second is the
answer to the second question, et cetera.
currentUser is the name of the user who made the “Get Best Mates” request.
sf is an integer representing the similarity factor.
Can you help me, and tell how to find a solution in the TopCoder arena?

use the problem archive to find out which SRM or tournament the class was used in.
http://community.topcoder.com/tc?module=ProblemArchive
this will show you the top submissions from each of the acceptable programming languages. You can also use the summary button if you know which SRM the class is from but this does not guarantee that the solution you view is correct if the problem was an old one.

Related

Invoking method [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
Hello fellow developers.
I am suppose to write a code that stores patient details and calculates some details like ratio. HDL(High Density Lipoprotein) and LDL are cholesterol figures. Please correct where ever you can.
I have a default constructor that assigns default values. And an overload constructor that has three parameters.
public PatientCheckUp()
{
PatientNumber = "L123";
HDL = 60.00;
LDL = 300;
}
public PatientCheckUp(String PatientNumber, double HDL,double LDL)
{
this.PatientNumber = PatientNumber;
this.HDL = HDL;
this.LDL = LDL;
}
`
I already included the get and set methods, I understand those.
What i don't know how to do is
Create a method called getCholesterolStatus() that will invoke a method i created to compute cholesterol ratio ( computeRatio() )
This method must compare the patient's cholesterol ratio to that of the optimum cholesterol ratio and return a messaged based on the comparison. If the ratio is less than the ideal cholesterol the a "optimal cholesterol ratio" message should be returned(3.33)
The computeRatio() method
public double computeRatio()
{
ratio = LDL / HDL;
return ratio;
}
I realize i have asked for a lot. I need to understand how to do this for my upcoming examination.
Thank you in advance.
You call a method by typing its name and () at the end of it, possibly passing parameters and an instance variable's name before it with a dot or class name ahead of it with a dot if necessary. If you call a method correctly, then you can use it simply as a value, compare it to a final variable and you can also use the ternary operator to make this a one-liner.
public String getCholesterolStatus() {
return (IDEAL_CHOLESTEROL <= computeRatio()) ? "Optimal cholesterol ratio" : "Bad cholesterol ratio";
}

What data type should i use? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
hi i have a java programming assignment wich include 3 exercice i have done 2 already but in the third one i am dont know wich data type i should use
here is the question :
Write a java program that reads from the user the course code, section and the scores of a student for three exams representing two midterms and a final. The percentage of each of the three exams is of fixed value 30, 30 and 40 percent respectively. Your program computes the final average grade and displays it along with the course code and the section.
Remark: All data, except for the average, must be whole numbers and you should use the most efficient data type that is suitable for this specific exercise.
Sample Run:
Enter your course code: CSCI250
Enter your section: E
Enter the scores of the tests and the final: 97 83 77
CSCI250 E 84.8 (result)
so what i want to know is what is the preferable data type to use for course code ? and char is the one that i should use for section right ?
If you're capturing user input, use a String for everything.
Reason? You may request a number, but the user can type anything. Your code needs to handle bad input.
I think you can use String as data type for Course Code. You can write both numbers and letters by using it. And for section, yes, char will be suitable for it.
Use a String for arbitrary text.
If the section code is always present1 and is never more than character than a char can be used.
However, I would still use a String for consistency, flexibility, and easy of use. The teacher may prefer this based on the "efficient"cy they are going for.
1The is a soft "always": while char cannot represent null a sentinel (eg. '\0' or ' ') can be used to indicate 'no section specified'. Using such a sentinel to supplement null can also (but does not always) lead to more logic work - in particular when the record is displayed.
In any case, it is probably best to not switch to Character just for the null as this is most likely outside of the scope of current course work.

Changing a variable name [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
So I'm making a simple game in java. In this game I want there to be an infinite number of players.
The game is Dictionary, but not the one where you race to find a word in a dictionary.
How to play:
A person chooses a word that no one would know.
Everyone enters a made up definition that is believable.
Each person guesses which one is the real definition.
You get a point for guessing correctly and for the number of people who guess your word
(Steps 2 and 3 are ignored by the person who chooses a word)
My program (So far):
Choose start or quit
When start is pressed the number of players selected (Not including word selector).
Word selector chooses word in JPasswordField
Enters definition in JPasswordField
The word is told to Player 1 and then they must enter a definition into a JPasswordField
Repeats step 5 until the times repeated are equal to the number of players.
The problem I'm having:
Player + numberrepeated = passwordfield.getText;
doesnt exist.
I need to have the variable change each time.
You can't have dynamic variable names in Java. What you can do is use a Map, to associate a key (the player's name, for example), with a value (the player's password, for example):
Map<String, String> passwordsByPlayer = new HashMap<>();
...
passwordsByPlayer.put(playerName, passwordField.getText());

java arrayoutofbounds exception error when program together [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I am doing an assignment and I have to do several simple string manipulations. I think I have the last one figured out, and it works by itself, but it does not work when I put it together with the other string manipulations, giving me an arrayoutofbounds exception error. Any advice?
Here is the small code I made
public static void main (Strings[] args) {
Scanner sc = new Scanner(System.in);
String theSentence = sc.nextLine();
String [] theWords = theSentence.split(" ");
Arrays.sort(theWords);
System.out.println(theWords[1]);
System.out.println(Arrays.toString(theWords));
}
This does not work when it is put together with the rest of the code even though it works by itself. For reference, this code is supposed to take in a small sentence and give me the smallest word lexicographically. Ex: input: "4 WHAT WAIT IS THIS" output would be "IS"
The code is assuming that theWords will always have at least two elements in it. If the sentence provided by the user does not have any spaces, theWords will never get an element in position 1 and so the program will crash on System.out.println(theWords[1]);
In Java arrays are indexed from zero, where the 0th element is the first.
As Mark said you are assuming that there are always two words entered in this case. You should check the length of theWords before trying to access an element.

How do I use letter as a variable/placeholder in a math equation? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
Sorry if that title confused you its kinda hard for me to ask this without explaining it.
I am writing a (fairly) simple program to find the roots of a quartic (biquadratic) function.
My main question (I should know this >.>) is how do i get x in the quartic function (ax^4 * bx^3 * cx^2 * dx * e = 0) to stay as x and not be given a value. just sorta a place holder. this is part of it: ( b1 * x * c1 / 2 ); so i dont want x to be replaced. i just want it to stay as x and everything else around it multiply as you normaly would when solving the problem by hand.
My second question is from this site:
http://easycalculation.com/algebra/learn-quartic-equation.php
We haven't covered Quartics in school yet but We have covered cubics and quadratics so I know enough that i can follow a long for the most part except for right after it talks about the discriminant.
y2=(- term1 + r13*cos(q3+(2∏)/3) )
y3=(- term1 + r13*cos(q3+(4∏)/3) )
i dont get the parts with 2∏ and 4∏. If you know a simple way to explain it, please do :D if not i can always look it up and try to figure it out from there.
And my last question. I know how with the discriminant of quadratics depending on what it is depends on one root, no roots, or two roots. How does that apply with quartics and what should i do to check for that in my code (if you think i cant figure it out lol).
ummm i believe thats it. i can add info if needed. I dont think my code would be needed but i would prefer not to post it either way.
Thanks for the help.
-Ryan
The approach cited relies on a trigonometric identity described here used to solve cubic equations. The symbol ∏ is a capital π, or Math.PI in Java.
See also this example that uses org.jscience.mathematics.function.Polynomial and references a convenient root-finding algorithm.
The approach that you are looking for is called Symbolic Programming.
I do not, however, know of any stable Java libraries which allow for such programming.

Categories

Resources