Program To Maintain A List Of High Scores Obtained In A Game
Dec 6, 2014
I am stuck on what to put in my functions for this question: Write a program to maintain a list of the high scores obtained in a game. The program should first ask the user how many scores they want to maintain and then repeatedly accept new scores from the user and should add the score to the list of high scores (in the appropriate position) if it is higher than any of the existing high scores. You must include the following functions:
-initialiseHighScores () which sets all high scores to zero.
-printHighScores() which prints the high scores in the format: "The high scores are 345, 300, 234", for all exisiting high scores in the list (remember that sometimes it won't be full).
-higherThan() which takes the high scores and a new score and returns whether the passed score is higher than any of those in the high score list.
-insertScore() which takes the current high score list and a new score and updates it by inserting the new score at the appropriate position in the list
here are my functions the insertScore is missing because I am having troubles with it.
public static void initialiseHighScores (int[] scores, int size)
{
for (int i = 0; i < size; i++)
{
scores [i] = 0;
}
}
public static boolean higherThan (int[] scores, int size, int newScore)
{
I am a beginning programmer and was learning how to make an XML. It was for a simple game and only needs to hold the highscores of three different levels. Here is what I coded:
try { OutputStream fout= new FileOutputStream("highScores.xml"); OutputStream bout= new BufferedOutputStream(fout); OutputStreamWriter out = new OutputStreamWriter(bout, "8859_1");
[code]....
My issue is that I run this code every time I create the program and the scores are reset to 0. How can I make a small change so that I only run this block of code and create the XML the first time the program is run?
a project I am working on. Its a program that creates a singly linked list that stores names and high scores and prints them. For some reason it is printing an entry extra times. Also my remove function is not working properly
GameEntry class: package project; public class GameEntry implements Comparable<GameEntry> { private String name; private int score; public GameEntry(String n, int s) { name = n;
I'm trying to write a program that asks a user how many high scores they want on a table, then the users types the inital highscores and is repeatedly asked to place more high scores on the table, which if larger than any existing high score, will take its place and shift the other scores down.
Although for the shifting and inserting of that next score the code just doesnt seem to be working, the insertScore function is where im getting the main exception, and im not sure why?
import java.util.Arrays; import java.util.Collections; import java.util.Scanner; public class HighScores { public static void main(String[] args) {
I have a list of uninstanciated class types and I wanted to call a static function from these "Class<? extends PropControl>" (without using reflection) that would create a new corresponding object instance but it appears I cant do that in java so now I want to create a factory that takes a class type as aparameter to create the corresponding object instance but this code dont compile:
Java Code:
public PropControl Create(Class<? extends PropControl> cls) { if(cls==HouseControl.class) <---- ERROR { here I create a new instance of HouseControl (that inherits PropControl) } } mh_sh_highlight_all('java');
I get this error :
incomparable types: Class<CAP#1> and Class<HouseControl>
where CAP#1 is a fresh type-variable:
CAP#1 extends PropControl from capture of ? extends PropControl
Alright, so, for my CS project, we're supposed to list diving scores. However, there are four sections (which I've made in the code) and each section has 9 scores. Of those nice scores, the highest and lowest must be eliminated and then the total needs to be figured out. We're supposed to be using arrays for this...
import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; public class Diving { public static final int MAX_DIVES = 51; public static void main (String[] args) {
[Code] .....
The text file link is uploaded on this post.File is here:
I am creating a program called "Mad Math Machine". This program is to generate random arithmetic questions, with integers ranging from -12 to 12, for the user to answer. The user has three lives. Once they get more than three questions wrong, they run out of lives, and their "score" (the number of questions they answered correctly) is taken.
I have the large chunk of the program (the arithmetic questions and answers) completed. The only part I am stuck on is the scoring system. I believe that arrays would be useful for this task, but I have little idea of where to start. Here is what the scoring list should be able to do:
- It should print out the top ten recent players and their scores. - A separate list should show the top-two highest scores of all time.
*I didn't think it was relevant, but I can include the program code. Up until this point, I have created methods to keep track of the score, but I have simply left them commented out so I could build the rest of the program.*
So for this project I'm going to take in some quiz scores, then eventually get the total number, the range, the mean, and others... Here's the instructions for the two methods I need to create but am completely stuck on:
2. public boolean inputData(Scanner in) 2.1.takes in a Scanner object passed in from main() 2.2. asks the user for a number in the range of 0 through 100. 2.3.It must read a number into an integer variable unless a non-number value is entered, in which case the method will return false. You may use try/catch or an if statement for this. 2.4.If the datum/score seems acceptable, the addGrade method must be called. 2.5.If addGrade returns false, then inputData should throw an IllegalArgumentException or return false Otherwise, inputData should return true. See section 11.4 for exceptions.
3. public boolean addGrade 3.1.takes in an integer grade. If grade is not in the range of 0 through 100 the method should return false. Otherwise, it should appropriately change the values of numberOfQuizzes, highValue, lowValue, 3.2.totalQuizScore , sumOfSquares (used in variance calculation), and add one to the count of the proper variable for A's, B's, C's, D's or F's. The method should then call calculate and return true
Now I have done very little with booleans in class at all, so this is all very confusing for me. I've tried to do a lot of research on my own and so far I came up with the following for the two methods above:
public boolean inputData() { int score = 0; System.out.println("Please enter values, Q to quit:"); Scanner in = new Scanner(System.in); while (in.hasNextInt())
[Code] ....
Honestly I'm not really sure what I'm doing wrong at all, and I have done a lot of research but can't really find anything too similar to what the instructions want so I'm not sure what's right/wrong.
I have a project that is asking me to create a program that will handle a Golfer and his scores. The program will be comprised of three classes: a Golfer class that will manage all the golfer's scores, a Score class and a Tester class to drive the other classes. To accomplish this task the program will use a partially filled array to store the golfer's scores. I have the majority of the code written. It compiles fine, but when I compile and run it only gives the following output.
Tiger ID Number: 1001 Home Course: Pebble Beach Score Date Course Course Rating Course Slope [LScore;@15db9742
I am not sure what I am doing wrong. I have been over and over the code. It is also only printing one golfers information. I have tried creating a for loop for the for the toString in the Golfer class but I am getting the following error Golfer.java:117: error: missing return statement.
I am at a loss here is the code I have for the three sections.
public class Golfer { private String name; private String homeCourse; private int idNum; private Score[] scores; private static int nextIDNum = 1000;
I was trying to write a program that will accept values and transform the scores to grade. Like 70 and above will be given A from 60 to 69 is B, from 50 to 59 is C, from 40 to 49 is D and below 40 is F. I have defined the variables, for the textfield, am confused on how make this hapen on just a click of the comand botton.
Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program:
calculateAverage This method should accept five test scores as arguments and return the average of the scores. determineGrade This method should accept a test score as an argument and return a letter grade for the score, based on the following grading scale
Score Letter Grade 90-100 A 80-89 B 70-79 C 60-69 D Below 60 F
System.out.println("Enter the first score"); test1 = keyboard.nextDouble(); System.out.println("Enter the second score"); test2 = keyboard.nextDouble();
1.Write a JAVA program that will input 10 scores and output the Highest and Lowest score.
2.Write a JAVA program that will input the base and power and display the result: Example: Base is 4 Power is 2 the answer is 16 (Note: Math.pow( ) method is not allowed)
3.Write a JAVA program that will input an integer number, and then will output the sum of all inputted numbers. The program will stop in accepting inputs if the user entered 0.
I am attempting to maintain separate files for different types of "messages" (user messages, field labels/buttons, data values). In this attempt I am trying to get the description of different data values. For example, a UserStatus "A" might be displayed as Active or Activo.
Here are the relevant entries in the values_en_us.properties file:
user.status.A = Active user.status.I = Inactive user.status.P = Pending
I would like to build an Enum for each type of value that I can get the localized value from. In the code below, I have hardcoded the values being passed to the get message to reduce the number of variables when trying to debug this.
org.springframework.context.NoSuchMessageException: No message found under code 'user.status.A' for locale 'en_us'.
On this line of code:
description = appCtx.getMessage("user.status.A", null, new Locale("en_us"));
The application is already showing my custom application error messages I have in the messages localized files, but in that case the ApplicationContext is already available. Because I can get to the contents of the messages_en_us.property files, I'm assuming me config is correct. However, the classes that get the messages content are instantiated by Spring.
The Enums are not created by Spring, so my assumption is that I am doing something wrong in how I am getting a handle on the ApplicationContext or how I am using it.
After looking at the appCtx values in debug mode, I can see that the messageSource > basenames does at least contain my configuration data.
I currently use Eclipse to maintain our Java application. I recently upgraded from Java 6 to Java 7. I updated my Eclipse projects to use the Java 7 .jar files. I can run the application from Eclipse via the Run Configuration.
I can also run the Ant build and it completes successfully. When I install the application on my desktop, I receive the "Java Virtual Machine Launcher: Could not find main class..." error. My CLASSPATH is set to ".".
I am trying to write a code that asks the user to enter a temperature for each day of the week and then it prints out the high temperature, the low temperature, and the average temperature. This is the code I have so far:
import java.util.*; import java.text.DecimalFormat; public class Lab10 { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); int high, low, i, sum; double avg; [Code] ....
There are a few issues that I am having.
1. I can't for the life of me figure out how to make it print the low temperature 2. I had it running perfectly until I changed one thing and now I get a compile error saying that the last 5 statements are unreachable. (lines 32-37)
This program will not give me the average high temperature for the week and I cannot figure out why! Every time it only spits out "0" whereas the average low temperature works great..
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Temps_Grid_Keenan extends JFrame { private static final long serialVersionUID = 1L; private static final int WIDTH = 400; private static final int HEIGHT = 500;
I am trying to code a program that orders 5 random numbers from high to low with the basic coding i know (im starting to learn theory of methods... so you can imagine) When i run the code i cant get all 5 numbers ordered but my logic says the code is right although it's pretty confusing.
I know you could code in a simpler way but first i wanna get it as it is right now. When i debug (on my own way cause i dont know how to actually use it) shows line 72 with yellow color.
public class NuevaCalculadora { import java.util.Scanner; public static void main(String[] args) {
We have a webservices application that uses Java 1.6.0_43, Spring 3.2.3, CXF 2.6.9 and deployed to Jboss 5.0.1 GA in a LINUX x86_64 centos box. It essentially uses apache httpclient (4.2.2) to call internal services and returns the results back to customers. The application has been running fine for a year or so until early this month when all of sudden, it loaded about 300K classes in a very short time during our regression tests and saturated the CPU usage ever since. Hence the application is no longer responding.
I have been trying to troubleshoot the problem for a while. Tried visualvm, dynatrace. thread dumps. heap dumps... None of them is very effective in capturing what are the classes that are loaded so many times and what path triggered that.
I'm in an introduction CSE class and we're working with Java. Basically I need to create a program using scanner, while loops, and pseudorandom numbers. My program is a guessing game and I will post below the code that I already have. Basically I can get the game to work and get it to ask if you want to play another game and it keeps going until you say no. But my issue is getting the statistics of the game down. I need a separate method not in main to produce this at the end of the game once the user decides to stop playing:
Overall results: total games = int total guesses = int guesses/games = double best game = int
here's my code:
import java.util.*; public class Guess { public static void main(String[] args) { intro(100); Scanner console = new Scanner(System.in); game(console, 100); int numGuesses = 0; int numGames = 1; int end = 0;