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.
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,.
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);
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?
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.
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;
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 ?
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.
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.
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
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??
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.
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?
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):");
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)";
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.
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).
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
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;
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;