Testing Boolean Statement

Mar 30, 2015

I wrote a class for encapsulating coins and I was to do a boolean statement but when I test the statement the results are not showing.Here is the code for my coin class coins.java

package project_3;
/**
*
* @author user a
*/
public class Coins {
private double pennies;
private double nickles ;
private double dimes ;
private double quarters ;
private int dollars ;

[code]...

View Replies


ADVERTISEMENT

Boolean Statement Not Working

Apr 14, 2015

code=Java
import java.util.Random;
import java.util.Scanner;
public final class Derp {
public static int WIN, Tick;
public static Scanner Input = new Scanner(System.in);

[code]...

why this boolean statement isn't working correctly. It's not detecting that the WIN and Tick are the same and instead chooses to always run the second statement.

View Replies View Related

Using String And Boolean In If Statement?

May 24, 2015

I want to write a program that ask if you want to go to the movies. If the user type in yes then it'll print out (Alright let go) but if the user type no then it would print (whatever). The trouble that I'm having is. What's the best way to use Boolean and Strings together in a if statement?

public class Night {
static Scanner UserInput = new Scanner (System.in);
public static void main (String [] args){
boolean user1, user2;
user1 = true;
user2 = false;

[Code] ....

View Replies View Related

If Statement Requires A Return Of Type Boolean

Dec 6, 2014

Im trying to do this

if( 2/2 ) {
system.out.println( "number is not event" );
} else {
system.out.println( "number is event" );
}

However if statement requires a return of type boolean. So im forced to this instead

if( (2/2) != 0 ) {
system.out.println( "number is not event" );
} else {
system.out.println( "number is event" );
}

Is there a way to achieve the former method, without typecasting, if you had to typecast how do you do it?

View Replies View Related

Assert Statement Check Boolean Expression During Runtime Execution

Mar 5, 2014

An assert statement checks a Boolean expression during run time execution. Is this true?

View Replies View Related

Testing TCP Client And Server

Oct 22, 2014

I am attempting to test a TCP Client and Server for an assignment I am doing in class. The goal here is to "test your client and Server applications by transferring (i) a file having 10,000+ lines (see supplied big-file1.txt having 12000+ lines), (ii) a file having 20,000+ lines (you may create one of your own from big-file1.txt, or obtain a large size file from the Google website at [URL] ...). Then, compute and display the total transfer time of the files at both of the sides separately (your choice in millisecond/second)."

I have created the TCPClient and TCPServer java classes, ran the server first and then the client, and using mathematical formulas to calculate the transfer time. Trouble is, I'm having trouble testing the client and server in the file area and not the area where I had to input a line, let the server print it, and then have the client eliminate the articles from the line. I need testing the file. Here is my code so far:

TCPClient:

package tcpclient;
import java.io.*;
import java.net.*;
public class TCPClient {
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
String sentence;

[code] ....

How to fix the code so that the time in seconds does not output as 60 for both files and that the files go through the exchange?

View Replies View Related

Testing Double Null

May 2, 2014

how to execute a particular class. I've created a Kinematics class that will execute and calculate all the functions pertaining to kinematic equations. In the main class, I will have the user provide the data in JTextField. Now I need to test which JTextfields (variables) were left empty. I plan to use a number of if/else statements :

if(distanceI != null && distanceF != null)

The problem with this is that these variables are double and therefore cannot be tested as null. I read a few things about Double but I really don't see how I'm supposed convert each double variable to Double, is that even possible?

public class Kinematics {
double distanceI, distanceF, velocityI, velocityF,
velocityAverage, acceleration;
public Kinematics(){
//v2 = v1 + a*dt
if(distanceI != null && distanceF != null){
 
[code]...

View Replies View Related

Database Junit Testing

May 28, 2014

I have been designing a music collection application that runs from a database. I now need to develop a junit test to test the application but I am not sure if Junit has anything to work with testing databases. I have been googling on the internet but most of the search results do not really give any good examples that I can easily follow and adapt to my application. I am using only one table and I would like to test INSERT, UPDATE and DELETE actions and I would also like to test a successful connection.

I once found one tutorial which I cannot find any more that had something that retrieves all the data in the database and stores it in a CSV file and the loops through the CSV file to check or update information.

View Replies View Related

Testing Events Within Inner Class Using JUnit?

Apr 17, 2015

How do you test the events within an inner class using JUnit

// File: : events/SomePanel.java
// Purpose: Show use of named inner class listener.
 
import javax.swing.*;
import java.awt.event.*;
class SomePanel extends JPanel {
private JButton myGreetingButton = new JButton("Hello");
private JTextField myGreetingField = new JTextField(20);
 
[Code] .....

Code extract taken from: Java: Inner-class Listeners

Taking the above example, do I need to use myGreetingButton.doClick to trigger this event to test the respective variables/values being used ? Also the Actionlistener inner classes is private so doubt I can access this from JUnit Test class.

View Replies View Related

String Testing For Null / Empty?

Oct 13, 2014

I've been beavering away with Java for a few months. But as with all languages the String implementation looks designed to trip up even experienced programmers.

My current development gets data from various sources outside my control. When I get a string I want to test if it is empty/null/or whatever. Simple enough one thinks.

But if you search the internet you see everone seems to have a slightly different approach. So what is the best way of determining that a string is not useful to you?

I've had success with this

if(string == null || string.length() == 0)

But I've seen people using methods - not necessarily of String (e.g equals, empty) and regular expressions.

What is the best approach to this considering coding efficiency and/or processing efficiency (accepting you'd have to be processing a lot of strings for the latter to be an issue).

View Replies View Related

EJB / EE :: Bean Annotations And Unit Testing?

Mar 6, 2014

I have a bean that represents data been collected from a form on a jsp page. Currently I would like to validate my fields and write some test cases for them. As you can see from my test case example I test a string in the hope that it fails because it contains only one letter. My problem is my unit test is passing. The reason this is from what I can tell is that at runtime it fails when I try to persist my object using my entity manager. During my unit test I just I don’t call my entity manager I just try and set the field.

What I thought would happen was that when I use my bean fields set method the annotations would be checked and fail at that point. Hence why I expected my unit test in this case to fail.

What I would like to know is

1.Are annotations specifically designed to validate when I persist my object and am I using them incorrectly at this point?

2.Is this the best method to use to validate fields, is there a better way, should I write my own code to validate for me when I set my value?

a. Should I throw an exception from the set method of each bean field?

Unit Test:

@Test
public void testName(){
Human h=new Human();
try {
h.setFname("a");
} catch (Exception e) {
// TODO Auto-generated catch block
fail("failed");
e.printStackTrace();

[code]....

View Replies View Related

Syntax Error When Testing Code

Jun 4, 2014

My issue is that when I run the code if I enter anything but 1, 2, or 3 the code breaks. I have spent hours trying to find the error. here is my code

import java.util.Scanner;
public class Tester {
public static void main(String[] args) {
/**
* constructor
* pre: none
* post: inherit values of other classes
*/
Car Car = new Car(); //inherits the properties of the Car class
Truck Truck = new Truck(); //inherits the properties of the Truck class

[code]....

View Replies View Related

Testing Testcase In Junit3 Using Treemap

Apr 22, 2014

I am beginner in Java and facing one problem while testing junit3 testcase using treemap.

The code :
===========================
package sampleJunit3;
import java.util.TreeMap;
import org.junit.*;
import static org.junit.Assert.*;
import junit.framework.TestCase;

[code]....

While running as a Junit Test, test getting failed with error " Test Class not found in selected project".

View Replies View Related

How To Turn If Statement Into A Case / Switch Statement

Jun 19, 2014

So from what iv learnt in Java and programming in general is that using a case statement is far more efficient that using multiple IF statements. I have an multiple IF statements contained within a method of my program, and would like to instead use a case statement.

public String checkPasswordStrength(String passw) {
int strengthCount=0;
String strengthWord = "";
String[] partialRegexChecks = { ".*[a-z]+.*", // lower
".*[A-Z]+.*", // upper
".*[d]+.*", // digits
".*[@#$%!]+.*" // symbols

[code].....

View Replies View Related

Precision And Recall Testing For Search Engines

May 14, 2014

I have code for precision and recall testing for search engines. I am trying to run it in Newbeans 8.0, but I am getting the common error in UnsupportedOperationException

I have tried making files and directories as the given in the code file. I am attaching the two files here.

Attached File(s)

 PrecisionRecall.rtf (1.79K)
 FSDirectory.rtf (687bytes)
error file-result.rtf (506bytes)

View Replies View Related

Testing Two Mapping Libraries - Orika Vs JMapper

Feb 27, 2014

I have downloaded and testing these two mapping libraries. I wrote a program which has 100000 iterations and maps the beans of the same class:

public class IntBean {
 
    @JMap
    private int int1;
    @JMap
    private int int2;

[Code] ....
 
Mappers are created BEFORE iterations start:
 
    private JMapper jmapper = new JMapper(IntBean.class, IntBean.class);
    private MapperFactory orikaFactory = new DefaultMapperFactory.Builder().build();
    private MapperFacade orikaFacade = null;
orikaFactory.registerClassMap(orikaFactory.classMap(IntBean.class,IntBean.class).byDefault().toClassMap());    orikaFacade = orikaFactory.getMapperFacade(); 

What is in each iteration:this.orikaFacade.map(a1, a2);
or
a2 =  (A) this.jmapper2.getDestination(a1);
 
I know, that Orika and Jmapper are great libraries from Google and they use reflection in a different way than for example Dozer, which is much slower, they se reflection to generete code somehow..

I have 3 questions:

1) How they work - when the code is generated, during maven build, in runtime - everytime when I create mapper in code? Are they change class code byte dynamically?
2) Why there is this speed difference that I noticed?
3) Which library would you choose and why? Both have the same capabilities? Why both come from Google? Why Google didnt develop Orika and created Jmapper instead?

View Replies View Related

Swing/AWT/SWT :: Using Doubles For Positioning Objects And Testing Equality

Aug 15, 2014

I've been noticing some of my programs have been a little buggy recently, and think it's down to confusion over doubles and positioning. Lets say I have a label called banner that I want to scroll across the screen. Now I need to know the label's width in order to position it, but the width depends on the amount of text, so i use this code:

double bannerWidth = banner.getWidth();

Which forces me into using a double if I want to be accurate.

But the problem is that I'm trying to use a condition that compares the label's horizontal position (currentX) to the left edge of the screen (LEFT_EDGE), minus the width of the label (bannerWidth). In other words when the label is off the screen, it should go back to its starting position.

I assume that means that any variables I use to track the label's position (in this case currentX), or constants that I use to check equality (LEFT_EDGE), have to be doubles as well?

My difficulty is that I iterate currentX. But currentX--; won't work because doubles don't iterate as I'd expect.

So casting becomes an option..... but if I cast to an integer I effectively lose width on the label. And that is magnified each loop, resulting in the label's starting position moving further and further to the left.

View Replies View Related

How To Write A Computer Based Testing Program Using Files

Jan 8, 2015

I'm supposed to write a computer based testing program using files. I have started writing however, I am stuck. I am to prompt the user to enter the file name 'test.dat" and if something different is entered then a error message should be displayed. Also the file will create an input stream for the data using the file. I am to have the user enter other information about an employee and then write the record to the file.

The program should be created so when the user enters "quit" the loop is terminated and the file is closed. I'm not asking for code. I was just giving a brief synopsis of the project. Where I am stuck is I wrote the first part of the program that creates the file; however when I enter a wrong file name the exception error message does not display. The code is below:

import java.io.*;
import java.lang.*;
import java.util.*;
public class Project5Write
{
private Formatter x;
public void openFile(){

[Code]...

View Replies View Related

Analyzing And Fixing Failed Cases In Stress Testing

Apr 29, 2014

There are few modules in our application whose performance degrade with time when 50-100 simultaneous users are working on them at a given instance.The memory allocations are taken care of to allow maximum data.My issue to where to start finding the root cause.

I am currenlty using JvisualVM for profiling and finding memory leaks..Do i need to Simualte 50-100 virtual users and start finding the memory leaks with JvisualVM or working with a single user would do ?

View Replies View Related

Rational Number Class - Java Client Code For Testing

Mar 7, 2014

We are making a Rational Number class. After that we must create client code to test it out. The instructions-

•Create 3 instances of RationalNumber. Remember every time you say “new” you are creating an instance.
oOne of them should use the default constructor
oOne of them should use the constructor with one parameter
oOne of them should use the concstructor with two parameters.
•Print out the int and double value of each Rational Number
•Print out the sum (as a double) of all the numbers.
•Print out the sum (as an int) of all the numbers.

My rational number class :

public class RationalNumber{
private int numerator;
private int denominator;
public RationalNumber()
{
numerator =1;
denominator = 4;

[Code] .....

View Replies View Related

Using Switch Statement Inside If Statement

Nov 18, 2014

So I want to make a simple Java that ask the user to pick a powers and it has two options.If the user picks magic then execute the first if statement then ask the user again which type of magic the user wants.I can't make it work it keeps printing the else statement. Why is that?

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

[code]....

View Replies View Related

Boolean Cannot Be Converted To Int

Jun 11, 2014

I do not see a boolean trying to be converted into an int. Could my decompiler have caused this?

this.redStones[this.tabIDHover == i].drawSprite(6 + paddingX + ((client.clientSize >= 1) ? 2 : 0) - ((this.longTabs && client.clientSize >= 1) ? 240 : 0) + x, 261 + paddingY + ((this.longTabs && client.clientSize >= 1) ? 37 : 0) - ((client.clientSize == 0) ? 261 : 0));
this.redStones[this.tabIDHover == i + 8].drawSprite(6 + paddingX + ((client.clientSize >= 1) ? 2 : 0) + x, 298 + paddingY);

View Replies View Related

Cannot Convert Int To Boolean

Dec 11, 2014

I am making a program which accepts two user inputs one being a letter either upper or lower case and the other being a number. the out come should be some thing like this:

G
GG
GGG
GGGG
GGGGG

This is assuming the user inputted 'G' and '5'.

here is the code i have so far:

package week10;
import java.util.Scanner;
public class integer {
public static void main(String args[]) {
Scanner user_input = new Scanner( System.in );

[Code] ....

The problem i am having is that i cant get the number that is inputted to be accepted as a variable to be used for the program.

View Replies View Related

Odd And Even Numbers With Boolean?

Apr 14, 2014

how to determine if an integer is even or odd by using a boolean method. I think I have the method right, but it's calling the method into the main that has got me stumped.

import java.util.Scanner; 
public class Odd_Even {
public static void main(String[] args) {
//Scanner, variables
Scanner input = new Scanner(System.in);
int number;
 
[code]....

View Replies View Related

Boolean Return Missing

Sep 25, 2014

So I'm trying to check if the new coordinates vs original coordinates are diagonal and 1 line further, and if there is a piece there(getNum()) if it's 2 lines further, so I'm trying to return a boolean value then.

so if it's the first if, it returns true, if it's the 2nd it returns true, then I say else for all other scenario's, and return false there, but my compiler says my method is missing a return statement.

public boolean check(int[] d) {
int x,y;
x = loc[0][0];
y = loc[0][1]; 
int sx = d[0];
int sy = d[1];

[Code] .....

Edit: used a local boolean and returned that after my if's.,

View Replies View Related

Converting Boolean Into String

Feb 15, 2014

I have this project due and its asking that i print out what type of triangle it is when the user inputs 3 sides. I have most of it done and working, but it pops up different windows instead of using one window for everything. The assignment says it needs all the final info to be in one window. The boolean is coming from another method. I'm unsure how to get it into a string (Or if that's what i have to do). The method must return a boolean true/false.

import javax.swing.*; 
public class Triangle { 
public static void main(String[] args) {
int side1 = getSides();
int side2 = getSides();
int side3 = getSides();
 
[Code] ....

View Replies View Related







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