Hello,

First of all, I hope my post isn't breaking any of the forums' rules

Here's my code so far

import java.util.Scanner;

/**
 *
 * @author user
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) 
    {
          
         Scanner sc = new Scanner (System.in);
         System.out.print("Employee name: ");
         String str =sc.next();
         System.out.print("Skill level: ");
         int level =sc.nextInt();
         System.out.print("Hours worked: ");
         int hours =sc.nextInt();     
         if(hours>40){
         int x=hours-40;
         double overtime;
           
  if(level==1){
                int l1=30;
                overtime= x*1.5*l1;
                int leveLL=(40*(l1)); //level2
           System.out.println("Regular pay: "+leveLL);
           System.out.println("overtime pay: "+overtime);
           System.out.println("Total pay: "+(overtime+leveLL));
}else if (level == 2){
                int l2=40;
                int leveLL=(40*(l2)); //level2
                overtime= x*1.5*l2;
            System.out.println("Regular pay: "+leveLL);
            System.out.println("Overtime pay: "+overtime);
            System.out.println("Total pay: "+(overtime+leveLL));}
            System.out.print("How many option you need? ");
            int option=sc.nextInt();
            if (option==1 ||option==2 ||option==3);{
             System.out.print("choose insurance option Medical,Dental or Disability? ");
             String o=sc.next();
             int Medical=60;
             int Dental=40;
             int Disability=25;
             System.out.println("total insurance deduction"+o);}
            if((option==1&&option==2)||(option==1&&option==3)||(option==2&&option==3)){
                System.out.print("choose insurance option Medical,Dental or Disability..?1");
             String o=sc.next();
             int Medical=60;
             int Dental=40;
             int Disability=25;
             System.out.println("total insurance deduction"+o);}
           if(option==3){
                int Medical=60;
                int Dental=40;
                int Disability=25;
                System.out.println("total insurance deduction"+(+Medical+Dental+Disability));}

 }else if(level==3){
               if(hours>40){
               int x=hours-40;
               int l3=50;
               int leveLL=(40*(l3)); //level2
              double overtime3= x*1.5*l3;
             System.out.println("Regular pay: "+leveLL);
             System.out.println("overtime pay: "+overtime3);
             System.out.println("Total pay: "+(overtime3+leveLL));
             System.out.print(" insurance option?!...");
             int option3=sc.nextInt();
          if (option3==1 ||option3==2 ||option3==2);{
            System.out.print("choose insurance option Medical,Dental or Disability..?1");
             String o=sc.next();
            int Medical=60;
             int Dental=40;
             int Disability=25;
             System.out.println("total insurance deduction"+o);}
            if((option3==1&&option3==2)||(option3==1&&option3==3)||(option3==2&&option3==3)){
                System.out.print("choose insurance option Medical,Dental or Disability..?1");
             String o=sc.next();
             int Medical=60;
             int Dental=40;
             int Disability=25;
             System.out.println("total insurance deduction"+o);}
           if(option3==3){
              int Medical=60;
              int Dental=40;
              int Disability=25;
              System.out.println("total insurance deduction"+(+Medical+Dental+Disability));}
             System.out.print("Do you have retirement option?...");
             boolean retirement=sc.hasNext();

           }else{
             System.out.println("skill level invalid");
               }

this is the full question for this code: (pretty long, but I highlighted the parts I don't really understand)

A company runs a small factory. Workers are paid one of the three hourly rates depending on their skill level.

Skill level Hourly rate (dirham)
1 30
2 40
3 50

Each factory worker might work any number of hours per week; any hour over 40 are paid at one and one-half rate.

In addition workers in skill levels 2 and 3 can choose to participate in the following insurance options (zero or more) :

Option Explanation Weekly Cost to Employee
1 Medical Insurance 60
2 Dental Insurance 40
3 Disability Insurance 25

Also, workers in skill level 3 can choose to participate in the retirement plan at 3% of their gross pay.Write an interactive Java payroll application that calculates the net pay for a factory worker.

1-The program prompts the user for:
a.Employee name
b.skill level (1, 2, or 3)
c.hours worked,
d.insurance option (1, 2, or 3) , notice that only workers of level 2 and 3 can choose insurance option. In addition, they can choose more than one plan. For example, a worker can have dental and medical plans at the same time.
e.retirement option (yes or no) only for workers of skill level 3

2-The application displays:
a.hours worked,
b.hourly rate
c.regular pay for 40 hours
d.overtime pay
e.total pay
f.total deductions
g.the net pay (total pay – total deductions).

3-The output in step 2 should be saved also in a file under the employee name in the following format:

Pay Information for this week:
-Employee:
-Skill-Level:3
-Total hours worked:42
-Regular pay: (40 *50=) 2000
-Overtime pay (2 * 75 =) 150
-Total pay: ( 2000 + 150 =) 2150
-Total insurance deduction: (plan 1 and 3) 85
-Total retirement deduction: Not chosen
-Net Pay: 2150 – (85 +0) = 2045

-------------------------------

what I'd like help with is:
- for the "Total insurance deduction: (plan 1 and 3) 85
the insurance option is available only for workers with skill levels 2 and 3 and are able to have any of these three options
1>Medical Insurance...60
2>Dental Insuranc...40
3>Disability Insurance.....25
so if one user, wanted to have ALL three options (60+40+25)
and another user wanted to have the Medical Insurance + Disability Insurance option, so(60+25) which is the "Total insurance deduction" and also, another user wanted to have only one option (Dental Insurance...40)
Problem is: how can I make the program find the total\sum of options that the user might enter as he has in mind. I tried this
System.out.println("total insurance deduction"+o);}

System.out.println("total insurance deduction"+(+Medical+Dental+Disability));

but its not working. and i'd like to know if the code I wrote so far has some logical errors (if there is, could you help me spot them). and is there a more easier way to solve this question? i'd really appreciate it and kind of explaination/hint..etc.

well your problem lies in the way you ask your user,the easiest way would be to prompt them for Medical y/n then if response is y add medical price to total, then prompt Dental y/n then if response is y add dental price to total...

int totalinsurance = 0;
System.out.print("would you like Medical insurance? (y/n) ");
String o=sc.next();
int Medical=60;
int Dental=40;
int Disability=25;
if(o.equals("y")){
   totalinsurance += Medical;
}
System.out.print("would you like Dental insurance? (y/n) ");
String o=sc.next();
if(o.equals("y")){
   totalinsurance += Dental;
}
System.out.print("would you like Disability insurance? (y/n) ");
String o=sc.next();
if(o.equals("y")){
   totalinsurance += Disability;
}
System.out.print("your insurance options total $"+totalinsurance);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.