This works but does it look right?
Posted: 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.
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);
}
}
]