alligarbage
asked on
Java GUI program- VERY URGENT
Here is my problem:
Write a complete interactive Java GUI program that requests two numbers from the user. The first number is the row dimension and the second number is the column dimension. Print to the user a rectangle of stars based on the input. The program must do the following:
A. Print a rectangle of stars.
B. Error check for bad input: alphabetic characters or negative numbers. Do not end the program but remind the user of the proper input.
C. Allow the user to use the program until the user decides to terminate the program.
List any functionality that is NOT in your completed program.
Here is the code I have so far:
import javax.swing.JOptionPane;
public class RectangleOfStars
{
public static void main(String[] args)
{
int rows, columns;
String rowsStr, columnsStr, outputStr;
rowsStr = JOptionPane.showInputDialo g("Enter the number of rows: ");
rows = Integer.parseInt(rowsStr);
columnsStr = JOptionPane.showInputDialo g("Enter the of columns: ");
columns = Integer.parseInt(columnsSt r);
while(true) // endless loop.
{
try
{
rowsStr = JOptionPane.showInputDialo g("Enter the number of rows: ");
rows = Integer.parseInt(rowsStr);
break;
}
catch(NumberFormatExceptio n)
{
// tell them the input was wrong
System.out.println("Please enter a positive integer.");
}
JOptionPane.showMessageDia log(null, outputStr, "Rectangle of Stars", JOptionPane.INFORMATION_ME SSAGE);
System.exit(0);
//Print output
for(int i = 0; i < rows; ++i)
{
for(int j = 0; j < columns; ++j)
{
// print a star
System.out.print("*"); // System.out is a default PrintWriter given by JAVA
}
// go to the next line
System.out.println();
}
}
}
}
Here are the error messages I'm getting, so I can't even compile it. Please help:
RectangleOfStars.java:25: <identifier> expected
catch(NumberFormatExceptio n)
^
RectangleOfStars.java:30: ')' expected
JOptionPane.showMessageDia log(null, outputStr, "Rectangle of Stars", JOptionPane.INFORMATION_ME SSAGE);
Thank you for your help
Write a complete interactive Java GUI program that requests two numbers from the user. The first number is the row dimension and the second number is the column dimension. Print to the user a rectangle of stars based on the input. The program must do the following:
A. Print a rectangle of stars.
B. Error check for bad input: alphabetic characters or negative numbers. Do not end the program but remind the user of the proper input.
C. Allow the user to use the program until the user decides to terminate the program.
List any functionality that is NOT in your completed program.
Here is the code I have so far:
import javax.swing.JOptionPane;
public class RectangleOfStars
{
public static void main(String[] args)
{
int rows, columns;
String rowsStr, columnsStr, outputStr;
rowsStr = JOptionPane.showInputDialo
rows = Integer.parseInt(rowsStr);
columnsStr = JOptionPane.showInputDialo
columns = Integer.parseInt(columnsSt
while(true) // endless loop.
{
try
{
rowsStr = JOptionPane.showInputDialo
rows = Integer.parseInt(rowsStr);
break;
}
catch(NumberFormatExceptio
{
// tell them the input was wrong
System.out.println("Please
}
JOptionPane.showMessageDia
System.exit(0);
//Print output
for(int i = 0; i < rows; ++i)
{
for(int j = 0; j < columns; ++j)
{
// print a star
System.out.print("*"); // System.out is a default PrintWriter given by JAVA
}
// go to the next line
System.out.println();
}
}
}
}
Here are the error messages I'm getting, so I can't even compile it. Please help:
RectangleOfStars.java:25: <identifier> expected
catch(NumberFormatExceptio
^
RectangleOfStars.java:30: ')' expected
JOptionPane.showMessageDia
Thank you for your help
Why do you ask the same question again?
Okay,
I just saw it as well.
sciuriware is right. Why do you ask the same question again? I believe that this is the continuation of https://www.experts-exchange.com/questions/22043462/Java-GUI-program-that-requests-two-numbers-VERY-URGENT.html
I just saw it as well.
sciuriware is right. Why do you ask the same question again? I believe that this is the continuation of https://www.experts-exchange.com/questions/22043462/Java-GUI-program-that-requests-two-numbers-VERY-URGENT.html
... and I fear that alligarbage doesn't understand any of our answers ...
;JOOP!
;JOOP!
ASKER
I asked the same question because I needed an answer asap and I thought that posting a new question would generate an answer sooner.
Here is my updated code. Still one error message.
import javax.swing.JOptionPane;
public class RectangleOfStars
{
public static void main(String[] args)
{
int rows, columns;
String rowsStr, columnsStr, outputStr;
rowsStr = JOptionPane.showInputDialo g("Enter the number of rows: ");
rows = Integer.parseInt(rowsStr);
columnsStr = JOptionPane.showInputDialo g("Enter the of columns: ");
columns = Integer.parseInt(columnsSt r);
while(true) // endless loop.
{
try
{
rowsStr = JOptionPane.showInputDialo g("Enter the number of rows: ");
rows = Integer.parseInt(rowsStr);
break;
}
catch(NumberFormatExceptio n nfe)
{
// tell them the input was wrong
System.out.println("Please enter a positive integer.");
}
JOptionPane.showMessageDia log(null, outputStr, "Rectangle of Stars", JOptionPane.INFORMATION_ME SSAGE);
System.exit(0);
//Print output
for(int i = 0; i < rows; ++i)
{
for(int j = 0; j < columns; ++j)
{
// print a star
System.out.print("*"); // System.out is a default PrintWriter given by JAVA
}
// go to the next line
System.out.println();
}
}
}
}
Error message:
RectangleOfStars.java:30: variable outputStr might not have been initialized
JOptionPane.showMessageDia log(null, outputStr, "Rectangle of Stars", JOptionPane.INFORMATION_ME SSAGE);
^
1 error
Here is my updated code. Still one error message.
import javax.swing.JOptionPane;
public class RectangleOfStars
{
public static void main(String[] args)
{
int rows, columns;
String rowsStr, columnsStr, outputStr;
rowsStr = JOptionPane.showInputDialo
rows = Integer.parseInt(rowsStr);
columnsStr = JOptionPane.showInputDialo
columns = Integer.parseInt(columnsSt
while(true) // endless loop.
{
try
{
rowsStr = JOptionPane.showInputDialo
rows = Integer.parseInt(rowsStr);
break;
}
catch(NumberFormatExceptio
{
// tell them the input was wrong
System.out.println("Please
}
JOptionPane.showMessageDia
System.exit(0);
//Print output
for(int i = 0; i < rows; ++i)
{
for(int j = 0; j < columns; ++j)
{
// print a star
System.out.print("*"); // System.out is a default PrintWriter given by JAVA
}
// go to the next line
System.out.println();
}
}
}
}
Error message:
RectangleOfStars.java:30: variable outputStr might not have been initialized
JOptionPane.showMessageDia
^
1 error
Delete those 2 lines. Do you want to stop your program in the middle?
;JOOP!
;JOOP!
And please learn the basics of programming first!
What use is it to complete this program without understanding it?
And: WE MAY NOT WRITE THIS PROGRAM FOR YOU!!!!
even if we wanted to do so,
besides, would you learn anything from that?
;JOOP!
What use is it to complete this program without understanding it?
And: WE MAY NOT WRITE THIS PROGRAM FOR YOU!!!!
even if we wanted to do so,
besides, would you learn anything from that?
;JOOP!
ASKER
At this point, I'm not trying to learn as much as I'm trying to get it turned in. I have had a lot of family emergencies this term and haven't had much time to study this. I realize that you cannot just give me the answer, but I just need as much help as I can get.
Thank you
I have deleted those two lines and asked another question in the other post for this.
Thank you
I have deleted those two lines and asked another question in the other post for this.
Do you now understand what each line does?
If so tell me what is the use of lines 10, 11, 12, 13 & 14.
;JOOP!
If so tell me what is the use of lines 10, 11, 12, 13 & 14.
;JOOP!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Are you referring to these lines:
rowsStr = JOptionPane.showInputDialo g("Enter the number of rows: ");
rows = Integer.parseInt(rowsStr);
columnsStr = JOptionPane.showInputDialo g("Enter the of columns: ");
columns = Integer.parseInt(columnsSt r);
If so, I'm not entirely sure why these lines are here, if I am asking them again in the loop. I am thinking that these should probably be deleted and just asked in the loop.
I'm not suprised I've made no progress since yesterday. I have gotten 2 hours of sleep and I'm stressing cause everything is due tomorrow.
rowsStr = JOptionPane.showInputDialo
rows = Integer.parseInt(rowsStr);
columnsStr = JOptionPane.showInputDialo
columns = Integer.parseInt(columnsSt
If so, I'm not entirely sure why these lines are here, if I am asking them again in the loop. I am thinking that these should probably be deleted and just asked in the loop.
I'm not suprised I've made no progress since yesterday. I have gotten 2 hours of sleep and I'm stressing cause everything is due tomorrow.
Yes
alligarbage, this is no use!
You can't learn to swim by just diving from a bridge into a wide river.
It took us years.
;JOOP!
You can't learn to swim by just diving from a bridge into a wide river.
It took us years.
;JOOP!
ASKER
Make each question worth 250 points.
.. and say "please".
ASKER
please and thank you :)
sorry if I was rude before.
I'm stressed, but that's no excuse.
sorry if I was rude before.
I'm stressed, but that's no excuse.
You are stressed because you try to do something you can't do:
you must learn to program from the basics up, and NOT start
with a program you don't understand and in a language you don't master.
My advice:
it's like making a long jump:
if you jump without a run, you don't loose time but you will fall short,
if you turn and make a run first, you'll loose time but you'll make it.
So loose some time you invest to be good in the end.
;JOOP!
you must learn to program from the basics up, and NOT start
with a program you don't understand and in a language you don't master.
My advice:
it's like making a long jump:
if you jump without a run, you don't loose time but you will fall short,
if you turn and make a run first, you'll loose time but you'll make it.
So loose some time you invest to be good in the end.
;JOOP!
ASKER
I understand that, but I can't learn Java in two days and my assignments are due tonight.
I was just trying to get everything done.
Hopefully next time I won't have any family emergencies throughout the term that deters me from studying.
I was just trying to get everything done.
Hopefully next time I won't have any family emergencies throughout the term that deters me from studying.
I wish I could help you but now I am extremely busy with my works.
Apologized but can't help you now.
Apologized but can't help you now.
ASKER
Yes, I REALIZE that NO ONE will do the work for me. lol
You should have the identifier as
catch(NumberFormatExceptio