Test Quality Of Number

Oct 12, 2014

Write a Java program that reads a positive, non-zero integer as input and checks if the integer is deficient, perfect, or abundant.A positive, non-zero integer, N, is said to be perfect if the sum of its positive proper divisors (i.e., the positive integers, other than N itself, that divide N exactly) is equal to the number itself. If this sum is less than N, the number is said to be deficient. If the sum is greater than N, the number is said to be abundant.

For example, the number 6 is perfect, since 6 = 1 + 2 + 3, the number 8 is deficient, since 8 > 1 + 2 + 4, while the number 12 is abundant, since 12 < 1 + 2 + 3 + 4 + 6.

Sample Output:

Input N: 5

5 is deficient.

Input N: 6

6 is perfect.

Input N: 18

18 is abundant.

View Replies


ADVERTISEMENT

Code Quality Plugins In Eclipse?

Jul 10, 2013

I write lot of java code everyday. Sometime in hurry I forget to close the resources (connection,file,etc,) in JAVA6 and this causes memory leak issues. I am looking for an eclipse plugin which can complain for these minor mistakes. Also I am looking for some more eclipse plugins which can improve my source code quality like naming conventions, code redundancy, complexity, too long code outside methods, etc,.

View Replies View Related

Image Print In Poor Quality With Jagged Edges

Apr 14, 2014

I'm trying to print (to the printer) a small image 265x35 px and it is printed in very poor quality with jagged edges. When I'm printing it from any other program (e.g. Word, mspaint, etc) it is printed clearly.

Also, the image is printed bigger than it's normal size (approximately 25%). But, I'm not doing any scale in my code. I did scaled it down to the right size, but the quality still remained very poor and jadged.

The image is a transparent PNG file. I tried with a BMP too, but I got the same results.

I'm using

Graphics g;
g.drawImage(headerLogo, x, y, headerLogo.getWidth(), headerLogo.getHeight(), imageObserver);

View Replies View Related

Running A Test With A File?

Jun 11, 2014

I just wrote a java program with eclipse that has to read many-many inputs from the user. I want to test it, but I really don't want to type it everytime again and again...

Can I just write all inputs in a text file and let eclipse read this file so instead of typing it again and again, Eclipse reads every line whenever it waits for a user input?

View Replies View Related

Test That A Function Has No Any Exceptions

Aug 3, 2014

I want to test that a function has no any exceptions.In C++ and Google Test Framework (GTest) it will look like this:

ASSERT_NO_THROW({
actual = divide(a, b);
});

How will it look in Java?

View Replies View Related

Test If A Name Is Variable With Regex

Jun 11, 2014

I would like to test whether the first word in a line is is a valid var name (e.g sequence of letters, digits and "_", it may not start with a digit, if "_" is the first char it must be followed by a letter). I tried this simple code:

String namePattern = "_[a-zA-Z0-9]+";
String text = "__c";
Pattern pattern = Pattern.compile(namePattern);
Matcher matcher = pattern.matcher(text);
"__c" is an illegal var name.

But it returns the string "_c", where it is supposed to return an empty matcher.

where am I wrong here?

View Replies View Related

How To Test Code On A Tablet

Jun 12, 2014

One: is it possible to test code offline with one device, preferably an android tablet?

Two: if, not, is it possible, online with just an android tablet?

Three:if not, is it possible using the internet on my smart phone and with no internet on my tablet - and no, I can't use my smartphone as a hotspot?

I want to test code I wrote on droid edit. An app I purchased for writing code. I'm using Java.

View Replies View Related

Spring Integration Test

Nov 18, 2014

In my integration test, I tried to use resttemplate to send a Get request to a dummy server created by MockMvcBuilders. However I got an error:I/O error on GET request for `"http://localhost:8080/test"`:Connection refused:(In the function testAccess(), url is `"http://localhost:8080/test"`). My code is as below:

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@IntegrationTest("server.port=8080")
public class MyTest {
private MockMvc mockMvc = null;

[code]....

View Replies View Related

How To Test If Class / Object Is Immutable

Jul 2, 2014

I have make the immutable class as below, Now my question is how I can test if my this class/object is immutable

package com.learning;
import java.util.*;
import java.util.Map.Entry;
public final class ImmutableTest {
private final int id;
private final String name;
private final HashMap<String, String> hm ;

[Code]...

How I can Test If it is immutable class without looking ?

View Replies View Related

Recursive Function To Test All Combinations?

May 17, 2014

I am not sure how to add all the possibilities of elements in an array and find the greatest sum. I want to do this recursively. I don't need any code. How I would do it.

View Replies View Related

Compact Test For Any Of 4 Values Being Null

Apr 7, 2014

Any compact if statement or any type of test for checking if atleast ONE out of 4 integers is null. So 1 of all, 2 of all, 3 of all, or all of them being null will give a specific result ELSE do something else.

View Replies View Related

Generate Set Of Test Scores Between 0-100 Inconclusive

Dec 8, 2014

Design and write a Java program that will generate a set of test scores between 0-100, inconclusive. The exact umber of scores is determined either randomly or by the user input. There should be a minimum of 5 test scores. The program calculates the average of all test score in this data set. Then it asks the user how many scores are to be dropped and drops that number of low scores. The average is recalculated.

Output of this program:

The original test scores printed in rows of 10 scores
The average before low scores are dropped
The number of low scores to be dropped
The list of low scores dropped
The new average

View Replies View Related

Test Correct Name Format With For Loop

Sep 25, 2014

I have to test user input for the correct format of a name in the format of firstName lastName (i.e. Bob Smith). These are my for loops to test each of these four exceptions: No blanks between names firstName and lastName, Non-alphabetic characters in names, Less than two characters in first name, Less than two characters in last name.

import java.util.*;
public class Driver {
private String name;
public static void main(String[] args) {
new Driver();

[Code] ......

How to search for more than two characters in the first and last name??

View Replies View Related

How To Test For Array Length Equal To Zero

Mar 15, 2015

I am working on an assignment covering exception handling and am stuck on part of the assignment. How can you test for array length = 0?

When I try something like: if (array.length == 0) on a null array, naturally I get a NullPointerException. I would try something like if (array != null) but both array length of 0 and null array are supposed to throw different expressions.

View Replies View Related

How To Test Object Boolean Method

Feb 18, 2014

I have been writing test scripts for my class but I'm stuck on this method. how do i test for an object?

@Override
public boolean equals(Object obj) {
if (obj.getClass() != Fraction.class)
return false;
return (this.toString().equals(obj.toString()));
}

View Replies View Related

Simple Code To Test Palindrome

Jul 25, 2014

I have a simple code to test palindrome. I have the word "civic" and I got this code:

public String isPalindrome(String word) {
StringBuilder builder = new StringBuilder(word);
String reversed = builder.reverse().toString();
String s = new String();
if(reversed.equalsIgnoreCase(word)){
s = "Word " + parameters + " evitative is a palindrome!";
}
return s;
}

to my surprise, the if() condition is false even though the word is a palindrome.

View Replies View Related

Test Equality Of Two Dates In Different Formats

Jul 7, 2014

I need to find out if two dates are equal or not. I have two dates coming from UI and from DB. From UI I am getting as Sun Jun 15 00:00:00 CDT 2014 from DB I am getting as 2014-06-15 00:00:00.0. Data type for both fields are java.util.Date but when I do uiDate.equals(dbDate) it return false. So how can I test these dates to fins out they are equal or not?

View Replies View Related

Input String And Test Whether Or Not It Is Palindrome

Feb 6, 2015

I have to write a program that inputs a string and tests whether or not it is a palindrome. This worked fine, and now I want to make it so I continually enter strings until I tell the program to stop.

The code below compiles just fine, but it doesn't do what I want. Why it doesn't work how I think it should work? (Typing in STOP does not make the program stop.)

Here is the code

import javax.swing.JOptionPane;
public class PalTest {
public static void main(String[] args){
String S="pony";
while(S!="STOP"){
S=JOptionPane.showInputDialog("Enter a string (STOP to terminate):");

[Code] ....

View Replies View Related

Setting Up A Test For Combination Method

Nov 18, 2014

I'm having trouble setting up a test for my combination method.Here's the method (It basically finds the most amount of characters that both substrings share and combines the two using the number of shared characters as a breaking point):

public static String combination(String str1, String str2, int overlap) {
assert str1 != null : "Violation of: str1 is not null";
assert str2 != null : "Violation of: str2 is not null";
assert 0 <= overlap
&& overlap <= str1.length()
&& overlap <= str2.length()
&& str1.regionMatches(str1.length() - overlap, str2, 0, overlap) : ""
+ "Violation of: OVERLAPS(str1, str2, overlap)";

[code]....

View Replies View Related

Create A Large Test Array

Mar 2, 2015

In my programming class we need to create a large test array of Longs to iteratively sum/reverse the array and recursively sum/reverse the array.creating the array and where to go from there.

View Replies View Related

Why Does Removal Of Boolean Test Result In Different Answers

Mar 15, 2014

I'm trying to find all of the prime factors for a given number. The following code achieves this:

private static ArrayList<Long> findPrimesOf(long number) {
ArrayList<Long> primes = new ArrayList<>();
long highestDivisor = (long)sqrt(number);
for (long divisor = 2; divisor <= highestDivisor; divisor++) {
if (number % divisor == 0) {
boolean isPrime = true;
for (long i = 2L; i < divisor; i++) {
if (divisor % i == 0) {
isPrime = false;
break;

[code]....

However, if I remove the boolean test isPrime, as below, I get additional numbers after the highest prime factor.

private static ArrayList<Long> findPrimesOf(long number) {
ArrayList<Long> primes = new ArrayList<>();
long highestDivisor = (long)sqrt(number);
for (long divisor = 2; divisor <= highestDivisor; divisor++) {
if (number % divisor == 0) {
for (long i = 2L; i < divisor; i++) {
if (divisor % i == 0) {
break;

[code]....

I can't work out why this should be. From my understanding, the divisor only gets added to the list of primes if the loop doesn't break (which, with the boolean test would be true anyway).

View Replies View Related

Binary Tree Java Test Class

Mar 24, 2014

So, managed to get my Binary Search Tree to work properly:

package SystemandDesign.BinaryTree;
 import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
import java.io.ObjectInputStream;
import java.util.Scanner;
 
[Code] ....

No matter how many times I keep rewritting the testInsert method I get a chock full of errors.

View Replies View Related

How To Test Default Constructor In Different Class In Java

Nov 5, 2014

How do you test a default constructor in one class and then test it in a different class? This is the code for the Person class which has the default constructor. I'm not sure in the PersonTester class how to access this default constructor and how to test it - what I have so far for the second class is also below.

class Person {
// Data Members
private String name; // The name of this person
private int age; // The age of this person
private char gender; // The gender of this person

[code]...

View Replies View Related

Recording And Printing From Large Test Array?

Mar 22, 2015

I have a program that works, but I would like to know an easier way to record and print from a large array.

Here is what I have

package pa2;
import java.io.IOException;
public class PA2Delegate {
//long[] array = new long[100000];
int arraySize = 100000;
int iterations = 9999;
Long[] array;

[code].....

View Replies View Related

EJB / EE :: How To Unit Test MDBs And Session Beans

Apr 18, 2014

What are the best practices for unit testing MDBs and session beans ?How can they be tested without running an application server ?

View Replies View Related

Find Weighted Average Of Four Test Scores

Apr 17, 2015

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;

[Code] .....

View Replies View Related







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