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){
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).
I am currently making a double linked list class in my compsci class. i was absent for a few days and i need to make an add method for the class. when i go to compile test code i made i get a null pointer error on line 36. This is the node class i wrote and the double linked list class i wrote.
node class
public class Node{ // Two references and Data Node prev; Node next; String data; public Node(){ prev = null; next = null;
[Code] ....
This is the class i need working with ( in the doublelinkedlist class)
public class Test { public static void main(String[] args) { Car c = new Car(); c.setInf("toyota", "red"); System.out.println("name: "+ c.brand + " colour: " + c.colour);
[code]....
Why do I get the result brand null, colour null? I know what null means but what am I missing here?
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?
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 ;
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.
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.
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();
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
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.
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?
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.
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(){
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 ?
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;
I'm having some trouble with a code I am writing for class. I had an 2 errors like this before this one and fixed it by changing int avgRe, avgMiles =0; to double. Now I am getting this error and am stuck on what I need to change. Here is the code:
import java.io.*; import java.util.*; import java.text.*; public class Reimbursement_3_09 { static Toolkit tools = new Toolkit(); public static void main (String [] args) throws Exception {
[Code] ....
This is my error:
[code=Java] Reimbursement_3_09.java:33: error: incompatible types: possible lossy conversion from double to int summary (outFile, totalAmount, ctrMiles, ctrMilesgt0, avgRe, avgMiles); ^ Some messages have been simplified; recompile with -Xdiags:verbose to get full output 1 error
My question is how do I configure this so that when / if I need to change the discount value, it automatically adjusts the % discount off of the Full or Compact?
All I can get to work is simply hardcoding it and assigning the discount value, i'm probably just messing up the syntax.
So I'm trying to add two numbers using a stack class I made myself. I have a main class with a main method in which I use three stacks on holds one number one holds the other and then I sum one digit at a time keeping in midn that there may be a carry before putting the result on a third stack.
My problem is I'm getting a null pointer error when it should be putting an integer into the top of my stack which is index 0, I've checked my code and can't see why it would be doing this.This is my main method in my main class
import java.util.*; import java.io.*; public class CS25driver { public static void main(String[]args) throws FileNotFoundException {
[code]...
my input file looks like a single line of input stating the problem followed by two lines of input which need to be summed.this is the error I'm getting
Exception in thread "main" java.lang.NullPointerException at StackClass.push(StackClass.java:38) at CS25driver.main(CS25driver.java:55)
public static javax.swing.JPanel pane; I initialize it in a method (Well, Netbeans' GUI builder does. :P) pane = new javax.swing.JPanel(){ @Override public void paint(Graphics g){ g.setColor(Color.BLACK); g.drawArc(8, 6, 15, 15, 0, 90); /* This works. The panel and frame are displayed, the arc is drawn, &c. */ } };
it works and all; the arc is drawn.I want to draw on it dynamically by instantiating its Graphics (I call the "public Graphics getGraphics()" method.). This has worked for me before, taking a JPanel's Graphics and drawing with it through a different method than public void paint(Graphics g); But when I do, it comes up with a NullPointerException. WAIT! Don't go rambling on about initializing the variable because I've gotten past that NPE newbie's blockade.public static void render(Something s) { /*This is in a different file altogether. pane is public, static so I can access it from here. That's not the problem.*/
Upon further investigation: Exception in thread "main" java.lang.NullPointerException at physics.Renderer.render(Renderer.java:30) <-- This line is "JPanel jp = Frame.pane;" at physics.Renderer.renderall(Renderer.java:24) <--This line calls public static void render(Something s) at physics.Updater.update(Updater.java:47) <--Renderer is just a tool used by the Updater. Sounds like a game loop, right? at physics.Physics.main(Physics.java:31) <-- The game loop.
it says that Line 30, making jp and pointing it to pane itself is the problem.
Conclusion: -The JPanel in the JFrame is created, initialized and overrides a parent method. -The JPanel is not initialized, meaning that it is null. There is obviously a problem.
I am working on a project which manages an airport's airplanes and flights based on user input. The method printFlights() - lines 133-134 - is returning null and I can't figure out why. The method is supposed to print information about each flight. The logic is identical to the printPlanes() method which is working successfully.