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?
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 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) {
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;
Write a program in JAVA in response to the following prompt:
Design a GUI program to find the weighted average of four test scores. The four test scores and their respective weights are given in the following format:
testscore1 weight1 ...
For example, the sample data is as follows:
75 0.20 95 0.35 85 0.15 65 0.30
The user is supposed to enter the data and press a Calculate button. The program must display the weighted average.
Here is what I have written:
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class weightedaverage2 extends JFrame { private JLabel Score1L,Score2L,Score3L,Score4L;
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 getting this -file not found- error despite the fact that I have saved the file with appropriate permissions in the src folder of the given application in netbeans. The program prompts for a listings.txt file to read and write data to a new file that counts and sums the info in a overview.txt report. Here is the stacktrace:
run:
Type in the name of the file: listings There was a problem:java.io.FileNotFoundException: listings.txt (The system cannot find the file specified) java.io.FileNotFoundException: listings.txt (The system cannot find the file specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:131) at java.io.FileInputStream.<init>(FileInputStream.java:87) at java.io.FileReader.<init>(FileReader.java:58) at kettask2a.KetTask2a.main(KetTask2a.java:48)
I'm trying to find a specific file that already exists on the computer. I want to find that file and zip it. don't get sidetracked with whether or not the file exists, because I'm sure it does on my local machine and TDD will address that what-if scenario later.
My code and JUnit is below. Since its not finding the file, I assume I must be formatting 'path' wrong. I wonder if I'm even on the right track logically.
private ZipParameters zp = new ZipParameters(); private ZipFile zipFile; public ZipFile createZipFile(File f, String path) throws ZipException{ zipFile = new ZipFile(path); zp.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL); zp.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
I'm trying to read a .xlsx file using Apache Poi on Eclipse and store the data into an ArrayList.
My code :
import org.apache.poi.ss.usermodel.*; import java.io.*; import java.util.*; public class parseReadFiles { public static void main(String[] args) {
[Code] ....
I keep getting a FileNotFoundException: Users/Divjot/Desktop/first.xlsx (No such file or directory). I've tried different combinations of file names and paths but can't get the program to find it. Should the file be stored in a special place or should the class path be different?
First of all, i am using ubuntu and jdk8. My problem: displaying the current path of a file in my system Approach: I have a file called dummy.txt in a given directory which have enough permissions and i did the following:
I expected to see displayed the current path of the file without the name of the file but it is showing a different path. I just want to display the current path of the file without the name.
I am working through a text and I am supposed to complete the following tasks.
Your ReadFiles.java class requires the following methods:
Method: check to see if the file exists
Method: find number of rows in csv file
Method: Converts the csv file to a mutli-dimensional array
Method: PrintArray
Method: Return array using a get method
Create a file DataAnalyzer.java. This file will be used to call the methods in ReadFiles.java. Be sure to demonstrate that all of your methods work through DataAnalyzer.java.
The problem is that it does not really provide any information on how to go about reading a file into an array. I am stuck at the third task of converting the file to an array and I have tried several ways to do this unsuccessfully. I thought that I would at least try to get things to print out (line 87) to see if I could get that to work, but all that prints in null over and over again.
Java Code:
public class DataAnalyzer { public static void main (String[] args) { ReadFiles aReadFiles = new ReadFiles(); aReadFiles.fileCheck(); aReadFiles.findRows(); aReadFiles.convertFile();
I have to recursively find a given string in a file. I HAVE to use the LineNumberReader class, and the output would be like so:
Line#Found : the string of the whole line
This is the code I've written:
public String findGivenString(String givenString, int currentLineNumber) { LineNumberReader lnr = null; try { lnr = new LineNumberReader(new FileReader(getFile()), 4096); lnr.setLineNumber(currentLineNumber); String s = lnr.readLine().toLowerCase();
[Code] ....
I messed around with a bit, and it doesn't change to the new set line. Though the line number is incrementing! So it just keeps checking the first line of the file over and over again, which is why it can't find the given string. Which also throws the StackOverFlow exception I'm getting.
Here's the output if I remove the comment from the System.out...:
String @ that Line# 1: package banking; String @ that Line# 2: package banking; String @ that Line# 3: package banking; String @ that Line# 4: package banking; ....
So you see it keeps checking the same line even though the line number IS incrementing.
class mmm { public static void main(String[] args) { OcrEngine ocr = new OcrEngine(); ocr.setImage(ImageStream.fromFile("pp.tif")); // ocr.setImage((IImageStream) new File("pp.tif"));
[Code] ....
In above code giving error .
Exception in thread "main" com.aspose.ms.System.IO.FileNotFoundException: Can't find file: pp.tiff.
Where i am wrong. I am trying to pass all formt(.png,.gif,.jpg) images. I am giving proper path ....
i want to find an embedded file extension i.e suppose if word file is there in that excel is also included then is should detect both file types word n excel and is is it possible to find an embedded file type.
I need to find the largest value in a scanned file.I've gotten the count, sum, average, evens, and odds myself.The code above the while loop is not mine and my professor said I may no edit it or other wise mess with it. I also may not use arrays.Also I've realized that the largest/smallest are recording the value of count. I've tried the following:
Scanner infile = new Scanner ( new FileReader(args[0]) ); int count=0,sum=0, largest=Integer.MIN_VALUE,smallest=Integer.MAX_VALUE, evens=0, odds=0; double average=0.0;
I have included split() to put a string read from a given file into indexed array. Looking for a word position (not char position number in addition to the line number I have already written. Line number works fine, however word position isn't quite right.Below is my code:
import java.io.*; public class Word implements Comparable, TreeComparable{ String word; int count; int wordpos; ObjectList lines; private SuperOutput so;