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.

Results 1 to 2 of 2

Thread: Intro to java hw assignment

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    20
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Intro to java hw assignment

    Just kinda looking to brainstorm with people or get some good tips (looking to learn too not just post here for someone to do my hw). Remember I'm literally like only 2 weeks into java, we are just learning about if, else statements and putting them to use.Anyway, here's my hw assignment:

    Main topics: User input
    Basic String Methods
    Boolean Expressions
    if & if - else Statements

    Program Specification:

    Write a Java program that does the following:
    Prompts the user to input exactly three characters, which constitude a valid Double literal in Java.
    Gets whatever the user enters and stores it into a String variable, using the the Scanner's .nextLine() method.
    Determines if the input string is indeed a valid Double literal of length three.
    Displays this determination to the user in a reasonable report format.
    Grading:

    Performance Indicator [1] [2] [3]
    Readability and documentation1 2 2
    Use of conditional operators 1 2 2
    Functional requirements 2 3 4
    Efficiency 1 2 2

    Sample run(s):
    Please enter a valid (3 character) double literal : 123

    123 is a valid (3 character) double literal


    Please enter a valid (3 character) double literal : 002

    002 is a valid (3 character) double literal


    Please enter a valid (3 character) double literal : +45

    +45 is a valid (3 character) double literal


    Please enter a valid (3 character) double literal : -45

    -45 is a valid (3 character) double literal


    Please enter a valid (3 character) double literal : 4.5

    4.5 is a valid (3 character) double literal


    Please enter a valid (3 character) double literal : 0.1

    0.1 is a valid (3 character) double literal


    Please enter a valid (3 character) double literal : 45.

    45. is a valid (3 character) double literal


    Please enter a valid (3 character) double literal : +.1

    +.1 is a valid (3 character) double literal


    Please enter a valid (3 character) double literal : -.1

    -.1 is a valid (3 character) double literal
    I know i'll ask the user to enter the double literal my question is how do i go about making sure its valid input. do i just if statements for each individual char spot? like if (input.charAt(0) >= 0 $$ <= 9) then move to charat(1) ect ect cause there is 8 possible combinations they could have in a sense, (+,-) (0-9) (.) if they start with a +,- they're is going to be followed by a int or a '.' , if they start with a '.' then the rest have to be int's obviously cause you can't go .+4 thats not a valid double literal i don't think. Just thinking while i type lol... any pointers are helpful. Am i sort of on the right track?

    PS: if i sound like i don't have a clue to what i'm talking about... its cause i don't.. lol
    Last edited by coke32; October 6th, 2011 at 03:51 PM.


  2. #2

    Default Re: Intro to java hw assignment

    If you are only two weeks into Java, then you should be learning about concepts and not error checking. Did your teacher tell you to assume correct input? You shouldn't be learning about handling Exceptions yet.

    In any case, you can turn a String into a double via Double.parseDouble(stringToken) static method. If you receive no errors and the stringToken.length() == 3, then it is a valid double of length 3 characters.
    Kenneth Walter
    Software Developer
    http://kennywalter.com

Similar Threads

  1. Intro
    By LMO in forum Member Introductions
    Replies: 1
    Last Post: February 4th, 2011, 04:43 AM
  2. Intro
    By ramakanta in forum Member Introductions
    Replies: 2
    Last Post: July 16th, 2010, 08:16 AM
  3. Intro
    By Thandaninkosi Moyo in forum Member Introductions
    Replies: 5
    Last Post: April 30th, 2010, 08:13 AM
  4. Replies: 1
    Last Post: February 22nd, 2010, 08:20 AM
  5. Intro!
    By deceptionminds in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: July 30th, 2009, 05:14 AM

Tags for this Thread