Hey guys I have a java programming problem I need solved, I wish to go
step by step to see where I have made my mistakes. All of the output
messages need to be in Joption frames.
If I left anything out please let me know!
Objective: This exercise provides the student with additional
experience with the control structures, if and for (or while), in
context of formulating an algorithm to calculate prime numbers. The
student also is asked to use a Boolean variable. We also gain
experience by creating applets.
Assignment: (PrimeApplet.java)
Based on the partial program provided, carry out the following
instructions in order to complete the program.
1.) Declare two integer variables: value and divisor. Declare a
Boolean variable, value_is_prime. Declare a character variable,
response. Declare three String variables of your choosing to capture
user input (2 places) and format the results. Call your results
String, result, and you may name the other two variables.
2.) Initialize value to 0, divisor to 2, response to ?y?, and
value_is_prime to true.
3.) Formulate the condition for the while loop to iterate as long as
response = ?y?. Also make sure you add the close brace for the loop
(the open brace is already coded).
4.) Prompt the user to ?Please enter a value to be checked as prime:?
and convert String to the integer variable, value/
5.) Assign value_is_prime the value true.
6.) Formulate a loop which iterates over the variable divisor into the
variable value. If an even division is found, assign the value false
to the variable, value_is_prime, and inform the user which value was
evenly divided by adding the value to the result String. (see sample
output).
7.) After the loop, if the Boolean variable, value_is_prime is true,
output: ?Your number is prime!?, otherwise output: ?Sorry, your number
is not prime.?
8.) Formulate the sign-off message (JOPTION PANE Thanks for using the
prime program)
9.) Create a html file (have that pretty well covered though)
Import javax.swing.*;
public class PrimeApplet extends JApplet
{
Public void init()
{ //declare your variables here
While( ) // Formulate condition #3 and determine where the while
block should end
{
// prompt user for input and convert the string to integer, value #4
//Assign the Boolean variable the value, true #5
// Formulate loop #6
//Formulate output to inform user if the number is prime or not #7
//show your results:
JOptionPane.showMessageDialog( null, result );
Result = ??; // reinitialize result String
Input = JOptionPane.showInputDialog(
?Would you like to check another number? (y/n) ?);
Response = input.charAt(0);
//Formulate Sign-off dialog box #8
} //end init
} //end class |