This works but does it look right?

Technical assistance & information for projects
Post Reply
User avatar
Trebor29
Lieutenant
Lieutenant
Posts: 75
Joined: Thu Apr 29, 2010 12:34 am

This works but does it look right?

Post by Trebor29 » Fri May 14, 2010 12:08 am

It is all working so far but as Ive not been writing any code for a couple of weeks if feels slightly odd! Does it seem to you a bit 'hickledy pickeldy' LOL... Im sure I should be putting more in the methods. Can you have methods inside methods? & if's inside methods?
It just feels like im going at it the wrong way, even though its working.
Any advice is greatly appreciated. Thank you.

Code: Select all

import java.util.Scanner;
import java.text.*;

class PayMethods
{
	public static void main(String[]args)
	{
		Scanner input = new Scanner(System.in);
		DecimalFormat Currency = new DecimalFormat("£###,###,000.00");
		
		double basic=36;
		int bonus=0;

		System.out.println("Please enter name.");
		String name = input.next();
		
		System.out.println("Please enter position.");
		System.out.println("======================");
		System.out.println("Manager       = (M)");
		System.out.println("Supervisor    = (S)");
		System.out.println("Team Leader   = (TL)");
		System.out.println("General Staff = (G)");
		String position = input.next();
		
		System.out.println("Please enter total hours worked.");
		double totalHrsWkd = input.nextDouble();
		
		if (position.equalsIgnoreCase("m"))
		{
			System.out.println(name+"'s total wages for the week.");
			System.out.println("=================================");
			
			/* Ive use 'man' at the start of some names because this 
			 * part is for the Manager option (position).
			 */
			
			if (totalHrsWkd<=36)
			{
				double a1 = manBasic(totalHrsWkd);
				String newA1 = Currency.format(a1);
				System.out.println("Basic     = "+newA1);
				double manOvrTime=0;
				System.out.println("Over Time = £"+manOvrTime);
				System.out.println("Bonus     = £"+bonus);
				double gross=(totalHrsWkd*8.165)*0.89;
				String newGross = Currency.format(gross);
				System.out.println("Gross     = "+newGross);
			}
			
			if (totalHrsWkd>36 && totalHrsWkd<50)
			{
				double basicRate=basic*8.165;
				String newbasicRate = Currency.format(basicRate);
				System.out.println("Basic     = "+newbasicRate);
				double a2 = manOvrTime(totalHrsWkd);
				String newA2 = Currency.format(a2);
				System.out.println("Over Time = "+newA2);
				System.out.println("Bonus     = £"+bonus);
				double gross=(basicRate+a2)*0.89;
				String newGross = Currency.format(gross);
				System.out.println("Gross     = "+newGross);
			}
			
			if (totalHrsWkd>50)
			{
				double basicRate=basic*8.165;
				String newbasicRate = Currency.format(basicRate);
				System.out.println("Basic     = "+newbasicRate);
				double a2 = manOvrTime(totalHrsWkd);
				String newA2 = Currency.format(a2);
				System.out.println("Over Time = "+newA2);
				int b = manBonus(bonus);
				String newB = Currency.format(b);
				System.out.println("Bonus     = "+newB);
				double gross=(basicRate+a2+b)*0.89;
				String newGross = Currency.format(gross);
				System.out.println("Gross     = "+newGross);
			}
		}
	}
	
	public static double manBasic(double hrsWkd)
	{
		return(hrsWkd*8.165);
	}
	
	public static double manOvrTime(double hrsWkd)
	{
		double ovrTime=hrsWkd-36;
		return(ovrTime*13.135);
	}
	
	public static int manBonus(int bonus)
	{
		bonus=50;
		return(bonus);
	}
}
]
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: This works but does it look right?

Post by Neo » Fri May 14, 2010 4:00 pm

Hi Trebor

Had a look at your code and it looks fine to me.

* You can't put methods inside methods. However you can call other methods from a method.

Example:

Code: Select all

void MyFirstFunc(){
}

void MySecondFunc(){

      MyFirstFunc(); // calls the first function
}
* You can use as many as "if"s you want inside a method.

I think I have cleared your doubts now.
john122
Corporal
Corporal
Posts: 6
Joined: Thu Feb 02, 2012 12:21 pm

Re: This works but does it look right?

Post by john122 » Wed Feb 08, 2012 4:04 pm

I like it very much..............
Post Reply

Return to “Project Assistance”