Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-27-2008, 08:17 AM
Member
 
Join Date: Apr 2008
Posts: 77
Bascotie is on a distinguished road
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.

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?"); } }
here is what I've been trying to do (some of which is done):

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!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-27-2008, 08:23 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
What do you mean number of rolls?
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by sukatoa : 04-27-2008 at 08:26 AM.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-27-2008, 09:15 AM
Member
 
Join Date: Apr 2008
Posts: 77
Bascotie is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-27-2008, 09:36 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
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;
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by sukatoa : 04-27-2008 at 09:40 AM.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 04-27-2008, 09:46 PM
Member
 
Join Date: Apr 2008
Posts: 77
Bascotie is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 04-27-2008, 09:54 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
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.
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 04-27-2008, 10:02 PM
Member
 
Join Date: Apr 2008
Posts: 77
Bascotie is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 04-27-2008, 11:53 PM
Member
 
Join Date: Apr 2008
Posts: 77
Bascotie is on a distinguished road
So far I have :

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?"); } }
When I try to run the code I get:

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)
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 04-28-2008, 12:33 AM
Member
 
Join Date: Apr 2008
Posts: 77
Bascotie is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 04-28-2008, 01:31 AM
Member
 
Join Date: Apr 2008
Posts: 77
Bascotie is on a distinguished road
Thanks everyone who helped, i think im almost finished with program!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Coding an FTP server in java Zucheto Networking 3 06-22-2008 06:24 AM
Help On Coding problem mandrake446 New To Java 3 12-08-2007 09:01 AM
Error in my coding one198 New To Java 2 10-13-2007 07:07 AM
Problem in my coding one198 New To Java 9 08-09-2007 12:07 PM
Help with program coding cachi AWT / Swing 1 07-31-2007 09:16 AM


All times are GMT +3. The time now is 07:15 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org