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 5 of 5

Thread: If Else Flow Charts

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

    Default If Else Flow Charts

    I need help using Flow Charts for if else statements...
    I don't understand how to do questions like these:

    Construct a flow chart:
    If A and B have the same sign, print POSITIVE or NEGATIVE according to whether A and B are positive or negative.

    Design the flowchart and write the java statements to execute the following:
    Write an if statement that assigns 0 to x when y is equal to 20.
    Write an if statement that multiples payRate by 1.5 if hours is greater than 40.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: If Else Flow Charts

    What part of this is giving you trouble? Can you draw a flowchart? Can you write the if statement?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

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

    Default Re: If Else Flow Charts

    Quote Originally Posted by KevinWorkman View Post
    What part of this is giving you trouble? Can you draw a flowchart? Can you write the if statement?
    I can write a program.. but I dont understand how to write the questions into flow charts or flow charts to the program..

  4. #4
    Member
    Join Date
    Jun 2012
    Location
    Left Coast, USA
    Posts
    451
    My Mood
    Mellow
    Thanks
    1
    Thanked 97 Times in 88 Posts

    Default Re: If Else Flow Charts

    Quote Originally Posted by bakemono44 View Post
    I can write a program.. but I dont understand how to write the questions into flow charts or flow charts to the program..
    The thing about flow charts is that they are actually harder to keep straight (no crossed lines) if the program logic is sloppy. That's one reason they used to be required for lots of things, like Military/Aerospace projects. Nowadays, structured pseudo-code seems to be the norm.

    I didn't even know they were still teaching flow charts. Or, considering your professed cluelessness, maybe they aren't actually teaching them, just giving assignments.

    Anyhow...

    A language-agnostic (no particular computer language, that is) flow chart derived directly from the specification might look like the following.

    Forgive the butt-ugly ASCII "graphics" for diamond-shaped decision boxes and oval-shaped enter/exit boxes. The parallelogram I/O boxes came out pretty good, I'm thinking.

    I mean, I could have done it in Visio (or Inkscape) and attached a "real" graphics file, but this way was more fun. (I have been told that I have a very peculiar idea of "fun," but keep in mind that this is not my home planet, and I take my "fun" anywhere I can find it.)

    Anyhow...

          _______
         (       )
        (  Enter  )
         (_______)
              |
              |
              |
              V
              /\
            /    \ 
          /        \
        /     A has  \   Yes
       <     +sign    >--------->----------------+
        \      ?     /                           |
          \        /                             |                    
            \    /                               V
              \/                                 |
               | No                              |
               |                                 |
               V                                 V
               /\                                /\
             /    \                            /    \ 
           /        \                        /        \
         /    B has   \ Yes                /    B has   \   Yes
        <     -sign    >------>----+      <     +sign    >------->-------+
         \      ?     /            |       \      ?     /                |
           \        /              |         \        /                  |
             \    /                V           \    /                    V
               \/                  |             \/                      |
               | No                |             | No                    |
               |                   |             |                       |
               |           ________V______       |               ________V______
               |           \              \      |               \              \
               |            \     Print    \     |                \     Print    \
               V             \   "NEGATIVE" \    V                 \   "POSITIVE" \
               |              \______________\   |                  \______________\
               |                   |             |                       |
               |                   V             |                       V
               |                   |             |                       |
               |<----------<-------+             |<----------<-----------+
               |                                 |
               V                                 V
               |                                 |
               |<----------<------------<--------+
               |
               V
               |
               |
            ___V___
           (       )
          (  Exit   )
           (_______)

    Now, this is not tied to any particular computer language, but it does imply that the programmer has to know what it means for a number to have a "plus sign" or a "minus sign." It also assumes, that for purposes of this program, that every number has either a "plus sign" or a "minus sign." That distinction may or may not be important, depending on whether the person who made the assignment accepts zero as as a number with a "plus sign" or not. (Otherwise, the program would have to be modified a little to accommodate zero as having neither a "plus sign" nor a "minus sign.")

    Zero isn't, really a positive number, of course, but people seem to want all integers in the computer to be either positive or negative, and most would simply not accept zero in the 2's complement number system (which is what Java uses) as a negative number, so...

    A reference: Flowchart - Wikipedia

    Bottom line: There are about a million ways to write the program, but if you do the flow chart first and make it neat (no crossed lines), the program implementation in just about any procedural language is (almost) trivial.


    Cheers!

    Z
    Last edited by Zaphod_b; October 3rd, 2012 at 12:58 AM.

  5. The Following User Says Thank You to Zaphod_b For This Useful Post:

    bakemono44 (October 3rd, 2012)

  6. #5
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: If Else Flow Charts

          _______
         (       )
        (  Enter  )
         (_______)
              |
              |
              |
              V
              /\
            /    \ 
          /        \
        /     A has  \   Yes
       <     +sign    >--------->----------------+
        \      ?     /                           |
          \        /                             |                    
            \    /                               V
              \/                                 |
               | No                              |
               |                                 |
               V                                 V
               /\                                /\
             /    \                            /    \ 
           /        \                        /        \
         /    B has   \ Yes                /    B has   \   Yes
        <     -sign    >------>----+      <     +sign    >------->-------+
         \      ?     /            |       \      ?     /                |
           \        /              |         \        /                  |
             \    /                V           \    /                    V
               \/                  |             \/                      |
               | No                |             | No                    |
               |                   |             |                       |
               |           ________V______       |               ________V______
               |           \              \      |               \              \
               |            \     Print    \     |                \     Print    \
               V             \   "NEGATIVE" \    V                 \   "POSITIVE" \
               |              \______________\   |                  \______________\
               |                   |             |                       |
               |                   V             |                       V
               |                   |             |                       |
               |<----------<-------+             |<----------<-----------+
               |                                 |
               V                                 V
               |                                 |
               |<----------<------------<--------+
               |
               V
               |
               |
            ___V___
           (       )
          (  Exit   )
           (_______)
    Z.. You sure put the effort

Similar Threads

  1. Need help with pie charts locations
    By Wise girl in forum Object Oriented Programming
    Replies: 10
    Last Post: June 13th, 2012, 03:28 PM
  2. flow of struts
    By thirupathiswami017 in forum Java Servlet
    Replies: 1
    Last Post: May 24th, 2012, 06:12 PM
  3. stock charts...
    By theChameleon in forum Java Theory & Questions
    Replies: 1
    Last Post: February 24th, 2011, 05:11 AM
  4. Implementation of 3D char and use of Jfreechart
    By tomcat in forum Java Servlet
    Replies: 3
    Last Post: June 8th, 2009, 10:17 AM
  5. Tips or suggestion to learn java
    By tj23 in forum Java Theory & Questions
    Replies: 1
    Last Post: February 2nd, 2009, 06:05 AM