![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2006
Posts: 3
Rep Power: 0
![]() |
Method/Loop?
For the last part of my problem I need to create another method called payroll that takes no parameters and loop it 4 times and in each pass, it should ask for sales amount for the week then calculate sales for the month by calling on bonus and commission?
I'm not sure how to go about it and I don't understand why payroll shouldn't have any parameters. How can it call on commission and bonus without them are parameters? Also what kind of loop will be best suited for it? here's my code so far.
public class Project4 {
public static void main(String[] args) {
double amount;
int years;
double ans;
double extra = 400;
double baseSalary = 500.00;
//Ask for amount
System.out.print("Please enter sales amount for the week: "); //Ask for amount
amount = MyInput.readDouble(); //Store amount
//Ask for years
System.out.print("Please enter the number of years the sales person has been with the company: ");
years = MyInput.readInt(); //Store amount
double commission = commission(amount);
double bonus = bonus(years, amount, baseSalary);
double payroll = payroll(commission, bonus, amount);
System.out.println("Your monthly salary is $" + payroll );
}
public static double commission(double amount)
{
if (amount >= 5000) { //Calculate sales if amount entered is greater than or equal to 10001
return (amount * 0.10) + 400;
}
else if (amount >= 1000 ){
return (amount * .08);
}
else if (amount >= 1000){
return (amount * 0.08);
}
else if (amount >= 500 ){
return(amount * .05);
}
else { return 0.0;
}
}
public static double bonus(int years, double amount, double baseSalary)
{
if (amount >= 5000 && years >= 2) {
return (baseSalary + amount * years/100) ;
}
else if (amount >= 1000 && years >= 2){
return (baseSalary + amount * years/100);
}
else if (amount >= 500 && years >= 2){
return (baseSalary + amount * years/100);
}
else if (amount < 500&& years >= 2){
return(baseSalary + amount * years/100);
}
else { return baseSalary;
}
}
public static double payroll(double commission,double bonus, double amount)
{
{
if (amount >= 5000 ) {
return (commission + bonus) ;
}
else if (amount >= 1000 ){
return (commission + bonus);
}
else if (amount >= 500 ){
return (commission + bonus);
}
else if (amount < 500){
return(commission + bonus);
}
else { return 500.00;
}
}
}
}
//}
/**
if (amount >= 5000 && years >= 2) { //Calculate sales if amount entered is greater than or equal to 10001
ans = (amount * 0.10) + (baseSalary + 400);
ans = (ans * years/100) + ans;
}
else if (amount >= 5000 && years < 2){
ans = (amount * 0.10) + (baseSalary + 400);
}
else if (amount >= 1000 && years >= 2){
ans = (amount * .08) + baseSalary * (years/100);
ans = (ans * years/100) + ans;
}
else if (amount >= 1000 && years < 2){
ans = (amount * 0.08) + baseSalary;
}
else if (amount >= 500 && years >= 2){
ans = (amount * .05) + baseSalary * (years/100);
ans = (ans * years/100) + ans;
}
else if (amount >= 500 && years < 2){
ans = (amount * 0.10) + baseSalary;
}
else if (amount < 500&& years >= 2){
ans = baseSalary;
}
else { ans = baseSalary;
}*/ |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Not enough information to make a judgement. If you're not going to use parameters, the only option is to set up a few variables as class members. I also suppose the "loop it 4 times" could mean that you need to return the first four months salary, in which case a for-loop would look a likely candidate, but it's difficult to know for sure.
Perhaps if you could give the exact text of the problem? |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Nov 2006
Posts: 3
Rep Power: 0
![]() |
It seems as though I was misunderstanding what we had to do XD it was pretty simple and I worked it out. Thank you so much though.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|