Hey. I've been working on this for a while and am having a lot of trouble with it. What I have to do is:
Some processing requirements:
- all data entry will be in the main method
- must use a sentinel loop to stop processing salespersons
- must test for valid data and if not correct, must keep prompting until the user enters in valid data
- create user-defined methods for the following:
* isNumeric: this method will determine if the string passed in is numeric. The method will return a TRUE value if the string is numeric and FALSE if the string is not numeric
* calcBonus: this method will calculate the saleperson's bonus based on the above table. This method will calculate the bonus and return this value.
* calcCommission: this method will calculate the commission the salesperson earned and return this value.
- the output will be generated from the main method
- The output generated will include:
The Salesperon’s name and paycheck amount
This is my first time using user defined methods and am struggling a lot.
So far i have this as the main body of the program:
import java.io.*;
import java.util.*;
public class MonthlyPaycheckCalculator
{
//scanner
static Scanner console = new Scanner(System.in);
public static void main(String[]args)
{
//local variables
String salespersonName;
double baseSalary;
int yearsOfService;
double totalSales;
double bonus;
double additionalBonus;
//Get salespersonName
System.out.print("Please Enter Name of Salesperson (Enter # to end entry)");
System.out.println();
salespersonName = console.next();
System.out.println();
while (salespersonName != "#");
//Get baseSalary
System.out.print("Please Enter Base Salary");
System.out.println();
baseSalary = console.nextDouble();
System.out.println();
//check isNumeric
//Get yearsOfService
System.out.print("Please Enter Years of Service");
System.out.println();
yearsOfService = console.nextInt();
System.out.println();
//check isNumeric
//Get totalSales
System.out.print("Enter Sale Total");
System.out.println();
totalSales = console.nextDouble();
System.out.println();
}
}
This is my isNumeric method:
public class isNumeric
{
// This method checks if a String contains only numbers
public boolean isNumeric(String str)
{
//It can't contain only numbers if it's null or empty
if (str == null || str.length() == 0)
return false;
for (int i = 0; i < str.length(); i++)
{
//non-digit character returns false.
if (!Character.isDigit(str.charAt(i)))
return false;
}
return true;
}
}
This is my calcBonus method:
public class calcBonus
{
// constants
private static final double ltfYears = 10.00; // less than five years bonus
private static final double mtfYears = 20.00; // more than five years bonus
private static final int bonusStep = 5;
// main
{
// Local variables
int yearsWorked; //reads in years as string
double bonus; //calculated bonus
if (yearsWorked <= bonusStep)
//... Computation
bonus = ltfYears * yearsWorked; //Note 1
else
bonus = mtfYears * yearsWorked;
//... Output
System.out.printf("Bonus: $%.2f", bonus);
System.out.println();
}
}
And I have not done anything with the calcCommission method yet.
Can someone tell me whether either of my methods are on the right track, or if not what I need to do differently, and for the main body, is it set up right or am I way off on that as well?
This is all done in Java btw. Any help would be greatly appreciated. Thanks.