How Boolean Finished Is Set To False And Breaks While Loop

Sep 11, 2014

I'm having trouble understanding how this loop is broken, I can't understand how the boolean finished is set to false and breaks the While loop.

public void run()
{
char answer;
boolean finished = false;
while(!finished)// when false loop is broken

[Code] ....

View Replies


ADVERTISEMENT

Boolean Value (true Or False) Randomly Set?

Jun 15, 2014

I have the code and it works very well, but my professor wants us to use Junit testing to test our code. I've never used JUnit before, how it works. Is it possible to have a boolean value (true or false) randomly set?

Here is the code I need to test:

package musicalinstruments;
class MusicalInstrument {
public String name;
public boolean isPlaying;
public boolean isTuned;
public MusicalInstrument(){
isPlaying = false;
isTuned = false;

[Code]...

View Replies View Related

How To Stop Boolean Value Going Back To Original Value In While Loop

Oct 9, 2014

Inside a While Loop (While Loop begins if a condition is True) I have an If Statement, the else part of the statement assigns False to the condition I mentioned earlier.

But I've tried de-bugging and even when the code goes through the else part of the statement, firstly it returns False but then it returns to the beginning of the loop as True again.

View Replies View Related

Loop / Boolean - Find Greatest Common Divisor Of Two Integers

Sep 25, 2014

In attempting to find the greatest common divisor (gcd) of two integers, n1 and n2, whereas k is a possible gcd and gcd is initialized to 1, the following code has been entered:

for (int k = 2; k <= n1 && k <= n2; k++) {
if ( n1 % 2 == 0 && n2 % 2 == 0)
gcd= k;
}

When asked to change the previous line of code to this:

for (int k = 2; k <= n1 / 2 && k < n2 / 2; k++){

the questions states this revision is wrong and to find the reason.....well, I've changed it, entered "3" (per the answer key) for n1 and n2....

now I can see logically where k (2 in this example) is not <= n1/2, which is 3/2 or 1, since we're dealing w/integers, yet when I compile and run, my answer is indeed, gcd = 1. However, since this is a Boolean expression where && is being used, since the first portion evaluates to "false", the 2nd portion isn't executed and thus my result of 1?...... loops are throwing me for one, for sure....

View Replies View Related

Determining When JAVA Thread Is Finished

Jul 27, 2014

I have been new to JAVA programming language and have been using it for generation of a GUI (with NET BEANS).

My problem is, when i start a thread within GUI, that takes some amount of time to get finished (around 5min to 20min cpu time),

I need an a way to detect when the thread is done and accordingly some action to be taken afterwards.

I tried with isAlive, but to no avail.

Example is, I press an JButton, thread starts, when finished Jbutton get colour changed.

View Replies View Related

Swing/AWT/SWT :: Controls Not Updating Until Method Is Completely Finished

Dec 30, 2014

I have this method that does several RegEx queries along with a lot of searching and replacing of text, and each regex search / replace takes some time and a total of maybe two minutes for all of them to finish up. So I added a ProgressBar to my JavaFX form and I added code after each step to simply use the ProgressBar.setProgress method by a factor of 10% each step ... so the code would resemble something like this:

do a regex query
if it finds things then do a replaceAll method on the string being searched
ProgressBar.setProgress(.1)

do another RegexQuery
If it finds stuff, so a replaceAll method
ProgressBar.setProgress(.2)

etc...

What is happening is that the progress bar will not actually paint any progress until AFTER the entire method is done executing. So from the users perspective, they click on the button and the program appears to freeze until its all done with that method at which point it instantly changes the progress bar to the last value I set ...

So the desired effect is simply not working, and I don't know why.

I tried changing (as in replacing the progress bar with a different control) the progress bar value settings with updating text in a text box on the form, and even that didn't display any of the text messages until AFTER the procedure was done executing at which point, all of the text logs appeared at one time instead of gradually adding text to the box in increments as the method executed.So it FEELS like any time a method is actually running, the JavaFX scene simply freezes until the method is done running. And it doesn't matter if I change the progress bars value directly or put it into its own method which gets called throughout the execution of the regex method ... either way, nothing actually happens on the form until the software is done executing all of the procedures called and then it comes back to a "resting" state...

I tried simplifying it by making a single method that does two things ... it updates the progress bar and then it waits for 1 second. Then it increments a variable then updates the progress bar, then waits a second, thinking to myself that 1 second pause would give it time to update the progress bars value but even that little method would not work.

Here is the test method I created:

private void testProgressBar() {
for(int x = 0;x<10;x++) {
progressBar.setProgressBar(.1*(x+1));
try {
sleep(1000);
}
catch(InterruptedException e) {
e.printStackTrace();
}
}
}

Even that little piece of code will not actually show any changes in the progress bar until after its done looping at which point, the progress bar is filled to 100%, but I never see the first 9 changes in the progress bar within that for next loop.

View Replies View Related

While Loops And Conditional Breaks?

Feb 12, 2015

public class dowhile2 {
public static void main(String[] args) {
int i = 1;
while(i <= 100){
System.out.println(i);
if(i == 50){
break;
}
i++;
}
}
}

I just want to know how to count this lines of codes. Because if I place for example i++ further up the code or the system.out.println a bit lower the result will be 1-49 or 2-50 and not the goal that is 1-50.

I want to know how to think and count. Why do i get 2345678.........50 and not 12345678........50 or 12345678.....49, thats the question.

View Replies View Related

Code Breaks After Upgrading To Java 8?

Jan 22, 2015

We recently upgraded to JDK 8. Since then, a section of code in a jsp file breaks. The code is this:

ArrayList all = new ArrayList();
final List tsd = timeSeriesBean.getTSData();
all.addAll(tsd); 
Collections.sort(all, new Comparator() {
public int compare(Object o1, Object o2) {
TSData t1 = (TSData)o1, t2 = (TSData)o2;
int res = t2.getDate().compareTo(t1.getDate());

[code]....

The error message is this:

An error occurred at line: 65 in the jsp file: /TS/VerifyImportTSData.jsp The type new Comparator(){} must implement the inherited abstract method Comparator.thenComparing(Function, Comparator)
 
64:
65: Collections.sort(all, new Comparator() {
66: public int compare(Object o1, Object o2) {
67: TSData t1 = (TSData)o1, t2 = (TSData)o2;
68: int res = t2.getDate().compareTo(t1.getDate());

just trying to maintain some old java code that I can support until it is rewritten.

View Replies View Related

JSF :: Page Content In OUTLOOK Body Not Getting Breaks

Jun 3, 2014

I have a requirement. I got a JSF page(parent page). When a button(say SEND EMAIL) is pressed, an email window (OUTLOOK) will be displayed as a popup. I have to populate whatever the text data of parent page as the body of the mail.

I am using mailto method : eg :

Here is my code:
==============
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest origRequest = (HttpServletRequest) context.getExternalContext().getRequest();
context.getExternalContext().redirect(String.format("mailto:"+mailTo+"?subject=" + subject +"&body=" + body + "&cc="+mailCc+""));

till here it is fine..

My problem is body part is not getting breaks. I have tried
, ,
, <br>, <br></br> etc.. what ever stuff i found in google..

E.g. my email body looks like below.. it consists of url link also.

====================================================
Hi,

This is to inform you etc... ,

Please follow this Hyperlink link to navigate to your page.. etc.

regards..

======================================================

View Replies View Related

Moving Executable Jar Breaks App Save Function

Apr 1, 2014

I've been trying to deploy my desktop application as an executable jar file but I'm facing the following problem: Whenever I move the jar file from its original build location, my application becomes unable to write to its external files. I initially thought the problem was path related; however, when moved the app can still load data from these files.
 
The solution is probably simple but for some reasons I've yet to find it .
 
The app consists of a jar file and a folder named "files" containing text files (such as library.data) to which serialized objects are written.
 
I wouldn't be surprise if the problem has to do with the xml build file, but all modification I've tried so far have failed. If it is likely that it is the problem, I'll be happy to post a copy of it upon request.
 
public static void saveLibraryToFile() {
    File file = new File(System.getProperty("user.dir")+"fileslibrary.data");
    if (file != null && file.exists()) {
        library = new Library(sortedAccounts, accountCategoriesMap, accountCategoriesList);
 
[Code] ....
 
A mostly complete set of the relevant codes I'm using, including the full Ant xml file, can be found at : [URL] .....

View Replies View Related

True And False / Scanner

Jul 7, 2014

My goal is to ask them for their name and if they got it right then it says yes while if they wrote it wrong, it would say no.

Java Code: public static void main(String[] args) {
Scanner name = new Scanner(System.in);
System.out.println("What is your name?");
String sname = name.nextLine();
name.close();
System.out.println("Are you sure it's " + sname + "?");
Scanner tfname = new Scanner(System.in);
String stfname = tfname.next();

[code]....

View Replies View Related

Binary Search Returning False

Apr 15, 2014

The problem is it is returning -2, and also returning false when it should be true. There is no error it just is not working correctly.

import java.util.Arrays;
import java.util.Scanner;
/**
* This Script will allow you to add e-Mails and than beable to search for them.
*/
public class eMailSeacher
{
public static void main(String[] args)

[Code] ....

1. Enter an Email
2. Find an existing email
3. Exit
1
Enter the users E-Mail:
josh
-1
Insertion successful.

ans so on .....

View Replies View Related

Servlets :: How To Set Httponly To False For A Secure Cookie In 2.5

Mar 26, 2015

As below i m creating cookie .

Cookie myCookie = new Cookie("myck", value);
myCookie.setSecure(true);
response.addCookie(myCookie);

I am trying to read that cookie in javascript as below.

var cookieValue = $.cookie("myck");

I can see the cookie in the browser. However the read is not happening I tried to set httponly to false

myCookie.setHttpOnly(false);

However it is throwing compilation error as my servlet version is 2.5

Is there any way to get the cookie in javascript?

View Replies View Related

User Input True False Questions

Jan 11, 2015

Create an application that generates a quiz. Prompt for the user's first and last name, college major, and confidence in test taking (high, medium, or low). The quiz should contain at least five true/false questions about horticulture. When the user selects the correct answer, a message of positive reinforcement should be displayed. If the user selects the incorrect answer, the correct answer should be displayed with a message of constructive criticism. At the end of the quiz, display the number of correct and incorrect answers as well as the percentage of correct responses for each user.

import java.util.Scanner;
class HorticultureQuiz { 
public static void main(String[] args){

[Code].....

View Replies View Related

SetVisible Not Working When Starting On False (AWT Label)

Jul 24, 2014

I'm trying to create a Label using AWT (not swing) that is invisible on startup but shows up when pressung a button. Here's the relevant code:

Label:

updated = makeConfirmedLabel("Updated!");
updated.setVisible(false);

Button:

update = new Button("Update");
update.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
MainComponent.updateComponents();
System.out.println(updated.isVisible());
updated.setVisible(true);
System.out.println(updated.isVisible());
}
});

When I press the button I get the following output in console:
false
true

If I start with setVisible(true) and use updated.setVisible(!updated.isVisible()) it works fine. Why can't I start with it hidden??

I tried to use updated.revalidate() after setting it visible. That made it work but it makes the whole UI flicker when pushing the button which isnt desired.

View Replies View Related

String Declaration - Check A / B Returns False

Jan 30, 2014

I have doubts in string declaration. As I know we can declare string in two ways:

1. String a=new String("Hello");
2. String b="Hello";

What is exact difference between them? Another thing is when I check (a==b) it retuns me false, but when I check a.equals(b) it returns me with true. Why So?

View Replies View Related

Truth Table - Display 1s And 0s Instead Of True False

Feb 26, 2005

I'm supposed to take this truth table and alter it so it displays 1's and 0's instead of true false. I'm assumed to do this I would just need to change the variable type and replace true and false with 1 and 0 but every way I try this does not work.

//a truth table for the logical operators.

class LogicalOpTable {
public static void main(String args[]) {
boolean p, q;
System.out.println("P Q AND OR XOR NOT");
p = true; q = true;
System.out.print(p + " " + q +" ");

[Code] ....

View Replies View Related

Determine If There Is Path From One Vertex To Another - Why Is This Returning False

Dec 7, 2014

This method pretty much determines if there is a path from one vertex to another. When I check to see if there is a path from 5 to 2 (which there is) it return false. However, when I create a driver method, it return true (which it should). Why? It should never reach outside of the else because the condition is met, right???

Here is the graph:

0 1 2 3 4 5
------------
0| 0 1 1 0 0 0
1| 0 0 0 0 0 0
2| 0 0 0 1 0 0
3| 1 0 0 0 0 0
4| 0 0 1 0 0 1
5| 0 1 0 1 0 0

Path: 5 points to 1 and 3 (1 does not have a path to anything). 3 points to only 0. 0 points to 1 and 2. Thus there is a path from 5 to 2.

Here is the code without the driver (the one that is returning false, even tho it should be true)

public boolean existsPath(int x, int y){//x = 5, y = 2
stack.push(x);//mark x as visited
if(x == y){//path found
stack.removeAllElements();
return true;

[Code] ....

View Replies View Related

Queues - IsEmpty Method Only Returns False

Jan 29, 2015

My isEmpty method only returns false. Is something wrong? I printed the empty and not empty for testing purposes.

//determines if there are any items in the queue
public boolean isEmpty() {
if (front == -1 && rear == -1) {
System.out.println("empty");
return true;
} else {
System.out.println("not empty");
return false
}
}

View Replies View Related

Check If Height Is A Letter Between A To J - If Statement Always False

Jun 22, 2014

Why isn't heig ever equal to heightShipArray[count] no matter what letter I type in

String[] heightShipArray = {"A", "a", "B", "b", "C", "c", "D", "d", "E",
"e", "F", "f", "G", "g", "H", "h", "I", "i", "J", "j"};
boolean trueHeight = true; // checks if height is a letter between a-j/A-J
do {
Terminal.printLine("Input height with letters A to J");

[Code] ...

View Replies View Related

Dynamic Enum - How To Make DIME(10) False

Apr 20, 2015

I wrote a simple enum and a test class. The enum represents us coins and my test class uses the enum to calculate the change with the least number of coins. For example, I pass in 95 cents, I get back 3 quarters, 2 dimes. It all works just fine, easy to implement and I see why I should use an enum. Then I thought, what if the person is out of dimes. How could I tell the enum to skip dimes in it's switch statements? How would I make DIME(10) false?

View Replies View Related

How To Make Panels Visibility Go False / True With Actionlistener

Jan 28, 2014

I'm trying to create a program that has two labels... one in the top left and one in the top right... so far when i run it only the one in the top right (label2) shows... also In the program there will be multiple button and when I click a button it will show a different panel and then i can go back to the first panel to select other panels... so far i haven't figured out how to make panels visibility go false/true with actionlistener. last thing... when i have more then one panel added to the frame none of them show up.

Java Code:

//Matthew
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test{
public static void main(String[] args){

[code]...

View Replies View Related

True / False Result Cannot Be Printed Due To Variable Answer

Jun 30, 2014

Code in the book is written exactly like this:

import java.util.Scanner;
public class AdditionQuiz {
public static void main (String[] args){

//Generate random two integers using utility System.currentTimeMillis
int n1 = (int)(System.currentTimeMillis() % 10);
int n2 = (int)(System.currentTimeMillis() / 7 % 10);

[Code] ....

however the true/false result can not be printed due to the "answer" variable...

View Replies View Related

Java Servlet :: IsTokenValid (request) Always Returns False

Jan 29, 2013

I am using saveToken(request) and isTokenValid(request) to stop duplicate request. But while checking isTokenValid(request), it always returns false.

View Replies View Related

User Input 2 Ints - Output True If One Is In Range Otherwise False

May 14, 2014

How do I make it so that if both numbers are entered between 10 and 20 it will print false?

The assignment: Ask the user to enter 2 ints. Output "true" if one of them is in the range 10 - 20 inclusive, but not both. Otherwise output "false"

12 99 → true
21 20 → true
8 99 → false
15 17 → false

import java.util.Scanner;
 public class Practice {
 public static void main(String[] args) {
 //get user input
Scanner user_input = new Scanner(System.in);
System.out.print("Enter a number: " );

[Code] ....

View Replies View Related

Java Method - Return True If String Can Be Found As Element Of Array And False Otherwise

Mar 17, 2014

I am new to Java and would like to ask how to do this question specifically:

Code a Java method that accepts a String array and a String. The method should return true if the string can be found as an element of the array and false otherwise. Test your method by calling it from the main method which supplies its two parameters (no user input required). Use an array initialiser list to initialise the array you pass. Test thoroughly.

View Replies View Related







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