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 1 of 3 123 LastLast
Results 1 to 25 of 57

Thread: java programming assignment help

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

    Default java programming assignment help

    how to code this one??

    1. Create a program that accepts character input then determine whether it is letter, number or a symbol. If it is a letter, display whether it is Uppercase or lowercase letter. If it is a digit, display its square root. (Note: Use Character and JOptionPane class)
    Use the following predefined methods:
    isLetter( )
    isDigit( )
    charAt( )
    length( )
    sqrt( )
    showConfirmDialog( )
    SAMPLE OUTPUT 1:
    Enter a character: 9
    The character is a digit.
    The square root of 9 is 3.0
    Try again?[Y/N]
    SAMPLE OUTPUT 2:
    Enter a character: *
    The character is a symbol.
    Try again?[Y/N]
    SAMPLE OUTPUT 3:
    Enter a character: A
    The character is an Uppercase letter.
    Try again?[Y/N]
    SAMPLE OUTPUT 4:
    Enter a character: string10
    Invalid Input. Input a character only.
    Try again?[Y/N]


  2. #2
    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 have any specific questions about the program? Show some effort and you'll get some help.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: java programming assignment help

    if i can code even if a little of it i will do it but i really do not know how to start coding it...because we didnt study it..it is been an activity already

  4. #4
    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

    Start by making a list the the steps the program needs to do.
    Then start with the first step, code it, compile it, test it. When it works, move to the next item in the list.
    Look at the Scanner class's methods for reading input from a user.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: java programming assignment help

    help about getting the square root of i enter 9 the answer will be 7.54983443527075 and it should be 3
    /**
     * @(#)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;
        	 input=JOptionPane.showInputDialog(null,"Enter a character :");
        	 inputs= input.charAt(0);
        	 if(inputs>='a'&&inputs<='z'){ 
            System.out.println("Lowercase");
        	 }
        	 else if(inputs>='A'&&inputs<='Z'){	 
            System.out.println("Uppercase");
        	 }
        	 else if(inputs>='A'&&inputs<='Z'){	 
            System.out.println("Uppercase");
        	 } 
        	 else if(Character.isDigit(inputs)){
        	 System.out.println("The character is a digit.");
        	 System.out.println("The square root of " + inputs + " is " + Math.sqrt(inputs));
        	 }
     
     
     
     
     
        	 }
     
        }
    Last edited by darking123; October 1st, 2012 at 05:04 PM.

  6. #6
    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 use code tags to wrap code, not quote tags.

    You are confusing char and int values. The char '1' does not have the int value of 1.
    Do this to see a char's int value: System.out.println((int)'3' + " vs " + 3);

    char is a primitive that can be used in arithmetic forumlas: int x = 'b' - 'a';
    Given a char, you need to convert it to an int. One quick way to convert a char digit to an int is to subtract '0' from it. '9' - '0' = 9
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: java programming assignment help

    may i ask if how will i include it to my code?

  8. #8
    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 include it to my code?
    Include what? Please be more specific.

    Please edit your post and change quote to code tags.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    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 add the -0 to my program... or in short the one that you are telling to me sir

  10. #10
    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 uses a char like '9' as if it were an int 9. You need to convert the char digit to an int value.
    One way to do that is to subtract '0' from the char: '9' - '0' = 9

    Did you try this: System.out.println((int)'9' + " vs " + 9);
    What was the first number that printed? Was the sqrt() of that number the same as you got:
    square root of i enter 9 the answer will be 7.54983443527075
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: java programming assignment help

    ok i got it thanks.

    but another problem why my program doesn't output The character is a symbol. if i input * but if i input $ it will output The character is a symbol.
    import javax.swing.*;
    public class aa {
     
        public static void main(String args[]) {
     
        	String input;
        	char inputs;
        	double x;
        	 input=JOptionPane.showInputDialog(null,"Enter a character :");
        	 inputs= input.charAt(0);
        	 if (Character.getType(inputs) == Character.LOWERCASE_LETTER){ 
            System.out.println("Lowercase");
        	 }
        	 else if(Character.getType(inputs) == Character.UPPERCASE_LETTER){	 
            System.out.println("Uppercase");
        	 }
        	 else if(Character.getType(inputs) == Character.CURRENCY_SYMBOL){
        	 System.out.println("The character is a symbol.");
        	 }
        	 else if(Character.isDigit(inputs)){
    		int num = inputs - '0';
        	 System.out.println("The character is a digit.");
        	 System.out.println("The square root of " + inputs + " is " + Math.sqrt(num));
        	 }
     
     
     
     
     
        	 }
     
        }

  12. #12
    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

    Can you copy and post here the content of the console that shows your input and the programs output?

    Also Look at the API doc for the Character class. Is '*' defined as a symbol?
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: java programming assignment help

    if i input *.. my jcreator will not post anything instead process complete

  14. #14
    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

    For a test, change this line and execute the program and see what happens:
    input= "*"; // JOptionPane.showInputDialog(null,"Enter a character :");

    if i input *.. my jcreator will not post anything
    At the end of the chain of if/else if you should add an else statement that prints a message about none of the if statements were true for the value of input. The code ignores and does nothing if none of the if statements were true.
    Last edited by Norm; October 2nd, 2012 at 08:02 AM.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: java programming assignment help

    i tried your idea sir but still my program still doesnt recognize * as a symbol

  16. #16
    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

    What is printed out in the else statement you added to the end of the if/else if chain?

    What is the value of the '*'? Does your code test for it?
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: java programming assignment help

    i already add else then if i input * it will output The character is a symbol. but is there other way that when you input * and it will output The character is a symbol. with using else?? instead else if or if only?

  18. #18
    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 "character is a symbol" message to print for an "*" you need to add a test to the if statement that controls the printing of that message.
     else if(Character.getType(inputs) == Character.CURRENCY_SYMBOL || <*** ADD TEST HERE**>){
        	 System.out.println("The character is a symbol.");
        	 }
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: java programming assignment help

    thank you again for the help..
    but what are the different keys that can be called sa symbol in java??
    also how can i insert the isLetter() for my code below(what will i change to make it isLetter()

    import javax.swing.*;
    public class aa {
     
        public static void main(String args[]) {
     
        	String input= "*";
        	char inputs;
        	double x;
        	int loop=0;
        	while (loop == JOptionPane.YES_OPTION) {
        	 input=JOptionPane.showInputDialog(null,"Enter a character :");
        	 inputs= input.charAt(0);
        	 if (Character.getType(inputs) == Character.LOWERCASE_LETTER){ 
            JOptionPane.showMessageDialog(null,"Lowercase");
        	 }
        	 else if(Character.getType(inputs) == Character.UPPERCASE_LETTER){	 
            JOptionPane.showMessageDialog(null,"Uppercase");
        	 }
        	 else if(Character.getType(inputs) == Character.CURRENCY_SYMBOL || inputs == '*' ){
        	 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));
        	 }
        	 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");
    		}
            }
     
     
     
     
     
        	 }
     
        }

  20. #20
    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

    but what are the different keys that can be called a symbol in java??
    Read the API doc for the Character class.
    If you have questions about one symbol's type, print out the value returned by the getType() methd and look it up in the table of definitions referred to by any of the static values defined in the Character class.

    how can i insert the isLetter() for my code
    Where and when do you want to test if a character is a letter? insert the test there.


    Your code still does not have an ending else statement after the chain of if/else if???
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: java programming assignment help

    i want it to lest it from my code in the LowerCase And UpperCase part to my program..

    about this
    SAMPLE OUTPUT :
    Enter a character: string10
    Invalid Input. Input a character only.

    how will i do this will i use lenght()?? help again please thank you
    import javax.swing.*;
    public class aa {
     
        public static void main(String args[]) {
     
        	String input= "*";
        	char inputs;
        	double x;
        	int loop=0;
        	while (loop == JOptionPane.YES_OPTION) {
        	 input=JOptionPane.showInputDialog(null,"Enter a character :");
        	 inputs= input.charAt(0);
        	 if (Character.getType(inputs) == Character.LOWERCASE_LETTER){ 
            JOptionPane.showMessageDialog(null,"Lowercase");
        	 }
        	 else if(Character.getType(inputs) == Character.UPPERCASE_LETTER){	 
            JOptionPane.showMessageDialog(null,"Uppercase");
        	 }
        	 else if(Character.getType(inputs) == Character.CURRENCY_SYMBOL || inputs == '*' ){
        	 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{
        	 	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");
    		}
            }
     
     
     
     
     
        	 }
     
        }

  22. #22
    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 do this
    Please explain what it is that you want to do.

    Please edit your code and format it so it is easier to read. Code within {}s should be indented at least 3 spaces to show logic levels.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: java programming assignment help

    if i will input string10 or any not char size value the program prints out Invalid Input. Input a character only.

    also about the isLetter i want it to be Place In The LowerCase And UpperCase

    import javax.swing.*;
    public class aa 
    {
     
        public static void main(String args[]) 
        	{
     
        	String input= "*";
        	char inputs;
        	double x;
        	int loop=0;
        	while (loop == JOptionPane.YES_OPTION) 
        		{
        	 input=JOptionPane.showInputDialog(null,"Enter a character :");
        	 inputs= input.charAt(0);
        	 if (Character.getType(inputs) == Character.LOWERCASE_LETTER)
        	 { 
                 JOptionPane.showMessageDialog(null,"Lowercase");
        	 }
        	 else if(Character.getType(inputs) == Character.UPPERCASE_LETTER)
        	 {	 
                 JOptionPane.showMessageDialog(null,"Uppercase");
        	 }
        	 else if(Character.getType(inputs) == Character.CURRENCY_SYMBOL || inputs == '*' )
        	 {
        	     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
        	 {
        	 	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");
    		 }
                }
        	}
     
    }

  24. #24
    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

    You can test if the user input a single letter by testing the length of the String.

    also about the isLetter i want it to be Place In The LowerCase And UpperCase
    I'm not sure what you are asking here. Do you want to replace the tests for case with a test for letter?
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: java programming assignment help

    how will i test the length??and how will it confirm that the input is not a character?


    about the isLetter because i want that isLetter can be found to my source code is there a place where i can place it?/

Page 1 of 3 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