go to labs.codecademy.com and go to javascript
here is a sample solution in Javascript, but you will have to convert to Java and do the formatting on your own and add whatever else you need to meet the professor's specifications... but it should give you an idea of how to find the maximum sale of one particular employee and how to compare the maximum sale amongst two employees:
here is a sample solution in Javascript, but you will have to convert to Java and do the formatting on your own and add whatever else you need to meet the professor's specifications... but it should give you an idea of how to find the maximum sale of one particular employee and how to compare the maximum sale amongst two employees:
Code:
function employee(firstName, lastName, sales)
{
this.firstName = firstName;
this.lastName = lastName;
this.name = firstName + " " + lastName;
this.sales = sales;
this.maxSales = [];
this.getMaxSales = function(input)
{
var holder = 0;
for(i=0; i<input.length; i++)
{
if(input[i] > holder)
{
holder = input[i];
}
}
return(holder);
};
}
function getEmployeeMaxSale()
{
var salesholder = 0;
var nameholder = "";
for(i = 0; i < employeeArray.length; i++)
{
if(employeeArray[i].maxSales > salesholder)
{
salesholder = employeeArray[i].maxSales;
nameholder = employeeArray[i].name;
}
}
console.log("The employee with the maximum sale is: " + nameholder +
" with a sale of " + salesholder + ".");
}
// 3 employees created with the Employee constructor
var employeea = new employee("Lewis", "Peters", [9,1,4,1]);
employeea.maxSales = employeea.getMaxSales(employeea.sales);
var employeeb = new employee("Steven", "Jones", [4,3,8,2]);
employeeb.maxSales = employeeb.getMaxSales(employeeb.sales);
var employeec = new employee("Adrian", "Rainwater", [4,10,3,5]);
employeec.maxSales = employeec.getMaxSales(employeec.sales);
// Output the Employee Data
console.log(employeea.name);
console.log("Sales: " + employeea.sales);
console.log(employeea.name + "'s maximum sale is: " + employeea.maxSales + "\n");
console.log(employeeb.name);
console.log("Sales: " + employeeb.sales);
console.log(employeeb.name + "'s maximum sale is: " + employeeb.maxSales + "\n");
console.log(employeec.name);
console.log("Sales: " + employeec.sales);
console.log(employeec.name + "'s maximum sale is: " + employeec.maxSales + "\n");
// An Array that holds all the employees. Used to get the max sale of all employees
var employeeArray = [employeea, employeeb, employeec];
// Calls the function to get the max sale of all the employees
getEmployeeMaxSale();