how to Print out the employee details having highest and second highest salary? - arraylist

csv file which has 3 entries of empname,emp id,designation and salary Robert,33,Manager,12000 Duval,23,Associate,6000 Kierron,33,AD,20000
From below code how to Print out the employee details having the highest and second highest salary?
enter code here
public class HighSalary {
public static void highSalary() throws IOException {
String record;
BufferedReader br = new BufferedReader(new FileReader("/Users/ak/Documents/emp.csv"));
System.out.println("\t\t Printing Employee Details of Highest & Second Highest Salary \n");
System.out.println(" ------------------------------------------------------------- ");
System.out.println("| ID Name Age Address |");
System.out.println(" ------------------------------------------------------------- ");
List<List<String>> arlist = new ArrayList<>();
int highestSal = 0;
int secondSal = 0;
while ((record = br.readLine()) != null) {
String[] words = record.split(",");
arlist.add(Arrays.asList(words));
int salary = Integer.parseInt(words[3]);
if (highestSal == 0) {
highestSal = salary;
secondSal = salary;
}
else if (salary > highestSal) {
secondSal = highestSal;
highestSal = salary;
}
else if (salary > secondSal || secondSal == 0) {
secondSal = salary;
}
}
System.out.println("highest salary: " + highestSal);
System.out.println("second highest salary: " + secondSal);
br.close();
}
}
enter code here

You may iterate the file, keeping track of the highest and second highest salary. When assigning a new highest salary, the second highest should be assigned to the previous highest salary. Also, you may store two strings for the metadata associated with the highest and second highest paid employees.
Integer highest = null;
Integer second = null;
String highEmp = "";
String secondEmp = "";
while ((record = br.readLine()) != null) {
String[] words = record.split(",");
arlist.add(Arrays.asList(words));
int salary = Integer.parseInt(words[3]);
if (highest == null) {
highest = salary;
second = salary;
highEmp = record;
secondEmp = record;
}
else if (salary > highest) {
second = highest;
secondEmp = highEmp;
highest = salary;
highEmp = record;
}
else if (salary > second) {
second = salary;
secondEmp = record;
}
}
System.out.println("highest salary: " + highest);
String[] parts = highEmp.split(",");
System.out.println("Name: " + parts[0] + ", Age: " + parts[1] + ", Desig: " + parts[2]);
System.out.println("second highest salary: " + second);
parts = secondEmp.split(",");
System.out.println("Name: " + parts[0] + ", Age: " + parts[1] + ", Desig: " + parts[2]);

Related

Array list not obtaining smallest age

I've setup 2 different array lists that coincide and I have code to find the biggest age and smallest age, However my youngest age isn't outputting. I am getting the biggest age as outputted
import java.util.Scanner;
import java.util.ArrayList;
public class Database1{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
ArrayList<Integer> age = new ArrayList<>();
ArrayList<String> name = new ArrayList<>();
int count = 0;
while (count < 10) {
System.out.println("Please enter a first name");
String inputName = in.nextLine();
if(inputName.contains("done")){
break;
}
name.add(inputName);
System.out.println("Please enter an age");
age.add(in.nextInt());
in.nextLine();
count++;
}
int smallest = age.get(0);
int biggest = age.get(0);
String youngestName = "" ;
String oldestName = "";
for (int i = 0; i < age.size(); i++) {
if(age.get(i) > biggest){
biggest = age.get(i);
oldestName = name.get(i);
}if (age.get(i) < smallest){
smallest = age.get(i);
youngestName = name.get(i);
}
}
System.out.println("The oldest person was " + oldestName);
System.out.println("The youngest person was " + youngestName);
System.out.println(name);
System.out.println(age);
}
}
I am receiving this as an output
The oldest person was john
The youngest person was
[Luke, Chris, Neal, john]
[18, 19, 44, 66]
Modify to the following:
public static void main(String[] args){
Scanner in = new Scanner(System.in);
ArrayList<Integer> age = new ArrayList<>();
ArrayList<String> name = new ArrayList<>();
int count = 0;
while (count < 10) {
System.out.println("Please enter a first name");
String inputName = in.nextLine();
if(inputName.contains("done")){
break;
}
name.add(inputName);
System.out.println("Please enter an age");
age.add(in.nextInt());
in.nextLine();
count++;
}
int smallest = age.get(0);
int biggest = age.get(0);
String youngestName = name.get(0); ;
String oldestName = name.get(0);
for (int i = 0; i < age.size(); i++) {
if(age.get(i) > biggest){
biggest = age.get(i);
oldestName = name.get(i);
} else if (age.get(i) < smallest){
smallest = age.get(i);
youngestName = name.get(i);
}
}
System.out.println("The oldest person was " + oldestName);
System.out.println("The youngest person was " + youngestName);
System.out.println(name);
System.out.println(age);
}

I would like add GPA in my code but unfortunately not working

I would ask if someone can help me the GPA in my code not working as per required.please find below it.
Scanner Student=new Scanner(System.in);
System.out.println("Please Enter Three Marks for Student");
int sum=0;
double avg;
int[]x=new int[3];
for (int i = 0; i < x.length; i++) {
System.out.println("The mark : "+ ( i +1));
x[i]=Student.nextInt();
sum=sum+x[i];
}
char grade;
if (sum >= 90 )
{
grade = 'A';
}
else if (sum >= 80 )
{
grade = 'B';
}
else if (sum >= 70)
{
grade = 'C';
}
else if (sum >= 50)
{
grade = 'D';
}
else
{
grade = 'F';
}
// Display the grade.
System.out.println("The grade is " + grade);
avg=sum/x.length;
System.out.println("The total of three marks are :"+sum+"\nThe Average is :"+avg);
}

Need help on getting highest salary and second highest salary from emp.csv using java

I have one csv file which has 3 entries of empname,emp id,designation and salary
Robert,33,Manager,12000
Duval,23,Associate,6000
Kierron,33,AD,20000
Using Java program, I like to achieve the highest salary and second highest salary
public class HighSalary {
public static void highSalary() throws IOException {
String record;
BufferedReader br = new BufferedReader(new FileReader("/Users/ak/Documents/emp.csv"));
System.out.println("\t\t Max Salary Record\n");
System.out.println(" ------------------------------------------------------------- ");
System.out.println("| Name Age Desig Salary |");
System.out.println(" ------------------------------------------------------------- ");
List<List<String>> arlist = new ArrayList<>();
// List<String> list = Arrays.asList(a);
int maxSal = 0;
while ((record = br.readLine()) != null) {
String[] words = record.split(",");
arlist.add(Arrays.asList(words));
for (int i = 0; i < words.length; i++) {
if (maxSal <= Integer.parseInt(words[3])) {
maxSal = Integer.parseInt(words[3]);
} else {
maxSal = maxSal;
}
}
System.out.println("From The Salary Largest Number is:" + maxSal);
}
br.close();
}
}
the problem with this code is printing like this as below:
From The Salary Largest Number is:12000
From The Salary Largest Number is:12000
From The Salary Largest Number is:20000
You need to keep track of two separate variables, one for the highest salary, and the other for the second highest salary. When assigning the highest salary, the previous highest salary should be clobbering the second highest. When assigning a new second highest, only the previous second highest should be overwritten.
Integer highest = null;
Integer second = null;
while ((record = br.readLine()) != null) {
String[] words = record.split(",");
arlist.add(Arrays.asList(words));
int salary = Integer.parseInt(words[3]);
if (highest == null) {
highest = salary;
second = salary;
}
else if (salary > highest) {
second = highest;
highest = salary;
}
else if (salary > second) {
second = salary;
}
}
System.out.println("highest salary: " + highest);
System.out.println("second highest salary: " + second);
System.out.println("From The Salary Largest Number is:" + maxSal); Keep this outside while loop.

Optaplanner ScoreDirector continuous planning DayOff Request

I am trying to enable continuous planning and requests. I have tried to follow the computer example provided within the doco. Code below. I can see the values updated during debug. Code below. What am I doing wrong
public void addEmployeeDayOff(final Employee employee,final DayOffRequest dayOffRequest) {
logger.info("Scheduling employee dayoff ({}).", dayOffRequest);
doProblemFactChange(scoreDirector -> {
NurseRoster nurseRoster = scoreDirector.getWorkingSolution();
Employee workingEmployee = scoreDirector.lookUpWorkingObject(employee);
DayOffRequest dayoffRequest = scoreDirector.lookUpWorkingObject(dayOffRequest);
scoreDirector.beforeProblemPropertyChanged(workingEmployee);
if (workingEmployee == null) {
return;
}
ArrayList<DayOffRequest> requestoffList = new ArrayList<>(nurseRoster.getDayOffRequestList());
nurseRoster.setDayOffRequestList(requestoffList);
scoreDirector.beforeProblemFactAdded(dayoffRequest);
workingEmployee.getDayOffRequestMap().put(dayoffRequest.getShiftDate(), dayoffRequest);
scoreDirector.afterProblemPropertyChanged(workingEmployee);
nurseRoster.getDayOffRequestList().add(dayoffRequest);
scoreDirector.afterProblemPropertyChanged(dayoffRequest);
scoreDirector.triggerVariableListeners();
});
The above is called from here:
List<DayOffRequest> dayOffRequestList;
//updating from database .. not sure if this is the issue
List<DayOffData> dayOffElementList = (List<DayOffData>) rosterService.listDayOffData();
dayOffRequestList = new ArrayList<>(dayOffElementList.size());
long nextdayoffId =0L;
for (DayOffData element : dayOffElementList) {
if (nextdayoffId <= element.getId()) {
nextdayoffId = element.getId() + 1L;
}
DayOffRequest dayOffRequest = new DayOffRequest();
String empID = element.getEmployee().getName();
int weight = element.getWeight();
LocalDate shiftDate = element.getShiftDate();
ShiftDate date1 = shiftDateMap.get(shiftDate);
Employee employee = employeeMap.get(empID);
dayOffRequest.setId(nextdayoffId);
dayOffRequest.setWeight(weight);
dayOffRequest.setEmployee(employee);
dayOffRequest.setShiftDate(date1);
dayOffRequestList.add(dayOffRequest);
//If this is not enabled the values don't pass to the addEmployeeDayOff method is this correct??
scoreDirector.afterProblemFactAdded(dayOffRequest);
scoreDirector.afterProblemFactAdded(employee);
addEmployeeDayOff(employee,dayOffRequest);
}
I found this worked but not sure if this is the correct way to approach the problem.
public void addEmployeeDayOff(final Employee employee, final DayOffRequest dayOffRequest) {
logger.info("Scheduling employee dayoff ({}).", dayOffRequest);
doProblemFactChange(scoreDirector -> {
NurseRoster nurseRoster = (NurseRoster) scoreDirector.getWorkingSolution();
Employee workingEmployee = scoreDirector.lookUpWorkingObject(employee);
DayOffRequest dayoffRequest = (DayOffRequest) scoreDirector.lookUpWorkingObject(dayOffRequest);
scoreDirector.beforeProblemPropertyChanged(workingEmployee);
if (workingEmployee == null) {
return;
}
ArrayList<DayOffRequest> requestoffList = new ArrayList<>(nurseRoster.getDayOffRequestList());
nurseRoster.setDayOffRequestList(requestoffList);
scoreDirector.afterProblemFactAdded(requestoffList);
scoreDirector.afterProblemPropertyChanged(requestoffList);
ArrayList<Employee> beforeempList = new ArrayList<>(nurseRoster.getEmployeeList());
nurseRoster.setEmployeeList(beforeempList);
nurseRoster.getEmployeeList().remove(workingEmployee);
scoreDirector.beforeProblemFactRemoved(workingEmployee);
scoreDirector.afterProblemFactRemoved(workingEmployee);
ArrayList<Employee> empList = new ArrayList<>(nurseRoster.getEmployeeList());
nurseRoster.setEmployeeList(empList);
workingEmployee.getDayOffRequestMap().put(dayOffRequest.getShiftDate(), dayOffRequest);
nurseRoster.getEmployeeList().add(workingEmployee);
scoreDirector.beforeProblemFactAdded(workingEmployee);
scoreDirector.afterProblemFactAdded(workingEmployee);
scoreDirector.triggerVariableListeners();
});
I have uploaded the xml and Java file here https://github.com/rod182211/Optaplanner in to hope someone can advise why when I advance 14 days not all rule continue to apply. I assumed scoredirector only needed to be made aware of changes.
14 Day advance taking into account Requests via the below.
doProblemFactChange(scoreDirector -> {
NurseRoster nurseRoster = scoreDirector.getWorkingSolution();
NurseRosterParametrization nurseRosterParametrization = nurseRoster
.getNurseRosterParametrization();
List<ShiftDate> shiftDateList = nurseRoster.getShiftDateList();
Shift oldLastShift = nurseRoster.getShiftList()
.get(nurseRoster.getShiftList().size() - 1);
long shiftId = oldLastShift.getId() + 1L;
int shiftIndex = oldLastShift.getIndex() + 1;
ShiftDate oldLastShiftDate = shiftDateList
.get(shiftDateList.size() - 1);
long shiftDateId = (oldLastShiftDate.getId() + 1L);
int shiftDayIndex = (oldLastShiftDate.getDayIndex() + 1);
// long parmId = nurseRoster.getNurseRosterParametrization().getId()
// + 1L;
scoreDirector
.beforeProblemPropertyChanged(nurseRosterParametrization);
// Update to get the first day along with adding 14 days to the run
LocalDate startDate = (oldLastShiftDate.getDate().plusDays(1));
LocalDate endDate = (oldLastShiftDate.getDate().plusDays(14));
int maxDayIndex = Math.toIntExact(DAYS.between(startDate, endDate));
int shiftDateSize = maxDayIndex + 1;
List<ShiftDate> shiftDateList1 = new ArrayList<>(shiftDateSize);
shiftDateMap = new HashMap<>(shiftDateSize);
LocalDate date = startDate;
for (int i = 0; i < shiftDateSize; i++) {
ShiftDate shiftDate = new ShiftDate();
shiftDate.setId(shiftDateId);
shiftDate.setDayIndex(shiftDayIndex);
shiftDate.setDate(date);
shiftDate.setShiftList(new ArrayList<>());
shiftDateMap.put(date, shiftDate);
shiftDateId++;
shiftDayIndex++;
date = date.plusDays(1);
nurseRoster.getShiftDateList().add(shiftDate);
shiftDateList1.add(shiftDate);
scoreDirector.afterProblemFactAdded(shiftDate);
}
List<Skill> skillList;
List<Skill> skillElementList = (List<Skill>) nurseRoster
.getSkillList();
skillList = new ArrayList<>(skillElementList.size());
skillMap = new HashMap<>(skillElementList.size());
long id = 0L;
for (Skill element : skillElementList) {
Skill skill = new Skill();
skill.setId(id);
skill.setCode(element.getCode());
skillList.add(skill);
if (skillMap.containsKey(skill.getCode())) {
throw new IllegalArgumentException(
"There are 2 skills with the same code ("
+ skill.getCode() + ").");
}
skillMap.put(skill.getCode(), skill);
id++;
}
List<Contract> contractElementList = (List<Contract>) nurseRoster
.getContractList();
List<Contract> contractList = new ArrayList<>(
contractElementList.size());
contractMap = new HashMap<>(contractElementList.size());
for (Contract element : contractElementList) {
Contract contract = new Contract();
long Id = element.getId();
contract.setId(Id);
contract.setCode(element.getCode());
contract.setDescription(element.getDescription());
WeekendDefinition weekend = element.getWeekendDefinition();
contract.setWeekendDefinition(weekend);
contract.setContractLineList(new ArrayList<ContractLine>());
contractMap.put(contract.getCode(), contract);
contractList.add(contract);
}
List<ShiftTypeSkillRequirement> coverRequirementElementList = (List<ShiftTypeSkillRequirement>) nurseRoster
.getShiftTypeSkillRequirementList();
List<ShiftType> shiftTypeElementList = (List<ShiftType>) rosterService
.listShiftType();
List<ShiftType> shiftTypeList = new ArrayList<>(
shiftTypeElementList.size());
shiftTypeMap = new HashMap<>(shiftTypeElementList.size());
long Id = 0L;
int index = 0;
long shiftTypeSkillRequirementId = 0L;
List<ShiftTypeSkillRequirement> shiftTypeSkillRequirementList = new ArrayList<>(
shiftTypeElementList.size() * 2);
for (ShiftType element : shiftTypeElementList) {
ShiftType shiftType = new ShiftType();
shiftType.setId(Id);
shiftType.setCode(element.getCode());
shiftType.setIndex(index);
String startTimeString = element.getStartTimeString();
shiftType.setStartTimeString(startTimeString);
String endTimeString = element.getEndTimeString();
shiftType.setEndTimeString(endTimeString);
shiftType
.setNight(startTimeString.compareTo(endTimeString) > 0);
shiftType.setDescription(element.getDescription());
for (ShiftTypeSkillRequirement skillElement : coverRequirementElementList) {
ShiftTypeSkillRequirement shiftTypeSkillRequirement = new ShiftTypeSkillRequirement();
shiftTypeSkillRequirement
.setId(shiftTypeSkillRequirementId);
shiftTypeSkillRequirement.setShiftType(shiftType);
Skill skill = skillMap
.get(skillElement.getSkill().getCode());
if (skill == null) {
throw new IllegalArgumentException("The skill ("
+ skillElement.getSkill().getCode()
+ ") of shiftType (" + shiftType.getCode()
+ ") does not exist.");
}
shiftTypeSkillRequirement.setSkill(skill);
shiftTypeSkillRequirementList
.add(shiftTypeSkillRequirement);
shiftTypeSkillRequirementId++;
}
shiftTypeList.add(shiftType);
if (shiftTypeMap.containsKey(shiftType.getCode())) {
throw new IllegalArgumentException(
"There are 2 shiftTypes with the same code ("
+ shiftType.getCode() + ").");
}
shiftTypeMap.put(shiftType.getCode(), shiftType);
Id++;
index++;
}
nurseRoster.setShiftTypeList(shiftTypeList);
nurseRoster.setShiftTypeSkillRequirementList(
shiftTypeSkillRequirementList);
int shiftListSize = shiftDateMap.size() * shiftTypeList.size();
List<Shift> shiftList1 = new ArrayList<>(shiftListSize);
dateAndShiftTypeToShiftMap = new HashMap<>(shiftListSize);
dayOfWeekAndShiftTypeToShiftListMap = new HashMap<>(
7 * shiftTypeList.size());
for (ShiftDate shiftDate : shiftDateList1) {
for (ShiftType shiftType : shiftTypeList) {
Shift shift = new Shift();
shift.setId(shiftId);
shift.setShiftDate(shiftDate);
shiftDate.getShiftList().add(shift);
shift.setShiftType(shiftType);
shift.setIndex(shiftIndex);
shift.setRequiredEmployeeSize(0); // Filled in later
shiftList1.add(shift);
dateAndShiftTypeToShiftMap.put(
Pair.of(shiftDate.getDate(), shiftType.getCode()),
shift);
addShiftToDayOfWeekAndShiftTypeToShiftListMap(shiftDate,
shiftType, shift);
shiftId++;
shiftIndex++;
nurseRoster.getShiftList().add(shift);
scoreDirector.afterProblemFactAdded(shift);
}
}
List<DayOffRequest> dayOffRequestList;
List<DayOffRequest> requestList = (List<DayOffRequest>) nurseRoster.getDayOffRequestList();
DayOffRequest oldLastDayOff = requestList.get(requestList.size() - 1);
long DayOffId = (oldLastDayOff.getId() + 1l);
List<DayOffDate> dayOffElementList = rosterService.listDayOffDate();
dayOffRequestList = new ArrayList<>(dayOffElementList.size());
for (DayOffDate element : dayOffElementList) {
DayOffRequest dayOffRequest = new DayOffRequest();
int weight = element.getWeight();
LocalDate shiftDate = element.getDate();
ShiftDate date1 = shiftDateMap.get(shiftDate);
Employee employee = element.getEmployee();
Employee workingEmployee = scoreDirector.lookUpWorkingObject(employee);
dayOffRequest.setId(DayOffId);
DayOffId++;
dayOffRequest.setWeight(weight);
dayOffRequest.setEmployee(workingEmployee);
dayOffRequest.setShiftDate(date1);
workingEmployee.getDayOffRequestMap().put(date1, dayOffRequest);
nurseRoster.getDayOffRequestList().add(dayOffRequest);
}
List<DayOnRequest> dayOnRequestList;
List<DayOnDate> dayOnElementList1 = rosterService.listDayOnDate();
dayOnRequestList = new ArrayList<>(dayOnElementList1.size());
for (DayOnDate element : dayOnElementList1) {
DayOnRequest dayOnRequest = new DayOnRequest();
long DayOnId = element.getId();
int weight = element.getWeight();
LocalDate localshiftDate = element.getDate();
ShiftDate dateon = shiftDateMap.get(localshiftDate);
Employee employee = element.getEmployee();
Employee workingEmployee = scoreDirector.lookUpWorkingObject(employee);
dayOnRequest.setId(DayOnId);
dayOnRequest.setWeight(weight);
dayOnRequest.setEmployee(workingEmployee);
dayOnRequest.setShiftDate(dateon);
dayOnRequestList.add(dayOnRequest);
workingEmployee.getDayOnRequestMap().put(dateon, dayOnRequest);
nurseRoster.getDayOnRequestList().add(dayOnRequest);
}
List<ShiftOffRequest> shiftOffRequestList;
List<ShiftOffDate> shiftOffElementList = (List<ShiftOffDate>) rosterService.listShiftOffDate();
shiftOffRequestList = new ArrayList<>(shiftOffElementList.size());
for (ShiftOffDate element : shiftOffElementList) {
ShiftOffRequest shiftOffRequest = new ShiftOffRequest();
long ShiftonId = element.getId();
int weight = element.getWeight();
Employee employee = element.getEmployee();
Employee workingEmployee = scoreDirector.lookUpWorkingObject(employee);
LocalDate date1 = element.getDate();
String shiftcode = element.getShiftType().getCode();
Shift shift = dateAndShiftTypeToShiftMap.get(Pair.of(date1, shiftcode));
shiftOffRequest.setId(ShiftonId);
shiftOffRequest.setEmployee(workingEmployee);
shiftOffRequest.setShift(shift);
shiftOffRequest.setWeight(weight);
shiftOffRequestList.add(shiftOffRequest);
workingEmployee.getShiftOffRequestMap().put(shift, shiftOffRequest);
nurseRoster.setShiftOffRequestList(shiftOffRequestList);
}
List<ShiftOnRequest> shiftOnRequestList;
List<ShiftOnDate> shiftOnElementList = (List<ShiftOnDate>) rosterService.listShiftOnDate();
shiftOnRequestList = new ArrayList<>(shiftOnElementList.size());
for (ShiftOnDate element : shiftOnElementList) {
ShiftOnRequest shiftOnRequest = new ShiftOnRequest();
long ShiftonId = element.getId();
int weight = element.getWeight();
Employee employee = element.getEmployee();
Employee workingEmployee = scoreDirector.lookUpWorkingObject(employee);
LocalDate date1 = element.getDate();
String shiftcode = element.getShiftType().getCode();
Shift shift = dateAndShiftTypeToShiftMap.get(Pair.of(date1, shiftcode));
shiftOnRequest.setId(ShiftonId);
shiftOnRequest.setEmployee(workingEmployee);
shiftOnRequest.setShift(shift);
shiftOnRequest.setWeight(weight);
shiftOnRequestList.add(shiftOnRequest);
workingEmployee.getShiftOnRequestMap().put(shift, shiftOnRequest);
nurseRoster.setShiftOnRequestList(shiftOnRequestList);
}
List<CoverRequirements> coverRequirementElementList1 = (List<CoverRequirements>) rosterService
.listCoverRequirements();
for (CoverRequirements element : coverRequirementElementList1) {
String type = element.getShiftType().getCode();
DayOfWeek day = element.getDayOfWeek();
int req = element.getRequiredEmployeesize();
ShiftType shiftType = shiftTypeMap.get(type);
Pair<DayOfWeek, ShiftType> key = Pair.of(day, shiftType);
List<Shift> shiftList = dayOfWeekAndShiftTypeToShiftListMap
.get(key);
for (Shift shift : shiftList) {
shift.setRequiredEmployeeSize(
shift.getRequiredEmployeeSize() + req);
}
}
List<ShiftAssignment> shiftAssignmentList = new ArrayList<>(
shiftList1.size());
long shiftAssignmentId = nurseRoster.getShiftAssignmentList()
.get(nurseRoster.getShiftAssignmentList().size() - 1)
.getId() + 1L;
for (Shift shift : shiftList1) {
for (int i = 0; i < shift.getRequiredEmployeeSize(); i++) {
ShiftAssignment newShiftAssignment = new ShiftAssignment();
newShiftAssignment.setId(shiftAssignmentId);
shiftAssignmentId++;
newShiftAssignment.setShift(shift);
newShiftAssignment.setIndexInShift(i);
shiftAssignmentList.add(newShiftAssignment);
nurseRoster.getShiftAssignmentList()
.add(newShiftAssignment);
scoreDirector.afterEntityAdded(newShiftAssignment);
}
}
//This should move the planning window
nurseRosterParametrization.setFirstShiftDate(shiftDateList1.get(0));
nurseRosterParametrization.setLastShiftDate(shiftDateList1.get(shiftDateList1.size() - 1));
nurseRosterParametrization.setPlanningWindowStart(shiftDateList1.get(0));
nurseRoster.setNurseRosterParametrization(nurseRosterParametrization);
scoreDirector.afterProblemPropertyChanged(nurseRosterParametrization);
scoreDirector.triggerVariableListeners();
}, true);
}

Encountering problems with JSFiddle code

I have recently written a piece of code that checks temperature over a period of time for some course work. i wrote the program using different bits of code but cannot find the issue to some of the problems i am encountering.
I was just wondering if anyone can see any obvious errors that i am missing and could help out with some information int he right direction.
Link to the JSFiddle
//Counting the average temperatures in a day
//needs debugged!!!
var temperatures = [];
var total = 0;
function getCity() {
//get the locale to help with the display
city = prompt("Enter your city >> ");
}
function getNumDays() {
number = prompt("How many days in the study? Enter 1 - 10");
while ((number < 1) || (number > 10) ||( isNaN(number) === true)) {
alert ("Invalid input!");
number = prompt ("Enter again, 1 - 10 >> ");}
return number;
}
function getTemps(numDays) {
total = 0;
for (i = 0; i < numDays; i++) {
next = prompt ("Enter the temperature for day " + (i+1));
next = parseint(next);
while (isNaN(next)===true) {
next = 0;
next = prompt ("Error in input! Try again >>");
next = parseInt(next);}
temperatures.push(next);
}
total = total + next;
return temperatures;
}
function calcAverage(total, numDays) {
average = total / numDays;
return average;
}
function showStatistics(city, average, numdays) {
alert ("The average daily temperature for "+ city + " is " + average.toFixed(2) + " measured over " + numDays + " days." );
}
//main program
city = getCity();
numDays = getNumDays();
temperatures = getTemps(numDays);
Average = calcAverage(total, numDays);
showStatistics(city, average, numDays);
function getCity() {
//get the locale to help with the display
city = prompt("Enter your city >> ");
}
//main program
city = getCity();
Looks like you're missing a return statement.
Additionally, the line total = total + next; seems to be out of place: I imagine the total to be the total of the temperatures, not 0 + temperatureOfLastDay.