Variable Outputting 0 Instead Of Value

Oct 24, 2014

I have code that displays 3 game scores the series total and average. For some reason game 3 outputs 0 and game 1 and 2 output correctly. I don't see anything different that game 3 is doing that game 1 and game 2 aren't so I'm not sure what the problem is.

java file

package com.valenciaprogrammers.mybowlingscores;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
public class BowlingScores implements Comparable<BowlingScores>{
private long id;

[Code] .....

View Replies


ADVERTISEMENT

If Else / Switch Not Outputting Correctly

Jan 27, 2014

Trying to learn switch statements. Can't figure out what I am doing wrong.

java Code:

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

[code]...
When I run, it makes me enter letter = null and it wont output correctly.

View Replies View Related

Why Is Loop Outputting Line Twice

Oct 29, 2014

I have a loop and I was wondering why it is outputting my line twice. Here is the code:

while (x != -1) // closes the program if the user enters -1 for x
{
System.out.println("Which jar would you like to access? Please select a number between 1 and 3. Press -1 to exit.");
x = scan.nextInt();
ourpantry.Selection(x); // tells our pantry class what number the user selected
while ((response != "continue")) // loop continues until user gives a valid response

[Code] ....

This results in the Output:

Would you like to spread jam? Y or N.
Would you like to spread jam? Y or N.

View Replies View Related

Outputting Calendar On Console

Oct 14, 2014

I created a calendar program so when the user enters a day number and a year it would show the calendar for the year . My issue was that I could not get the numbers to line up neatly and how they should look . Also if its not to much trouble I would like to know how to turn this in to a loop .

import java.util.Scanner;
public class Calendar {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a Year");
int Year = scanner.nextInt();

[Code] .....

View Replies View Related

Outputting 2 Classes - ToString Method

Apr 22, 2014

My current assignment involves me outputting these 2 classes. Yet I'm not really sure in what manner I should go about doing this. I have tried creating a separate class and outputting my toString methods there but for some reason I am getting an error. .

The error message is thus;

Exception in thread "main" java.lang.NullPointerException
at Vehicle.toString(Vehicle.java:91)
at Run.main(Run.java:17)
 Process completed.

import java.util.Calendar;
public class HireContract {
String reference;
Calendar startDate = null;
Calendar endDate = null;
Vehicle vehicle = null;;
String customerRef;
double rate;

[Code] .....

View Replies View Related

User Input - Outputting To Excel Document

Mar 30, 2014

I am currently working towards taking input from the user and storing it in an excel document. However how can I test to make sure that I am trying to save it to an empty cell. Is there some type of method that will check to make sure the cell is empty, otherwise how can this be done?

View Replies View Related

Double Data Type Outputting To Exponent?

Nov 9, 2014

I was struggling to use BufferedReader to extract some data and then perform some calculations and then have the results as outputs.

I haven't quite solved that issue but in order to progress, I hard coded some values into my application and proceeded with the actual calculation loops etc.

Currently, the value out put from one of my calculations is given as:

1.1704926E7

How can I make the console show it in a natural way. I've performed the calculation manually and it should be 11704926.5 I don't want to lose that .5!

View Replies View Related

Comparing Two Array List And Outputting Difference

May 12, 2014

I'm having a bit of trouble outputting the difference between two array list

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.ArrayList;
public static void main(String[] args) throws Exception {

[Code] ....

This prints out something like

Test1
Test1
Test2
Test2
Test2
Test3
Test3
Test3
Test4
Test4
Test5
Test5
Test6
Test6
Test6

Ideally, it's suppose to print out only Test2, Test3, Test6.. I've tried different combinations of loops and equals() but I never get the correct output.

View Replies View Related

XML :: Setting Stylesheet Ref When Outputting File Using SAXTransformerFactory

Sep 27, 2012

I am using SAXTransformerFactory to output an XML file but can't figure out how to output the stylesheet setting, for example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ectd:ectd SYSTEM "util/dtd/ich-ectd-3-2.dtd">
<?xml-stylesheet type="text/xsl" href="util/style/ectd-2-0.xsl"?>

I am using the following code to get the first two lines, I just can't see how to output the third line above.

SAXTransformerFactory mTransformerFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
TransformerHandler handler = mTransformerFactory.newTransformerHandler();
Transformer mTransformer = handler.getTransformer();

mTransformer.setOutputProperty(OutputKeys.VERSION, "1.0");
mTransformer.setOutputProperty(OutputKeys.ENCODING, IBF_UtilXML.XML_ENCODING_UTF8);
mTransformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "util/dtd/ich-ectd-3-2.dtd");

I believe I found an example using a DOM approach but I would much prefer using SAX.

<?xml-stylesheet type="text/xsl" href="util/style/ectd-2-0.xsl"?>

View Replies View Related

Reading / Outputting A Text File With Modified Content

Feb 15, 2014

This is sort of like the last problem I had but it's all about the formatting at the end. I have a file that reads something like:

Name
a bunch of text here
and perhaps a second
or even a third line

I need to output this as:

Name; "a bunch of text here and perhaps a second or even a third line"

Right now I find 'Name' and it outputs:

Namea bunch of text here and perhaps a second or even a third line

How would I add ";" and quotes in the middle? I can imagine that I may need to find name, then skip to the next line and just add name manually as the variable output of the search string.

This is where I am now

public static void main(String[] args) {
boolean output=false;
String name="";
String junk="CHAMBERS";
TextIO.putln("Search for a name");
name = TextIO.getln();
TextIO.readFile("doc.txt");

[Code] .....

So I'm almost there, but those dange double Names are killing me. I tried to add a bit of code where:

if (line.indexOf(name) >= 0){}

View Replies View Related

Program Outputting Null Into Validation Statement - Runtime Error

Oct 17, 2014

I am Having trouble with my program to validate. It is outputting null into the validation statement then it brings back a run-time error to that validation Statement for the String.

public String validateData ()
{
if (nm == null)nm = "Error! Must enter at least one character";
else nm = name;
return name;
}//end validation method

Why is this happening, and then once that is completed, why is the validation Sentence in tests Scores not able to validate. I traced it back to out put "Error, a number between 1<100".

public void validateTests ()
{
String testschange;
if (test1 < 0 || test1 > 100) {
testschange = " You have entered an invalid number, between 1-100. Please restart!";
testschange = Integer.toString( test1 ) ;

[Code] .....

View Replies View Related

Taking Range Of Names In Array And Outputting Them Alphabetically - OutOfBoundsException

Apr 24, 2014

At the moment I am studying it and the problem is Taking a range of names in an array and outputting them alphabetically, But for some reason I get an outOfBoundsException. And its starting to get to me. How to put the code in

import java.util.Scanner;
import java.util.Arrays;

public class lab241 {
public static void main(String[] args) {
Scanner kb= new Scanner(System.in);
String[ ] names = new String[4];

names[0]= ("Horatio");
names[1]= ("Anatoly");
names[3]= ("Evelyn");
names[4]= ("Anna");
Arrays.sort(names);
for(String N: names){

System.out.println(N);

View Replies View Related

Difference In Variable Assignment Between Constructor And Variable Section

May 21, 2014

Given the case I have an object which is assigned only once. What is the difference in doing:

public class MyClass {
private MyObj obj = new MyObj("Hello world");

private MyClass(){}
//...
}

and

public class MyClass {
private MyObj obj;
private MyClass(){
obj = new MyObj("Hello world");
}
//...
}

Is there a difference in performance or usability? (Given also the case there are no static calls expected) ....

View Replies View Related

Are Terms Local Variable And Member Variable Comparable

Oct 27, 2014

The term "Local variable" is related to scope. That is a local variable is one which is defined in a certain block of code, and its scope is confined inside that block of code.And a "Member variable" is simple an instance variable.

I read in a discussion forum that when local variables are declared (example code below), their name reservation takes place in memory but they are not automatically initialized to anything. On the other hand, when member variables are declared, they are automatically initialized to null by default.

Java Code: public void myFunction () {
int [] myInt; // A local, member variable (because "static" keyword is not there) declared
} mh_sh_highlight_all('java');

So it seems that they are comparing local variables and member variables. While I think a member variable can also be be local in a block of code, isn't it?

View Replies View Related

Reference Variable - Create Another Variable And Set It Equal To First

Jan 11, 2015

Given a reference variable : Car c1 = new Car();

when we create another variable and set it equal to the first : Car c2 = c1;

we're pointing c2 at the same car object that c1 points to (as opposed to pointing c2 at c1, which in turn points at the car). So if we have code like,

Car c1 = new Car();
Car[] cA = {c1, c1, c1, c1};

are we doing the same? Are we creating four *new* reference variables, each of which points at the same car (again as opposed to pointing them at c1 itself)? I think so, but want to make sure I'm understanding this correctly.

View Replies View Related

How To Use Value Of String Variable Cel1 As Variable Name

May 23, 2014

I have a JFrame jf and JPanel jp on it. jp has five TextFields named cel1, cel2.. cel5. I wish to construct a String Cel + for loop index and run a for loop to reset the values of all the text fields using a single statement such as cel1.SetText("abc"). Similar things can be done in foxfro. How does one do it in java?

View Replies View Related

How To Use Variable In If Statement

Feb 17, 2014

How do I use a variable in an if statement to return a public void method from another class? I've tried:

System.out.print("select 1 - 6: ");
Scanner myScanner = new Scanner(System.in);
myScanner.nextInt();
if (myScanner.nextInt()==1) {
carSelection colour = new carSelection();
colour.carSelection();

The method colour in class car selection is just 4 print line statements? I've // out the if statement to see if it is correctly calling the method and displaying the data and it is?

View Replies View Related

What Is Variable Shadowing

Oct 6, 2014

What is variable shadowing?When does it occur?

View Replies View Related

Using Same Variable Name In Two Classes

Feb 7, 2014

Regarding the code examples in Head First Java, this is from Chapter 5, regarding the beginning creation of the dot com game. There are two classes in quesiton

the first is the SimpleDotComTester class:
public class SimpleDotComTester {
public static void main(String[] args)
{
SimpleDotCom dot = new SimpleDotCom();
int[] locations = {2, 3, 4};
dot.setLocationCells(locations);
String userGuess = "2";
String result = dot.checkYourself(userGuess);
}
}

and the second one is the code for the checkYourself () method in the SimpleDotCom class

public class SimpleDotCom {
int[] locationCells;
int numOfHits = 0;

public void setLocationCells(int[] locs)

[code]....

Now I noticed that both classes use a variable called result; the program runs fine, but assume from the example that you can use the same variable name two different classes;

View Replies View Related

JSF :: How To Set A Variable Globally

Mar 16, 2014

i have a datatable with id= tblId#{emp.id}
<c:set var="tableID" value="tblId#{emp.id}">
displaying employee details inside c:forEach
closing dataTable.

[code]...

For ex.Displaying 5 table dynamically.Need to validate check box selected or not.5 table are displayed.But it shows 5th table row id only.It is because of local varible declaration?

View Replies View Related

Variable Value Not Printing

Nov 6, 2014

I'm making a program where the user enters an ID number and can submit the amount of sales that person made for a specific product and write to a file. One of the things I have to do is making a running sum of the sales for each product for all people combined as well as an accumulation of the a persons sales every time he enters data. Everything seems to be working execpt my values like person1Total, person2Total...etx and product2Total.

When I try to write them to the file, they always come out at 0.0 even though they should be the sum of the indexes of the array sales.

import java.io.*;
import java.util.Scanner;
public class SalesReport {
// private static double p1Total, p2Total, p3Total, p4Total;
private static double product1Total, product2Total, product3Total, product4Total, product5Total;
private static double person1Total, person2Total, person3Total, person4Total;
public static void main(String[] args) throws IOException

[code]....

View Replies View Related

How To Initialize Variable Only Once

May 2, 2015

I'm working on a program where the user inputs song information (name, artist, filesize, duration) which is stored in a database. Once the user adds a song, the details should be stored in the first empty song slot (4 song slots total) and then taken back to the menu interface.

What I'm having trouble with is that I can add the first song fine (song1), but when I try to add another song, the information entered into song1 is gone. I've worked out that this is because every time I call upon the addNewSong() method, I'm creating four Song objects that are brand new with the line:

Song song1 = new Song();
Song song2 = new Song();
Song song3 = new Song();
Song song4 = new Song();

How to fix this problem is where I'm stuck because if I move these lines elsewhere, I get a 'cannot find symbol - variable song1' error.

Here is my code:

public class SongDatabase {
Scanner console = new Scanner(System.in);
public void addNewSong() {
Song song1 = new Song();
Song song2 = new Song();
Song song3 = new Song();
Song song4 = new Song();
if (song1.isEmpty()) {

[code]....

View Replies View Related

Why Cannot Get Value Of Variable To Display

Jul 18, 2014

I trying to display the value of a variable from a method, but I don't know why it will I can't do it.

//Java extension package
import javax.swing.JOptionPane;
public class Palindrome
{
public static void main(String[] args) {
int number = 0;
int palindrome = 0;

[Code] ....

View Replies View Related

Variable Name From Table Value?

Apr 17, 2014

How can I make variable from table value? Example:

Java Code:

String table [] = {"vara","varb"};
for(int i = 0; i < table.length; i++)
{
int table[i] = i;
} mh_sh_highlight_all('java');
And vara = 0, varb = 1 here.

Is this even possible?

View Replies View Related

How To Get Value From Database To Use In Variable

Apr 23, 2014

i'm new withh java netbeans, and i want to make program where variable from database. how to get value from database to use in variable/

View Replies View Related

Old Object Take Variable From New

Apr 30, 2014

I have a problem with my code. When, on strausParser class, i create the new object Beam i give him an array of Node object called "nodiestremi".

The problem is that when a Beam is created, the Beam created before take the Node of new Beam. Why it appends?

public class Main { 
public static void main(String[] args) throws NumberFormatException, IOException{
SetFile.setupWindows();
Structure structure = new Structure();
}
public class SetFile {
}

I get an output like this:

Import node complete
0 0 0 1
0 1 1 2
0 1 1 0
0 2 2 4
Import beam complete

and not like this:

Import node complete
0 0 0 1
0 0 1 2
0 0 1 0
0 0 2 4
Import beam complete

View Replies View Related







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