Results 1 to 10 of 10
  1. #1
    Bascotie is offline Member
    Join Date
    Apr 2008
    Posts
    88
    Rep Power
    0

    Default 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.

    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?");
    
    	}
    	
    
    }
    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!

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    What do you mean number of rolls?
    Last edited by sukatoa; 04-27-2008 at 07:26 AM.
    freedom exists in the world of ideas

  3. #3
    Bascotie is offline Member
    Join Date
    Apr 2008
    Posts
    88
    Rep Power
    0

    Default

    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.

  4. #4
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    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 08:40 AM.
    freedom exists in the world of ideas

  5. #5
    Bascotie is offline Member
    Join Date
    Apr 2008
    Posts
    88
    Rep Power
    0

    Default

    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.

  6. #6
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    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

  7. #7
    Bascotie is offline Member
    Join Date
    Apr 2008
    Posts
    88
    Rep Power
    0

    Default

    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

  8. #8
    Bascotie is offline Member
    Join Date
    Apr 2008
    Posts
    88
    Rep Power
    0

    Default

    So far I have :

    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?");
    
    	}
    	
    
    }
    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)

  9. #9
    Bascotie is offline Member
    Join Date
    Apr 2008
    Posts
    88
    Rep Power
    0

    Default

    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

  10. #10
    Bascotie is offline Member
    Join Date
    Apr 2008
    Posts
    88
    Rep Power
    0

    Default

    Thanks everyone who helped, i think im almost finished with program!

Similar Threads

  1. Coding an FTP server in java
    By Zucheto in forum Networking
    Replies: 3
    Last Post: 06-22-2008, 05:24 AM
  2. Help On Coding problem
    By mandrake446 in forum New To Java
    Replies: 3
    Last Post: 12-08-2007, 08:01 AM
  3. Error in my coding
    By one198 in forum New To Java
    Replies: 2
    Last Post: 10-13-2007, 06:07 AM
  4. Problem in my coding
    By one198 in forum New To Java
    Replies: 9
    Last Post: 08-09-2007, 11:07 AM
  5. Help with program coding
    By cachi in forum AWT / Swing
    Replies: 1
    Last Post: 07-31-2007, 08:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •