Results 1 to 10 of 10
Thread: Need Help Coding Project
- 04-27-2008, 06:17 AM #1
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
Need Help Coding Project
Hey guys,
I hope you can help me with this, I've been trying to get it right all day..
First I'll post my project so far and then my questions under, thank you.
here is what I've been trying to do (some of which is done):Java Code:import javax.swing.JOptionPane; public class kmbproject1 { public static void main(String[] args) { String userName = ""; String userPhone = ""; String userFilm; String userPrints = ""; int userExposures = 1; userName = JOptionPane.showInputDialog(null, "Please enter your name"); if (userName.equals("")) {JOptionPane.showMessageDialog(null, "Exiting the program!"); System.exit(0);} userPhone = JOptionPane.showInputDialog(null, "Please enter your phone number"); if (userPhone.equals("")) {JOptionPane.showMessageDialog(null, "Exiting the program!"); System.exit(0);} userFilm = JOptionPane.showInputDialog(null, "How many rolls of film will we be developing for you?"); userPrints = JOptionPane.showInputDialog(null, "How many 4 x 6 prints would you like to have made out of each film?"); } }
Display an error message and close the program if:
a. the name of the customer is not blank
b. the phone number of the customer is not blank and doesnt exceed 10 characters
c. the number of rolls is between 1 and 100
d. the number of exposures is 1
e. the number of prints can only be (1,2,8,10,,25,30,50)
So far, with help thank God, I was able to do (a) and the not blank part of (b)
But I cant seem to do c right now because I cant do an if statement like:
if (userFilm.length < 10) because i get a cannot convert from string to int error.
If you have the answer please show me the coding examples, im getting answers sometimes which I try and do not work, if I dont understand I will post to try and understand them further and I will also reply if they plain dont work. I really appreciate all help, thank you!
- 04-27-2008, 06:23 AM #2
What do you mean number of rolls?
Last edited by sukatoa; 04-27-2008 at 06:26 AM.
freedom exists in the world of ideas
- 04-27-2008, 07:15 AM #3
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
Rolls of film,
its a project for my java class to have the user input some information and calculate some things and display it back.
- 04-27-2008, 07:36 AM #4
What about the userFilm?
What should be the value to be stored on it?
Can you post more detailed info about your goal below?
String userFilm;
String userPrints = "";
int userExposures = 1;Last edited by sukatoa; 04-27-2008 at 07:40 AM.
freedom exists in the world of ideas
- 04-27-2008, 07:46 PM #5
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
String userFilm;
String userPrints = "";
int userExposures = 1;
Oops, String userFilm;
is an error, I will correct it as
String userFilm = ""; to initialize it
The reason I have those strings initialized is because you'll see below that they are used in the JOptionPane to receive feedback on their use and once I receive that I will add more code God willing about calculations according to how many rolls of film and prints were entered.
- 04-27-2008, 07:54 PM #6
At userFirm, it asks how many? so it should be an int not a string....
use Integer.parseInt(String s) to convert it.
and also the userPrints.freedom exists in the world of ideas
- 04-27-2008, 08:02 PM #7
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
Where do I put the line of code you are mentioning?
If I initialize it as
int userFilm = 0
then the JOptionPane line of code displays an error about int and string?
Thanks
- 04-27-2008, 09:53 PM #8
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
So far I have :
When I try to run the code I get:Java Code:public static void main(String[] args) { String userName = ""; String userPhone = ""; String userFilm = ""; int film = Integer.parseInt(userFilm); String userPrints = ""; final int USER_EXPOSURES = 1; userName = JOptionPane.showInputDialog(null, "Please enter your name"); if (userName.equals("")) {JOptionPane.showMessageDialog(null, "Exiting the program!"); System.exit(0);} userPhone = JOptionPane.showInputDialog(null, "Please enter your phone number"); if (userPhone.equals("")) {JOptionPane.showMessageDialog(null, "Exiting the program!"); System.exit(0);} if(userPhone.length() > 10) {JOptionPane.showMessageDialog(null, "Exiting the program!"); System.exit(0);} userFilm = JOptionPane.showInputDialog(null, "How many rolls of film will we be developing for you?"); if (film > 100) {JOptionPane.showMessageDialog(null, "Exiting the program!"); System.exit(0);} if (film < 1) {JOptionPane.showMessageDialog(null, "Exiting the program!"); System.exit(0);} userPrints = JOptionPane.showInputDialog(null, "How many 4 x 6 prints would you like to have made out of each film?"); } }
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unk nown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at kmbproject1.kmbproject1.main(kmbproject1.java:26)
- 04-27-2008, 10:33 PM #9
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
Actually ive finally gotten it after some help,
All I want to know now is,
How can I make an if statement for a group of integers such as:
if (prints != 1,2,8,10,35,50)
I get an error because I can only have one number
- 04-27-2008, 11:31 PM #10
Member
- Join Date
- Apr 2008
- Posts
- 88
- Rep Power
- 0
Similar Threads
-
Coding an FTP server in java
By Zucheto in forum NetworkingReplies: 3Last Post: 06-22-2008, 04:24 AM -
Help On Coding problem
By mandrake446 in forum New To JavaReplies: 3Last Post: 12-08-2007, 07:01 AM -
Error in my coding
By one198 in forum New To JavaReplies: 2Last Post: 10-13-2007, 05:07 AM -
Problem in my coding
By one198 in forum New To JavaReplies: 9Last Post: 08-09-2007, 10:07 AM -
Help with program coding
By cachi in forum AWT / SwingReplies: 1Last Post: 07-31-2007, 07:16 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks