Joe Fett

Greenhorn
+ Follow
since Jul 16, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Joe Fett

Originally posted by Ulf Dittmer:
What's with all the UnsupportedOperationExceptions? Does the code run if you remove those? If so, what does it do, and where are you stuck making progress?



As I was going through and resolving the issues, I let NetBeans resolve them so I could get it to compile. The result was all that unsupported nonsense which just added to my misery.

I'm stuck at getting the full JPanel or JFrame to show. As it runs now only the title bar of it displays.
16 years ago
I had to find a program that demos a bouncing ball in JPanel and I did that. The next evolution is taking that program and making it add a new ball with each mouse click. I have attempted a few things but now I am totally lost with this project. I was able to get the code to compile but not run.

Anyone have a helpful idea how I can unfunk this code and get it going the right direction? As always, the help is appreciated!



16 years ago
Since that question was answered, I'd like to know something else. If I want to write to more than one text file, is the following code a good or not-so-good way to begin?

I guess the better question is should I make a new java class file for each text file I need to write to?

16 years ago

Originally posted by Ulf Dittmer:
No, you'd need to create two Formatter objects. But I assume that the files will contain different content anyway, so it's not like using just one Formatter makes things much easier, right?



That makes perfect sense and is what I suspected.

And yes, both text files will have slightly different formats.

Thanks for the help.
16 years ago
Is it possible to create multiple text files using the class Formatter?

Here is the instructions for this program: "Write a program to create data for testing the (file-matching accounts receivable) program. Use sample account data from blah blah blah. Run the program to create the files trans.txt and oldmast.txt, to be used by your file-matching program."

I've seen in the text where I can create one text file using the class Formatter but can it create more than one within it?

Thanks for the help.
16 years ago

Originally posted by Piet Verdriet:
Getting there!

No, here you need the divide operator, not the modulo operator.



Piet, thanks again. I was able to get rid of the last bit of problems in the factorize method. It compiled and ran fine. I feel like an elephant stopped sitting on my back now. Thanks so much for your assistance! Breaking this program into several methods really made the difference for me. Great idea on your part.

Cheers to ya!
16 years ago

Originally posted by Piet Verdriet:
You are almost there. I suggest you re-factor your code a bit by adding some additional methods. It will enhance the readability of your code.
Here's how you can do it:

I made little changes to the actual code, I only added a couple of extra methods. The logic is still the same as in your last post.
In addition, I added some pseudo code in your factorize(...) method. Try to finish it now.

Good luck!

[ July 18, 2008: Message edited by: Piet Verdriet ]



I really appreciate your help Piet, breaking it into different methods makes it much saner. I'm still having an issue with the set portion though. I used your pseudo code to get it started but I think I'm making some rookie mistakes and its giving me incompatibility errors.

16 years ago
It turns out the prime number testing portion does not even work well so I tried a few things and got mixed results at best.

Anyone have an ideas how I can get my brain back in the game?

<blockquote>code:
<pre name="code" class="core">// Program finds the prime factors of a number using sets.
import java.util.Scanner;
import java.util.HashSet;

public class PrimeFactors
{
public PrimeFactors()
{
boolean prime = true;
Scanner scanner = new Scanner( System.in ); // create scanner
System.out.println( "Please enter a number, -1 to terminate:" );
int inputNumber = scanner.nextInt(); // get number


// process user input numbers
while ( inputNumber != -1 )
{
HashSet< Integer > factorSet = new HashSet< Integer >();
factorize( inputNumber, factorSet );

// Now print

int root = (int) Math.sqrt( inputNumber );

for (int i=2; i <= root; i++)
{
if (inputNumber % i == 0)
{
// System.out.println(inputNumber + " is not prime");
prime = false;
continue;
}
}

if (prime)
System.out.println(inputNumber + " is prime");
//If a prime, print the number is a prime

else
System.out.println(inputNumber + " is not prime");

//If not a prime, print the prime factors for the number

// Now get the next number
System.out.println("Please enter a number, -1 to terminate:" );
inputNumber = scanner.nextInt(); // get number

} // end while

} // end constructor PrimeFactors

// find prime factors
public boolean factorize( int inputNumber, HashSet< Integer > set )
{

return false;
} // end method factorize

public static void main( String args[] )
{
new PrimeFactors();
} // end main
} // end class PrimeFactors
</pre>
</blockquote>
16 years ago
This program is supposed to do two things:
1) determine if a user input number is prime and if it is, the output will say as much (this works okay)
2) if it is not prime, it should display the number and its prime factors using a set(I'm lost)

Here is the code and pseudocode I have for finding the prime factors. I'm just not understanding what I need to do for getting the prime factors. I'm not looking for free code because I want to understand this as learning Java has been frustrating for me. Any nudge of assistance may turn the light on for me so I'd appreciate anything you folks can help me with.

Thanks!

<blockquote>code:
<pre name="code" class="core"> // Program finds the prime factors of a number using sets.
import java.util.Scanner;
import java.util.HashSet;

public class PrimeFactors
{
public PrimeFactors()
{
Scanner scanner = new Scanner( System.in ); // create scanner
System.out.println( "Please enter a number, -1 to terminate:" );
int inputNumber = scanner.nextInt(); // get number
boolean prime = true;

// process user input numbers
while ( inputNumber != -1 )
{
HashSet< Integer > factorSet = new HashSet< Integer >();
factorize( inputNumber, factorSet );

// Now print

for (int i=2; i < inputNumber/2; i++)
{
if (inputNumber%i==0)
prime = false;
}
if (prime)
System.out.println(inputNumber + " is prime");
//If a prime, print the number is a prime

else
System.out.println(inputNumber + " is not prime and its factors are:\n");

//If not a prime, print the prime factors for the number



// Now get the next number
System.out.println("Please enter a number, -1 to terminate:" );
inputNumber = scanner.nextInt(); // get number

} // end while
} // end constructor PrimeFactors

// find prime factors
public boolean factorize( int inputNumber, HashSet< Integer > set )
{


return false;
} // end method factorize

public static void main( String args[] )
{
new PrimeFactors();
} // end main
} // end class PrimeFactors
</pre>
</blockquote>
16 years ago