Could you tell me what is wrong with this program and fix it? Thank you Create a
ID: 3621687 • Letter: C
Question
Could you tell me what is wrong with this program and fix it?
Thank you
Create a program that includes an array that holds 31 integers. This array represents the high temperature for each day in a month. Request the month from the user then the temperature for each of the days (months have different number of days).
Output: the average temperature, highest temperature, lowest temperature and the difference between the warmest and coldest day.
import java.util.ArrayList;
import java.util.Scanner;
/**
* Write a description of class Temperarture here.
*
* @author ()
* @version ()
*/
public class Temperature{
// instance variables - replace the example below with your own
private ArrayList monthTemperatures;
private int month;
/**
* Constructor for objects of class Temperature
*/
public Temperature(){
// initialize instance variables
monthTemperatures = new ArrayList();
}
public void storeNumTemp(){
readMonth();
int monthdays = getNumDays(month);
monthdays=31;
System.out.println("Entered Month: " + month + " Number of days for this month: " + monthdays);
for(int i=0; i
int temperature = scanTemp();
//monthTemperatures.add(temperature);
monthTemperatures.add(i, temperature);
}
for(int temp : monthTemperatures){
System.out.println(temp);
}
System.out.println("HighesTemp: " + getHighestTemp() + " LowestTemp: " + getLowestTemp() );
}
public int getHighestTemp(){
int highestTemp = 0;
for(int i=0;i
int temp = monthTemperatures.get(i);
if(temp>highestTemp)
highestTemp = temp;
}
return highestTemp;
}
public int getLowestTemp(){
int lowestTemp = 999999999;
for(int i=0;i
int temp = monthTemperatures.get(i);
if(temp
lowestTemp = temp;
}
return lowestTemp;
}
private void readMonth(){
Scanner scan = new Scanner(System.in);{
System.out.print("Enter Month Number: ");
month = scan.nextInt();
}
}
private int getNumDays(int month){
int days=0;
switch(month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: days=31;
break;
case 2: days=28;
break;
case 4:
case 6:
case 9:
case 11: days=30;
break;
default: days=0;
}
return days;
}
private int scanTemp()
{
int dayTemp;
Scanner scan = new Scanner(System.in);
{
System.out.print("Enter day Temperature ");
dayTemp = scan.nextInt();
}
return dayTemp;
}
public void totalTemp(){
int totalTemp=0;
for(int i=0; i
totalTemp += monthTemperatures.get(i);
}
System.out.println("Average Temperature for" + month + " is:" +(totalTemp/ monthTemperatures.size()));
}
}