Results 1 to 14 of 14
Like Tree3Likes
  • 3 Post By JosAH

Thread: From a flow chart to a code

  1. #1
    0smile0 is offline Member
    Join Date
    Oct 2014
    Posts
    8
    Rep Power
    0

    Unhappy From a flow chart to a code

    Hello everyone ..
    may someone please help me to solve this question my quiz is tomorrow and I need the answer ?


  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: From a flow chart to a code

    Show us what you have tried yourself and what part(s) you're having trouble with.

    kind regards,

    Jos

    ps. begging us to do your homework for you is a guarantee for not getting any help here.
    Build a wall around Donald Trump; I'll pay for it.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: From a flow chart to a code

    Quote Originally Posted by 0smile0 View Post
    Hello everyone ..
    may someone please help me to solve this question my quiz is tomorrow and I need the answer ?
    What happens if you don't have the answer?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: From a flow chart to a code

    Well, you haven't asked a question. And we certainly won't provide the code
    because that's not the way this forum works. But just start at the top and follow
    the logic. Diamonds are decision blocks, rectangles are process blocks, and parallelograms
    are I/O operations. Of course, that only really helps if you need to write one.

    For Position type == B, if the statement is true, the follow the true path, if the
    statement is false follow the false path.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    0smile0 is offline Member
    Join Date
    Oct 2014
    Posts
    8
    Rep Power
    0

    Default Re: From a flow chart to a code

    My question is after this statament if (WH>70) I don't how to start the next step which is position type==A

  6. #6
    0smile0 is offline Member
    Join Date
    Oct 2014
    Posts
    8
    Rep Power
    0

    Default Re: From a flow chart to a code

    I want to know what is wrong with my code !
    Java Code:
    import java.util.Scanner;
    public class Tests {
        public static void main(String args[]) {
        
    double WH; //WH=working hours
    char type ; //type=position type
    
    Scanner read = new Scanner(System.in);
    
    
    System.out.print("Enter working hours: ");
    System.out.print("Enter position type: ");
    WH = read.nextDouble();
    type=read.nextchar();
    
    if (WH<5)
    System.out.print("Salary="((WH*100));
    else 
    System.out.print("Salary="((WH*110));
    if (WH>70){
    if(positionType=='A')
    System.out.print("Overtime="(WH-70)*50);
    else if (positionType=='B')
    System.out.print("Overtime="((WH-70)*60);
    else
    System.out.print("Overtime="(WH-70)*70);
    }
    else
    System.out.print("Salary="(WH*110));
    
    
    
    
    
    
    }
    }

  7. #7
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: From a flow chart to a code

    Well, what error messages are being reported by the compiler and at what lines?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  8. #8
    0smile0 is offline Member
    Join Date
    Oct 2014
    Posts
    8
    Rep Power
    0

    Default Re: From a flow chart to a code

    Quote Originally Posted by jim829 View Post
    Well, what error messages are being reported by the compiler and at what lines?

    Regards,
    Jim

    SwitchDemo.java:17: error: ')' expected
    System.out.print("Salary="((WH*100));
    ^
    SwitchDemo.java:17: error: not a statement
    System.out.print("Salary="((WH*100));
    ^
    SwitchDemo.java:17: error: ';' expected
    System.out.print("Salary="((WH*100));
    ^
    SwitchDemo.java:19: error: ')' expected
    System.out.print("Salary="((WH*110));
    ^
    SwitchDemo.java:18: error: 'else' without 'if'
    else
    ^
    SwitchDemo.java:19: error: not a statement
    System.out.print("Salary="((WH*110));
    ^
    SwitchDemo.java:19: error: ';' expected
    System.out.print("Salary="((WH*110));
    ^
    SwitchDemo.java:22: error: ')' expected
    System.out.print("Overtime="(WH-70)*50);
    ^
    SwitchDemo.java:22: error: not a statement
    System.out.print("Overtime="(WH-70)*50);
    ^
    SwitchDemo.java:22: error: ';' expected
    System.out.print("Overtime="(WH-70)*50);
    ^
    SwitchDemo.java:24: error: ')' expected
    System.out.print("Overtime="((WH-70)*60);
    ^
    SwitchDemo.java:23: error: 'else' without 'if'
    else if (positionType=='B')
    ^
    SwitchDemo.java:24: error: not a statement
    System.out.print("Overtime="((WH-70)*60);
    ^
    SwitchDemo.java:24: error: ';' expected
    System.out.print("Overtime="((WH-70)*60);
    ^
    SwitchDemo.java:26: error: ')' expected
    System.out.print("Overtime="(WH-70)*70);
    ^
    SwitchDemo.java:25: error: 'else' without 'if'
    else
    ^
    SwitchDemo.java:26: error: not a statement
    System.out.print("Overtime="(WH-70)*70);
    ^
    SwitchDemo.java:26: error: ';' expected
    System.out.print("Overtime="(WH-70)*70);
    ^
    SwitchDemo.java:29: error: ')' expected
    System.out.print("Salary="(WH*110));
    ^
    SwitchDemo.java:29: error: not a statement
    System.out.print("Salary="(WH*110));
    ^
    SwitchDemo.java:29: error: ';' expected
    System.out.print("Salary="(WH*110));
    ^
    21 errors

  9. #9
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: From a flow chart to a code

    You need to ensure your ()'s are properly matched. And your syntax for a print statement is incorrect. Each argument
    is considered a string and must be treated as such. Here is a hint. System.out print and println statements only take
    a single argument.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  10. #10
    Thammer is offline Member
    Join Date
    Sep 2014
    Posts
    47
    Rep Power
    0

    Default Re: From a flow chart to a code

    Hey, I have been programming for just a few weeks, I find it very interesting and fun.
    I thought this looked like a fun challange for me, so I gave it a go. I have tried to put the flow-chart into code.

    The problem I have is that I dont know how to make the user promt a letter for Job type, so I have used int 1 and int 2 instead for the A and B job type.
    Could anyone help me with this problem, so the user can put in A or B like it says in the flowchart.

    When I use a scanner, does the variable need to be the same class? i.e. is it possible to get the user to both input a int and a string? if so how?

    I have posted my code below, I appreciate all feedback.

    [ spoonfeeding (bad) code removed ]
    Last edited by JosAH; 10-18-2014 at 06:23 PM.

  11. #11
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: From a flow chart to a code

    Quote Originally Posted by Thammer View Post
    Could anyone help me with this problem, so the user can put in A or B like it says in the flowchart.
    When I use a scanner, does the variable need to be the same class? i.e. is it possible to get the user to both input a int and a string? if so how?
    I have posted my code below, I appreciate all feedback.
    First, don't hijack someone else's thread. You can start your own if you wish. However, what you are also doing
    is spoonfeeding a homework or possible take home test solution to a student. That will not help them learn.
    You have a chance to correct this and remove your code asap before a moderator does.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: From a flow chart to a code

    Quote Originally Posted by jim829 View Post
    You have a chance to correct this and remove your code asap before a moderator does.
    Consider it done.

    kind regards,

    Jos
    jim829, DarrylBurke and SurfMan like this.
    Build a wall around Donald Trump; I'll pay for it.

  13. #13
    Thammer is offline Member
    Join Date
    Sep 2014
    Posts
    47
    Rep Power
    0

    Default Re: From a flow chart to a code

    Oh okey, no problem, wont happen again :)

    I just tried to join the disscusion. I can create a new thread, I am learning alot from you guys on java-forum!

  14. #14
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: From a flow chart to a code

    Quote Originally Posted by Thammer View Post
    Oh okey, no problem, wont happen again :)

    I just tried to join the disscusion. I can create a new thread, I am learning alot from you guys on java-forum!
    If you select a forum, say 'New To Java', you'll see a button near the top left of the page, labelled '+ Post New Thread'; doesn't it work for you?

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Replies: 2
    Last Post: 05-27-2013, 05:34 PM
  2. Replies: 6
    Last Post: 05-15-2013, 09:30 PM
  3. [ASK]Java Flow Chart to source code
    By potatosaladz in forum New To Java
    Replies: 0
    Last Post: 12-28-2010, 06:11 AM
  4. Replies: 2
    Last Post: 02-17-2009, 03:20 PM

Posting Permissions

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