Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 3 FirstFirst 123 LastLast
Results 26 to 50 of 57

Thread: java programming assignment help

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: java programming assignment help

    how will i test the length
    Look at the API doc for the String class. It has a method that will give you the length.

    how will it confirm that the input is not a character?
    Define what you mean by a character? The only data that can be entered easily via the keyboard is a character. Look at the Character class's methods if you want to know what kind of character was read into the program.

    The API doc: Java Platform SE 7
    If you don't understand my answer, don't ignore it, ask a question.

  2. #27
    Member
    Join Date
    Oct 2012
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java programming assignment help

    what is the API doc??

  3. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: java programming assignment help

    It's at this link:
    The API doc: Java Platform SE 7
    If you don't understand my answer, don't ignore it, ask a question.

  4. #29
    Member
    Join Date
    Oct 2012
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java programming assignment help

    how to fix this??
    when i input 81
    my program output the squareroot is 2.828 something...
    /**
    * @(#)activity2.java
    *
    *
    * @author
    * @version 1.00 2012/10/1
    */
     
    import javax.swing.*;
    public class aa
    {
    public static void main(String[]args)
    {
    String input="";
    char inputs;
    double x;
    int loop=0;
    do{
    input=JOptionPane.showInputDialog(null,"Enter A Character: ");
    inputs=input.charAt(0);
    if(Character.getType(inputs) == Character.CURRENCY_SYMBOL)
    {
    JOptionPane.showMessageDialog(null,"The character is a symbol.");
    }
    else if(Character.isDigit(inputs))
    {
    int num= inputs -'0';
    JOptionPane.showMessageDialog(null,"The character is a Digit.");
    JOptionPane.showMessageDialog(null,"The square root of "+inputs+" is "+Math.sqrt(num));
    }
    else if (input.length()>1)
    {
    JOptionPane.showMessageDialog(null,"Invalid Input. Input a character only.");
    }
    else if(Character.isLetter(inputs))
    {
    if(Character.isLowerCase(inputs))
    {
    JOptionPane.showMessageDialog(null,"Lowercase");
    }
    if(Character.isUpperCase(inputs))
    {
    JOptionPane.showMessageDialog(null,"UpperCase");
    }
    }
    else
    {
    JOptionPane.showMessageDialog(null,"The character is a symbol.");
    }
    loop = JOptionPane.showConfirmDialog(null,"Try Again?[Y/N]","repeat",JOptionPane.YES_NO_OPTION);
    if(loop == JOptionPane.NO_OPTION)
    {
    JOptionPane.showMessageDialog(null,"Thank You For Using The Program.");
    }
    }while(loop == JOptionPane.YES_OPTION);
    }
    }
    Last edited by darking123; October 3rd, 2012 at 09:06 AM.

  5. #30
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: java programming assignment help

    Please edit you post and change the quote tags to code tags.
    Also please format the code. All statements should NOT start in the first column.

    What is the square root of 8?

    Your code only works with one character
    Last edited by Norm; October 3rd, 2012 at 08:17 AM.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #31
    Member
    Join Date
    Oct 2012
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java programming assignment help

    how will i make it accept 2 or more values which will not affect the other codes but only the square root of a 2 digit or more number

  7. #32
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: java programming assignment help

    The code reads the full input from the user into a variable and then takes the first character.
    If you want all of the input, use it instead of just using the first character.


    Please edit your code and format it. All statements should not start in the first column.
    See: Code Conventions for the Java Programming Language: 4. Indentation
    If you don't understand my answer, don't ignore it, ask a question.

  8. #33
    Member
    Join Date
    Oct 2012
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java programming assignment help

    already fixed it another new problem
    if i input String10 my program output "Invalid Input. Input a character only" but if i input 10String my program will output "The Character is a Digit" the if i press ok an error will come out.....

    the problem is...if i Input 10String my problem will output "Invalid Input. Input a character only" because it is not a char
    please help me my program due tom

    /**
    * @(#)activity2.java
    *
    *
    * @author
    * @version 1.00 2012/10/1
    */
     
    import javax.swing.*;
    public class Activity2
    {
    public static void main(String[]args)
    {
    String input="";
    char inputs;
    double x;
    int loop=0;
    do{
    input=JOptionPane.showInputDialog(null,"Enter A Character: ");
    inputs=input.charAt(0);
    if(Character.getType(inputs) == Character.CURRENCY_SYMBOL)
    {
    JOptionPane.showMessageDialog(null,"The character is a symbol.");
    }
    else if(Character.isDigit(inputs))
    {
    JOptionPane.showMessageDialog(null,"The character is a Digit.");
    JOptionPane.showMessageDialog(null,"The square root of "+input+" is "+Math.sqrt(Double.parseDouble(input)));
    }
    else if (input.length()>1)
    {
    JOptionPane.showMessageDialog(null,"Invalid Input. Input a character only.");
    }
    else if(Character.isLetter(inputs))
    {
    if(Character.isLowerCase(inputs))
    {
    JOptionPane.showMessageDialog(null,"Lowercase");
    }
    if(Character.isUpperCase(inputs))
    {
    JOptionPane.showMessageDialog(null,"UpperCase");
    }
    }
    else
    {
    JOptionPane.showMessageDialog(null,"The character is a symbol.");
    }
    loop = JOptionPane.showConfirmDialog(null,"Try Again?[Y/N]","repeat",JOptionPane.YES_NO_OPTION);
    if(loop == JOptionPane.NO_OPTION)
    {
    JOptionPane.showMessageDialog(null,"Thank You For Using The Program.");
    }
    }while(loop == JOptionPane.YES_OPTION);
    }
    }

  9. #34
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: java programming assignment help

    If you want the program to give an error message for input of more than one character, have it test the length of the String it reads in from the user.


    Please edit your code and format it. All statements should not start in the first column.
    See: Code Conventions for the Java Programming Language: 4. Indentation
    If you don't understand my answer, don't ignore it, ask a question.

  10. #35
    Member
    Join Date
    Oct 2012
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java programming assignment help

    i already have this one "else if (input.length()>1)
    {
    JOptionPane.showMessageDialog(null,"Invalid Input. Input a character only.");"

    help please

  11. #36
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: java programming assignment help

    There are more than one if statement. Which one do you want done first?
    With if/else if statements, the first one that is true is the only one that will be executed. The following ones will be skipped.

    Your code is hard to read and understand.
    Please edit your code and format it. All statements should not start in the first column.
    See: Code Conventions for the Java Programming Language: 4. Indentation
    If you don't understand my answer, don't ignore it, ask a question.

  12. #37
    Member
    Join Date
    Oct 2012
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java programming assignment help

    already edited the if but still i have the error



    /**
    * @(#)activity2.java
    *
    *
    * @author
    * @version 1.00 2012/10/1
    */
     
    import javax.swing.*;
    public class activity2
    {
    public static void main(String[]args)
    {
    String input="";
    char inputs;
    double x;
    int loop=0;
    do{
    input=JOptionPane.showInputDialog(null,"Enter A Character: ");
    inputs=input.charAt(0);
    if(Character.getType(inputs) == Character.CURRENCY_SYMBOL)
    {
    JOptionPane.showMessageDialog(null,"The character is a symbol.");
    }
    else if(Character.isDigit(inputs))
    {
    JOptionPane.showMessageDialog(null,"The character is a Digit.");
    JOptionPane.showMessageDialog(null,"The square root of "+input+" is "+Math.sqrt(Double.parseDouble(input)));
    }
    else if (input.length()>1)
    {
    JOptionPane.showMessageDialog(null,"Invalid Input. Input a character only.");
    }
    else if(Character.isLetter(inputs))
    {
    if(Character.isLowerCase(inputs))
    {
    JOptionPane.showMessageDialog(null,"Lowercase");
    }
    else if(Character.isUpperCase(inputs))
    {
    JOptionPane.showMessageDialog(null,"UpperCase");
    }
    }
    else
    {
    JOptionPane.showMessageDialog(null,"The character is a symbol.");
    }
    loop = JOptionPane.showConfirmDialog(null,"Try Again?[Y/N]","repeat",JOptionPane.YES_NO_OPTION);
    if(loop == JOptionPane.NO_OPTION)
    {
    JOptionPane.showMessageDialog(null,"Thank You For Using The Program.");
    }
    }while(loop == JOptionPane.YES_OPTION);
    }
    }
    Last edited by darking123; October 4th, 2012 at 07:43 AM.

  13. #38
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: java programming assignment help

    Your code is hard to read and understand.
    Please edit your code and format it. All statements should not start in the first column.
    See: Code Conventions for the Java Programming Language: 4. Indentation
    If you don't understand my answer, don't ignore it, ask a question.

  14. #39
    Member
    Join Date
    Oct 2012
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java programming assignment help

    anyone??help please

  15. #40
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: java programming assignment help

    Why won't you fix the posted code to make it easier to read and understand?
    The statements should NOT all start in the first column. Add spaces to indent as per the link that has been posted several times.

    Did you understand what I said in post#36?
    Last edited by Norm; October 4th, 2012 at 08:15 AM.
    If you don't understand my answer, don't ignore it, ask a question.

  16. #41
    Member
    Join Date
    Oct 2012
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java programming assignment help

    help please

    /**
    * @(#)activity2.java
    *
    *
    * @author
    * @version 1.00 2012/10/1
    */
     
    import javax.swing.*;
    public class activity2
    {
    	public static void main(String[]args)
    	{
    	String input="";
    	char inputs;
    	double x;
    	int loop=0;
    	do{
    		input=JOptionPane.showInputDialog(null,"Enter A Character: ");
    		inputs=input.charAt(0);
    	if(Character.getType(inputs) == Character.CURRENCY_SYMBOL)
    	{
    			JOptionPane.showMessageDialog(null,"The character is a symbol.");
    	}
    	else if(Character.isDigit(inputs))
    	{
    			JOptionPane.showMessageDialog(null,"The character is a Digit.");
    			JOptionPane.showMessageDialog(null,"The square root of "+input+" is "+Math.sqrt(Double.parseDouble(input)));
    	}
    	else if (input.length()>1)
    	{
    			JOptionPane.showMessageDialog(null,"Invalid Input. Input a character only.");
    	}
    	else if(Character.isLetter(inputs))
    	{
    		if(Character.isLowerCase(inputs))
    			{
    				JOptionPane.showMessageDialog(null,"Lowercase");
    			}
    	else if(Character.isUpperCase(inputs))
    	{
    			JOptionPane.showMessageDialog(null,"UpperCase");
    	}
    	}
    	else
    	{
    			JOptionPane.showMessageDialog(null,"The character is a symbol.");
    	}
    		loop = JOptionPane.showConfirmDialog(null,"Try Again?[Y/N]","repeat",JOptionPane.YES_NO_OPTION);
    	if(loop == JOptionPane.NO_OPTION)
    	{
    		JOptionPane.showMessageDialog(null,"Thank You For Using The Program.");
    	}
    		}while(loop == JOptionPane.YES_OPTION);
    	}
    }

  17. #42
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: java programming assignment help

    Do you understand what I said in post #36?
    There is more than one if statement. Which one do you want done first?
    With if/else if statements, the first one that is true is the only one that will be executed. The following ones will be skipped.
    Your formatting is still wrong. It should look like this:
    	}
     
    	loop = JOptionPane.showConfirmDialog(null,"Try Again?[Y/N]","repeat",JOptionPane.YES_NO_OPTION);
    	if(loop == JOptionPane.NO_OPTION)
    	{
    		JOptionPane.showMessageDialog(null,"Thank You For Using The Program.");
    	}
       }while(loop == JOptionPane.YES_OPTION);
     } 
    }
    Last edited by Norm; October 4th, 2012 at 09:02 AM.
    If you don't understand my answer, don't ignore it, ask a question.

  18. #43
    Member
    Join Date
    Oct 2012
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java programming assignment help

    can you now just help me to my problem?

  19. #44
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: java programming assignment help

    I thought I did. If what I said in post #36 is not the problem, can you please explain what the problem is? Make a list the the steps you do and the steps the computer does and then explain what is wrong with the computer's responses. For example:
    1) I enter: s
    2) the computer says: lowercase
    3) I enter: 4
    4) the computer says: 2
    5) I enter:this is another
    6) The computer says: lowercase <<<<<< This should be: Invalid input
    If you don't understand my answer, don't ignore it, ask a question.

  20. #45
    Member
    Join Date
    Oct 2012
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java programming assignment help

    oh you dont get what i said awhileago
    the problem is
    1. I enter: 10String
    2. The Computer Says its A Digit then After i press Ok My Program shown an error
    ...the problem to my program is if i enter 10String,,the program should output invalid input because 10String is not a pure number it also has letter on it..
    so what is the solution for it??

    program works fine if i enter String10..and the program will output invalid input

  21. #46
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: java programming assignment help

    program should output invalid input because 10String is not a pure number it also has letter on it..
    Would 1234 be a valid input?

    One way to check if a String contains only numeric digits would be to use the Integer class's parseInt() method inside of a try{}catch block. The parseInt() method will throw an exception if the String it gets is not a valid/pure number.

    Another way to check if a String contains only numeric digits would be to write a loop that gets the characters in the String one at a time and tests each character with the isDigit() method.
    If you don't understand my answer, don't ignore it, ask a question.

  22. #47
    Member
    Join Date
    Oct 2012
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java programming assignment help

    yes 1234 will be a valid input because it contains pure numbers....


    about your solution how to do it??also i am using joption not buffered

  23. #48
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: java programming assignment help

    If you don't understand how to use the try{} catch block use the second way.

    i am using joption not buffered
    I don't understand what that is about.
    If you don't understand my answer, don't ignore it, ask a question.

  24. #49
    Member
    Join Date
    Oct 2012
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java programming assignment help

    i do not know where to start..please guide me

  25. #50
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: java programming assignment help

    Write a small program for testing.
    Define a String with several characters that will be scanned in the loop.

    Define a loop that gets the characters one at a time from the String.
    The loop needs to go around one time for each character in the String.
    If you don't understand my answer, don't ignore it, ask a question.

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. java programming assignment help
    By darking123 in forum Java Theory & Questions
    Replies: 0
    Last Post: October 1st, 2012, 07:26 AM
  2. Help on programming assignment
    By aaronmcohen in forum AWT / Java Swing
    Replies: 0
    Last Post: March 7th, 2012, 07:47 PM
  3. Programming help with java assignment!
    By kami21 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 15th, 2011, 06:37 PM
  4. Programming assignment using inheritance
    By Slypher in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 4th, 2011, 05:42 PM
  5. programming assignment help
    By sdgseed in forum Threads
    Replies: 1
    Last Post: October 20th, 2010, 02:43 PM