How To Make XML - Game To Hold High Scores Of Three Different Levels

May 22, 2015

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?

View Replies


ADVERTISEMENT

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

[Code]...

View Replies View Related

Find High And Low Scores From File

Aug 28, 2014

I am trying to figure out how to report the high and low scores with names from a file. The format is like:

6352 J@me$$
663843 BOBBBB1
etc...

This is my code so far.

import java.io.*;
import java.util.*;
public class Assignment1
{
public static void main(String[] args)throws IOException

[code]....

View Replies View Related

High Scores On Table - Shifting Elements In Array To The Right

Dec 7, 2014

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

[Code] .....

View Replies View Related

Creates A Single Linked List That Stores Names And High Scores And Prints Them

Sep 29, 2014

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;

[Code]...

View Replies View Related

HiLo Game In Java - User Can Choose Up To 3 Different Levels With 3 Methods

Apr 25, 2014

I will try to explain what i want to code , a HiLo game where the user can choose up to 3 different levels(1-10, 1-100, 1-1000) with these 3 methods

public static void main(String[] args) {...}
public static int playGame(int maxNumber) {...}
public static void giveResponse(int answer, int guess) {...}

with no Random , i will use the:

int number = (int)(Math.random() * max) +1; to generate numbers

I have tried so many times , but i don't get it ....

My code so far :

import java.util.Scanner;
public class HL{
public static void main(String[] args ){
Scanner s = new Scanner(System.in);

[Code] ....

View Replies View Related

How To Create Different Levels

Apr 6, 2014

I am trying to write a code for a game HiLo, where i want to add 3 different levels:

easy (1-10)
medium (1-100)
hard(1-1000)

Where the user can choose before the game starts. After that the game is finished i want even to write how many guesses the player used on the screen.

View Replies View Related

How To Make 2D Sandbox Game

Nov 8, 2014

I am pretty basic when it comes to java programming. i think the last thing i learned was if, repeat, random and boolean statements. the thing i want to do as a big project in java is make a 2D sandbox game with a title page and everything.

View Replies View Related

Make A Connect 4 Game With Java

Nov 17, 2014

I have to make the connect 4 game be connect 3. Ive edited a code but I the math is over my head. These loop methods check the ways someone can win.

for (int j=0;j<7;j+=2)//need to change
{
if ((f[i][j+1] != " ")
&& (f[i][j+3] != " ")
&& (f[i][j+5] != " ")
&& (f[i][j+7] != " ")
&& ((f[i][j+1] == f[i][j+3])
&& (f[i][j+3] == f[i][j+5])
&& (f[i][j+5] == f[i][j+7])))
//end of loop

[code]....

View Replies View Related

How To Make Grid For Battlefield Game

May 27, 2015

I wanted to know which RAD TOOL should I use to make the grid. I used the label but it's not interesting like the game *. I m starting to make the game and can't think how to make the grid.

Thought of using the buttons but can't add image to it.

what should I use to make the grid.

* what I did earlier Is place 9 label in grid form (just to test) and nine buttons one for each. When u click a button, image is shown in respective label... But it doesn't feel like u r playing game..

View Replies View Related

JRE :: Changing Default Security Levels

Dec 21, 2014

I have several Windows 7 Enterprise machines that have already been deployed via image and need to lower the security settings for use on internal web based applications.
 
Is there an easy way to manipulate the configuration (a file) so that I may simply make the changes by overwriting the current configuration settings instead of, having to go to each device, opening the Java console, and changing the security settings that way?
 
I have attempted to login as the machine administration, make the changes on the Java console with the hopes this configuration would have migrated to all user profiles that log into the PC. Is there a "public profile" configuration file I can change and if so, what should I do.

View Replies View Related

Simon Java Game / How To Make GUI Work

Dec 6, 2014

I am trying to make a java Simon game but I cannot figure out how to make the GUI work. I have this so far, but now it just keeps saying I lose and it isn't functioning. It seems the only way I can make it work is having the action listeners in the do loop, but then once a button is clicked, the code errors out.

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

[code]....

View Replies View Related

How To Make A Game Using Images (like Logo Quiz)

Jan 11, 2015

i am making a game in java eclipse which has a 3 category for kiddie, teenage and young adult, that also has subcategory which Q&A and images, my problem was i cant make an images quiz (like a logo quiz) that is randomize what i only made was to display an only one image if i clicked button and its only one image, how can i make showing one image then another one image if i clicked some button like NEXT...

This are the codes i used!

package com.example.exampleimage;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.onclickListener;

[Code] .....

View Replies View Related

Writing A Program To Make A Tic Tac Toe Game Utilizing Inheritance

May 7, 2014

I am new to programming and we are writing a program to make a tic tac toe game utilizing inheritance, client-supplier, arrays, and EventButton. I am still trying to wrap my head around events and inheritance. We are instructed to write 4 classes (a TicTacToeModel, a TicTacToeView, a TicTacToe Controller, and a TicTacToeButton). I got the TicTacToeModel down, but am having trouble with the other classes.

Instructions for View: Write a class that implements the UML class diagram below. The only purpose of this class is to draw a picture of the specified TicTacToeModel. For purposes of this assignment, we understand a ‘theme’ to include such things as the background color of the tic‐tac‐toe board, the shape and color of the X indicator and the shape and color of the O indicator. While you are free to select your own personalized ‘theme’ your TicTacToeComponent must always be proportionally ‘correct’ regardless of the client‐determined width and height of the Component.

Instructions for the Controller: Write a controller that controls the game. There is one human player (the X player) and the computer player (the O player). The name of the class must be TicTacToeController. In a sense, the controller is the game since the controller will

1) create a TicTacToeModel
2) create a TicTacToeView and
3) create a TicTacToeButton (you must write this class following the design pattern covered in class lectures), a label, and text field such that when the button is pushed, the player moves into the cell selected by the text field. After every player move, the computer moves into a randomly selected empty cell. When the game is over, a text message must be displayed somewhere on the screen the gives the status of the game. While you are free to change the appearance of the controller, the basic elements must be provided

These are our instructions for the TicTacToeButton: create a TicTacToeButton (you must write this class following the design pattern covered in class lectures), a label, and text field such that when the button is pushed, the player moves into the cell selected by the text field. After every player move, the computer moves into a randomly selected empty cell. When the game is over, a text message must be displayed somewhere on the screen the gives the status of the game.And this is the code I have thus far for the button:

import java.awt.event.*;
import java.awt.*;
public class TicTacToeButton extends EventButton{
public TicTacToeButton(int x, int y, int w, int h) {
super("Move");
setBounds(x, y, w, h);

[code]....

View Replies View Related

Make A Simple Platformer Game In Java - Moving Characters

May 24, 2015

I am trying to make a simple platformer game in Java. When I try to move the character I made it only moves over then immediately back

import java.awt.event.KeyEvent;
public class UCC
{
private int xLoc;
private int yLoc;
private int xSpeed;
private int ySpeed;
private double gravity;
private int size;
 
[code]....

View Replies View Related

Connect Four Game With Java Swing / Make Multi D Panel Maker When Try To Run It

May 31, 2014

I am trying to make a Connect Four game with java swing, but I am getting an error with my attempt at making an multi D panel maker when I try to run it.

import javax.swing.*;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
 
[code]...

View Replies View Related

Fields Won't Hold Value Given Through Input?

Oct 18, 2014

At the end of my main method, I want it to print out the input given that should have been stored in my sandwich class fields, but it didn't.

import java.util.*;
import java.lang.*;
public class SandwichBuilder {
public static void main(String[] args) {
Scanner inputDevice = new Scanner(System.in);

[Code] .....

View Replies View Related

Tic Tac Toe With GUI Using JButtons That Will Hold X And O Pictures

Jan 8, 2015

I am in the process of creating a Tic Tac Toe game with a GUI using JButtons that will hold the X and O pictures. I have the picture appearing when i click it once but it jumbles up all the other buttons which is why i have to run the method resetAllButton() to set everything back. Once i click the x again it puts everything back how it is supposed to be and works normal. How can i get this to work in one click.

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TicTacToeGui extends JFrame implements ActionListener {

[Code] .....

View Replies View Related

How To Hold And Print Distinct Numbers

Sep 29, 2014

I am able to get the integer in the array printed but I am lost on how to hold and print the distinct numbers.

This program will read in 10 numbers from the user via the console. It will display on the console only the distinct numbers, i.e. if a number appears multiple times in the input it is displayed only once.

Here is a sample test run:
Enter an integer: 2
Enter an integer: 6
Enter an integer: 1
Enter an integer: 8
Enter an integer: 6
Enter an integer: 1
Enter an integer: 2
Enter an integer: 4
Enter an integer: 7
Enter an integer: 5
The number of distinct values is 7
2 6 1 8 4 7 5

View Replies View Related

How To Declare ArrayList That Can Hold Int Variables

Mar 26, 2012

Any way of How to declare an ArrayList that can hold int variables?

View Replies View Related

High Numbers In Java?

Sep 3, 2014

i want to make an application that use vers high numbers, but can int, double, float, or long do that for me?

View Replies View Related

High / Low / Average Temperature

Nov 19, 2014

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)

View Replies View Related

Will Not Average For High Temperature

Apr 21, 2014

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;
 
private JTextField high1Field, low1Field, high2Field, low2Field;
private JTextField high3Field, low3Field, high4Field, low4Field;
private JTextField high5Field, low5Field, high6Field, low6Field;
private JTextField high7Field, low7Field, ave_highField, ave_lowField;
 
[code]....

View Replies View Related

Write TreeMap That Can Hold Maximum Of 20 Colors And Minimum Of 8?

Dec 11, 2014

I am trying to write a TreeMap that can hold a max of 20 colors and a minimum of 8. I have a while loop using pollLastEntry to limit the max but I can't figure out how to set the minimum. The hex number is the map's key and the color name is the value. I tried to use entrySet() and iterator to just double the size of the map but map can't have multiple keys with the same value. It also seems that to set a minimum would require some kind of further input(which I'm trying to avoid) of colors and their hex numbers.

//Method to hard code the colors into the map
public TreeMap<String, String> cm() {
//Color Map <Hex number, Color name>
//Uses a TreeMap to keep all the colors organized by key
TreeMap<String, String> cMap = new TreeMap<String, String>();
cMap.put("FFFF00", " Yellow");

[code]....

View Replies View Related

How To Create A Box To Hold Text Below Google Maps Within Android

Feb 19, 2014

At this point I know how to utilize Google Maps within Android but it always seems to take up the full window, there is an image below which shows what I'm attempting to accomplish (having a box below the Google maps where I can store text i.e. "Hello World"

How do I add box below Google Maps, so to store text i.e. "Hello World"

Code so far:

ActivityMain:

Java Code:

public class MainActivity extends Activity {
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

[Code] .....

Image:

View Replies View Related

Declare And Creates Integer Array That Can Hold 15 Integers

Nov 3, 2014

The main Method

-Create a main method declares and creates an integer array called nums that can hold 15 integers.

-Use a for loop to fill that array with multiples of 3: 0, 3, 6, 9, etc.

-Then use similar for loop to print each value in the array on one line, with each value separated by a single space.

-Compile and run the program to see the result:0 3 6 9 12 15 18 21 24 27 30 33 36 39 42

As you write other methods, you'll also modify the main method to make calls to them. The printArray MethodWrite a method called printArray that accepts an integer array as a parameter. This method does not return a value, and must be declared as static so that the main method can call it. Instead of printing the array in the main method, move that loop into this method. Call the printArray method from the main method. Compile and run the program to verify it prints the sam result as before.Add a println statement so that after printing the array values on one line, it then moves to the following line.Finally, modify the loop in the printArray method so that, instead of using a traditional for loop, it instead uses a for-each loop. Compile and run the program again.

Part III: More Array Methods

The linearSearch Method In lecture we looked at a method that performed a binary search on a sorted array. A much simpler (though much less efficient) search is a linear search, that simply starts at the front of the array and looks at each element in turn until it finds it or reaches the end.Create a method called linearSearch that accepts an integer array and a single int value as parameters. The goal of the method is to find the second parameter (the target) in the array. The method should return a single int representing the index of the target value. This method should not print any output itself. In this method, use a traditional for loop to scan through the elements in the array. As soon as you find the target value, return the index of that value.

If you scan through the entire array without finding the target value, return a -1.Modify the main method to call the linearSearch method and print the results. Call it twice, searching for the value 18 (which it should find) and the value 10 (which it should not). Including the previous activity, the output of the main method should now look similar to this:0 3 6 9 12 15 18 21 24 27 30 33 36 39 42

The index of 18 is 6

The index of 10 is -1

The sumArray Method

The sumArray method should take an integer array as a parameter and return a single integer representing the sum of all values in that array.Use a for-each loop to access each value in the array and compute a running sum. After the loop, return the total.Call the method from the main method, producing the following augmented output:0 3 6 9 12 15 18 21 24 27 30 33 36 39 42

The index of 18 is 6

The index of 10 is -1

The sum of this array is 315

The addValue Method...The addValue method should accept an integer array and a single int as parameters. The purpose of the method is to add the second parameter to EACH value in the array. The addValue method does not return a value, but the elements inside the array will be modified. Call the addValue method from the main method, adding 100 to each element in the array. Then call the printArray method again to see the modified array values:0 3 6 9 12 15 18 21 24 27 30 33 36 39 42

The index of 18 is 6

The index of 10 is -1

The sum of this array is 315 100 103 106 109 112 115 118 121 124 127 130 133 136 139 142

Test a Different Array..Finally, duplicate the content of the main method to perform similar tests on another array. Instead of filling it with multiples of 3, fill it with multiples of 4. And instead of using an array size of 15, use an array size of 20.Modify the values search for to include one that is in the array and one that isn't.Rerun the main method and carefully check the results.If you haven't been doing it all along (which you should), make sure the appropriate class and method documentation is included.When you're satisfied that all methods are working correctly, modify the main method to delete the second array tests.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved