3 Replies - 1961 Views - Last Post: 26 October 2006 - 12:47 PM Rate Topic: -----

#1 BigBoi601  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-October 06

Switch Statement Problem

Posted 25 October 2006 - 02:49 PM

  
		switch(employee_worker)
		{
			case 1:
			System.out.print(Enter manager hours:");
			manager=input.nextInt();
			System.out.print(Enter manager wage:");
			wage=input.nextInt();
			salary=hours*wage;
			System.out.printf("The weekly salary of the manager is %d\n",salary);
			break;
		
			
			case 2:	System.out.print("Hourly worker hours:");
			hourly_worker=input.nextInt();
			System.out.print(Hourly worker wage:");
			wage=input.nextInt();
			if(hourly_worker>40)
			hourly_worker*overtime;
			break;
			
			case 3:
		}	 


I'm writing a payroll program and i wasn't sure if i was using the switch statement correctly. this all i wrote so far for the switch statement. i got 2 more cases to put up for the switch to be complete. case three is givin me problems i suppose to put commission workers and how the commions worker receive $250 plus 5.7 percent for gross pay i'm stuck on how to write it in the switch bracket

edit: added [code] tags ~ jayman9

Is This A Good Question/Topic? 0
  • +

Replies To: Switch Statement Problem

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Switch Statement Problem

Posted 25 October 2006 - 03:01 PM

Your switch syntax is accurate so far, assuming employee_worker is of type integer. Although you've got some other problems in your code inside the cases.

One problem is that here hourly_worker*overtime; you have not assigned the value from your calculation. You need to store the value inside another variable or display it in print statement. Speaking of which, currently you are not outputting the results of your calculations in the case 2, you did it in case 1.
Was This Post Helpful? 0
  • +
  • -

#3 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 205
  • View blog
  • Posts: 4,807
  • Joined: 23-December 05

Re: Switch Statement Problem

Posted 25 October 2006 - 03:54 PM

try adding as your last case a default:
if you reach this, then you know the values are incorrect, even have this option print out the value of employee_worker, to see what is actually going on.
Was This Post Helpful? 0
  • +
  • -

#4 BigBoi601  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-October 06

Re: Switch Statement Problem

Posted 26 October 2006 - 12:47 PM

import java.util.Scanner;

public class employee

{
	public static void main(String args[])
	{
		Scanner input=new Scanner(System.in);
		
		int employee_worker; int hourly_worker;int overtime=1.5;
		int wage; int manager; int salary; 
		
		switch(employee_worker)
		{
			case 1:
			System.out.print("Enter manager hours:");
			manager=input.nextInt();
			System.out.print("Enter manager wage:");
			wage=input.nextInt();
			salary=manager*wage;
			System.out.printf("The weekly salary of the manager is %d\n",salary);
			break;
		
			
			case 2:	System.out.print("Hourly worker hours:");
			hourly_worker=input.nextInt();
			System.out.print("Hourly worker wage:");
			wage=input.nextInt();
			if(hourly_worker>40)
			overtime*=hourly_worker;
			System.out.printf("The hourly worker pay is %d\n",overtime);
			break;
			
			default: System.out.print("What a day");
			break;
			
		}
		}
	}



This is the whole code so far i'm having problem writing out case 3 and 4.I suppose add a commission worker and a pieceworker. This is what my professor want us to do. A company pays its employees as managers (who receive a fixed weekly salary), hourly workers* who receive a fixed hourly wage for up to the first 40 hours thye work and 'time an a half- 1.5 times their hourly wage for overtime hours worked), commission workers (who receive $250 plus 5.7 percent of thier gross weekly sales) or pieceworkers (who receive a fixed amount of money per item for each of the items they produce-each pieceworker in this com pany works on only one type of item). Write a program to com pute the weekly pay for each employee You do not know the number of employees in advance. Each type of employee has it own pay code: Managers have code1, hourly workers have code 2, commission worker have code 3, and pieceworkers have code 4. use switch statements to compute each employee's pay according to that employee's paycode. Within the switch prompt the user to enter the appropriate facts your program according to that employee's paycode. I think i got case 1 and 2 correct im having trouble figuring out case 3 and 4. Your help will be greatly appreciated!!

Edit: added code tags. ~Videege
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1