# Thread: From a flow chart to a code

1. Member
Join Date
Oct 2014
Posts
8
Rep Power
0

## From a flow chart to a code

Hello everyone ..

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

3. ## Re: From a flow chart to a code

Originally Posted by 0smile0
Hello everyone ..
What happens if you don't have the answer?

db

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

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

5. Member
Join Date
Oct 2014
Posts
8
Rep Power
0

## 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. Member
Join Date
Oct 2014
Posts
8
Rep Power
0

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

System.out.print("Enter working hours: ");
System.out.print("Enter position type: ");

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. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
13

## Re: From a flow chart to a code

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

Regards,
Jim

8. Member
Join Date
Oct 2014
Posts
8
Rep Power
0

## Re: From a flow chart to a code

Originally Posted by jim829
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. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
13

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

10. Member
Join Date
Sep 2014
Posts
47
Rep Power
0

## 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. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
13

## Re: From a flow chart to a code

Originally Posted by Thammer
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

12. ## Re: From a flow chart to a code

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

kind regards,

Jos

13. Member
Join Date
Sep 2014
Posts
47
Rep Power
0

## 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. ## Re: From a flow chart to a code

Originally Posted by Thammer
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

#### Posting Permissions

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