SlideShare a Scribd company logo
1 of 20
Download to read offline
Please fix the java code (using eclipse)
package hw4p1;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class MeanMedianHWv2 {
public static void main(String[] args) throws IOException {
String[] arrDate = { "", "", "","" };
Scanner in = new Scanner(System.in);
Boolean day = true;
// Year
do
{
System.out.println("Enter a year (2016)");
arrDate[0] = in.next();
if (!arrDate[0].equalsIgnoreCase("2016"))
{
System.out.println("Wrong Input. '2016' only! Try again.");
}
else
{
arrDate[0] = "2016";
}
} while(!arrDate[0].equalsIgnoreCase("2016"));
// Month
do
{
System.out.println("Enter a month (01)");
arrDate[1] = in.next();
if (!arrDate[1].equalsIgnoreCase("01"))
{
System.out.println("Wrong Input. '01' only! Try again!");
}
else
{
arrDate[1] = "01";
}
} while(!arrDate[1].equalsIgnoreCase("01"));
// Day
do
{
System.out.println("Enter a Day (04-10)");
arrDate[2] = in.next();
//if (arrDate[2] > 10 || arrDate[2] < 4)
if (!arrDate[2].equalsIgnoreCase("04"))
{
System.out.println("Wrong Inpit. '04' - '10' only! Try again!");
}
//else if (arrDate[2] == 4)
else if (!arrDate[2].equalsIgnoreCase("05"))
{
System.out.println("Error! Invalid day. Try again!");
}
else if (!arrDate[2].equalsIgnoreCase("06"))
{
System.out.println("Error! Invalid day. Try again!");
}
else if (!arrDate[2].equalsIgnoreCase("07"))
{
System.out.println("Error! Invalid day. Try again!");
}
else if (!arrDate[2].equalsIgnoreCase("08"))
{
System.out.println("Error! Invalid day. Try again!");
}
else if (!arrDate[2].equalsIgnoreCase("09"))
{
System.out.println("Error! Invalid day. Try again!");
}
else if (!arrDate[2].equalsIgnoreCase("10"))
{
System.out.println("Error! Invalid day. Try again!");
}
else
{
arrDate[2] = "04";
day = false;
arrDate[2] = "05";
day = false;
arrDate[2] = "06";
day = false;
arrDate[2] = "07";
day = false;
arrDate[2] = "08";
day = false;
arrDate[2] = "09";
day = false;
arrDate[2] = "10";
day = false;
}
} while (day);
do {
System.out.println("which data? 'w' for wind, 'b' for baro pressure, 't' for temp");
arrDate[3] = in.next();
if (!arrDate[3]. equalsIgnoreCase ("w") && !arrDate[3].equalsIgnoreCase("b") &&
!arrDate[3].equalsIgnoreCase("t"))
{
System.out.println("Wrong input. 'w' / 'b' / 't' only! Try again");
}
//while(!arrDate[2].equalsIgnoreCase("04") && !arrDate[2].equalsIgnoreCase("05") &&
!arrDate[2].equalsIgnoreCase("05"));
if (arrDate[3].equalsIgnoreCase("w"))
{
System.out.println("w");
}
else if (arrDate[3].equalsIgnoreCase("b"))
{
System.out.println("b");
}
else if (arrDate[3].equalsIgnoreCase("t"))
{
System.out.println("t");
}
} while (!arrDate[3].equalsIgnoreCase("w") && !arrDate[3].equalsIgnoreCase("b") &&
!arrDate[3].equalsIgnoreCase("t"));
in.close();
String Date = arrDate[0] + "_" + arrDate[1] + "_" + arrDate[2];
System.out.println("------------------------------------");
System.out.println("What you typed in is below");
System.out.println("Date" + Date);
System.out.println("Date :" + arrDate[3]);
System.out.println("-----------------------------------");
if (arrDate[3].equalsIgnoreCase("w"))
{
ArrayList windGust = getWindData(Date.arrDate);
System.out.println("Wind Gust");
System.out.println(" Results of" + Date + "");
System.out.println("mean :" + mean(windGust));
System.out.println("Median: " + median(windGust));
System.out.println("-----------------------------------");
}
else {arrDate[3].equalsIgnoreCase("b");
{
ArrayList pressure = getPData(Date, arrDate);
System.out.println("Pressure");
System.out.println(" Results of" + Date + "");
System.out.println("mean :" + mean(pressure));
System.out.println("Median: " + median(pressure));
System.out.println("-----------------------------------");
}
else
{
ArrayList airTemp = getTdata(Date, arrDate);
System.out.println("Temperature");
System.out.println(" Results of" + Date + "");
System.out.println("mean :" + mean(airTemp));
System.out.println("Median: " + median(airTemp));
System.out.println("-----------------------------------");
}
System.out.println("Printing all data");
ArrayListweaData = getAllData(Date, arrDate);
displayData(weaData);
}
// System.out.println("Sll Data");
// System.out.println(" Results of" + Date + "");
// else
// {
// ArrayList tempData = getbaroData(arrDate);
// }
//ArrayList barodata = getbaroData(arrDate);
//ArrayList airTemp = getData("Air_Temp", arrDate);
//ArrayList pressure = getData("Barometric_Press", arrDate);
// System.out.println("Gust: mean " + mean(windGust) + ", median " +
median(windGust));
// //System.out.println("Temp: mean " + mean(airTemp) + ", median " +
median(airTemp));
// //System.out.println("Pressure: mean " + mean(pressure) + ", median " +
median(pressure));
//
// displayData(weaData);
// }
// GEtting wind data
public static ArrayList getWindData(String Date, String [] arrDt) throws
NumberFormatException, IOException {
// construct the url if necessary
//URL dataSource = new URL("https://lpo.dt.navy.mil/data/DM/" + arrDt[0] + "/" +
arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] + "/" + label);
//URL url = new URL("http://umd-fmis.d.umn.edu/cpblee/weather.txt");
//URL url = new URL("http://umd-
fmis.d.umn.edu/cpblee/data/2016/2016_01_04/2016_01_04.txt");
String newurl = "http://umd-fmis.d.umn.edu/cpblee/data/" + Date + "/" + Date + ".txt";
System.out.println("Searching " + newurl);
URL url = new URL(newurl);
//URL url = new URL("http://umd-fmis.d.umn.edu/cpblee/data/" + arrDt[0] + "/" + arrDt[0] +
"_" + arrDt[1] + "_" + arrDt[2] +"/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2]
+".txt/");
BufferedReader buffer = new BufferedReader(new
InputStreamReader(url.openConnection().getInputStream()));
// get wind gust data
ArrayList windData = new ArrayList();
String inputLine;
while ((inputLine = buffer.readLine()) != null) {
windData.add(Double.parseDouble(inputLine.substring(20,22)));
}
buffer.close();
return windData;
}
// Getting temp data.
public static ArrayList gettempData(String[] arrDt) throws NumberFormatException,
IOException {
// construct the url if necessary
//URL dataSource = new URL("https://lpo.dt.navy.mil/data/DM/" + arrDt[0] + "/" +
arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] + "/" + label); URL url = new
URL("http://umd-fmis.d.umn.edu/cpblee/data/" + arrDt[0] + "/" + arrDt[0] + "_" + arrDt[1]
+ "_" + arrDt[2] +".txt/");
URL url = new URL("http://umd-fmis.d.umn.edu/cpblee/data/" + arrDt[0] + "/" +
arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] +"/" + arrDt[0] + "_" + arrDt[1] + "_" +
arrDt[2] +".txt/");
BufferedReader buffer = new BufferedReader(new
InputStreamReader(url.openConnection().getInputStream()));
// alternatively,
//BufferedReader data = new BufferedReader(new
InputStreamReader(dataSource.openStream()));
// get wind gust data
ArrayList tempData = new ArrayList();
String inputLine;
while ((inputLine = buffer.readLine()) != null) {
tempData.add(Double.parseDouble(inputLine.substring(20)));
}
buffer.close();
return tempData;
}
// Getting Baro Data.
public static ArrayList getbaroData(String[] arrDt) throws NumberFormatException,
IOException {
// construct the url if necessary
//URL dataSource = new URL("https://lpo.dt.navy.mil/data/DM/" + arrDt[0] + "/" +
arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] + "/" + label); URL url = new
URL("http://umd-fmis.d.umn.edu/cpblee/data/" + arrDt[0] + "/" + arrDt[0] + "_" + arrDt[1]
+ "_" + arrDt[2] +".txt/");
URL url = new URL("http://umd-fmis.d.umn.edu/cpblee/data/" + arrDt[0] + "/" +
arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] +"/" + arrDt[0] + "_" + arrDt[1] + "_" +
arrDt[2] +".txt/");
BufferedReader buffer = new BufferedReader(new
InputStreamReader(url.openConnection().getInputStream()));
// alternatively,
//BufferedReader data = new BufferedReader(new
InputStreamReader(dataSource.openStream()));
// get wind gust data
ArrayList baroData = new ArrayList();
String inputLine;
while ((inputLine = buffer.readLine()) != null) {
baroData.add(Double.parseDouble(inputLine.substring(20)));
}
buffer.close();
return baroData;
}
//GEtting all data
public static ArrayList getAllData(String[] arrDt) throws NumberFormatException,
IOException {
//URL dataSource = new URL("https://lpo.dt.navy.mil/data/DM/" + arrDt[0] + "/" +
arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] + "/" + label);
//URL url = new URL("http://umd-
fmis.d.umn.edu/cpblee/data/2016/2016_01_04/2016_01_04.txt");
//URL url = new URL("http://umd-fmis.d.umn.edu/cpblee/data/" + arrDt[0] + "/" +
arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] +"/" + arrDt[0] + "_" + arrDt[1] + "_" +
arrDt[2] +".txt");
URL url = new URL ("http://umd-fmis.d.umn.edu/cpblee/data/2016/ + arrData[0] + “_”+
arrDt[1]” + “_” + arrDt[2]+“/”+“ arrDt[0]” + “_”+ “arrDt[1]” + “_” + arrDt[2]+“.txt”");
// http://umd-fmis.d.umn.edu/cpblee/data/2016/2016_01_04/2016_01_04.txt
BufferedReader buffer = new BufferedReader(new
InputStreamReader(url.openConnection().getInputStream()));
//BufferedReader data = new BufferedReader(new
InputStreamReader(dataSource.openStream()));
// get date, time, and wind gust data (replicate data)
ArrayList allData = new ArrayList();
String inputLine;
while ((inputLine = buffer.readLine()) != null) {
allData.add(inputLine.substring(0));
}
buffer.close();
return allData;
}
public static void displayData(ArrayList a) {
for (String s : a) {
System.out.println(s);
}
}
public static double mean(ArrayList a)
{
double sum = 0;
for (double i : a) {
sum += i;
}
return sum / a.size();
}
public static double median(ArrayList a)
{
Collections.sort(a);
if (a.size() / 2 * 2 == a.size()) {
return (a.get(a.size() / 2) + a.get(a.size() / 2 - 1)) / 2;
} else {
return a.get(a.size() / 2);
}
}
}
**** this is the error i am getting:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
arrDate cannot be resolved or is not a field
arrDate cannot be resolved to a variable
Syntax error on token "else", delete this token
arrDate cannot be resolved to a variable
arrDate cannot be resolved to a variable
Syntax error, insert "}" to complete Block
at hw4p1.MeanMedianHWv2.main(MeanMedianHWv2.java:153)
Solution
There is a minor mistake in the else block you wrote. You just mistyped it seems. An open
paranthesis ( should be there in the else if condition, but you used open braces { it seems. Here is
the modificeation for you:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class MeanMedian {
public static void main(String[] args) throws IOException {
String[] arrDate = { "", "", "","" };
Scanner in = new Scanner(System.in);
Boolean day = true;
// Year
do
{
System.out.println("Enter a year (2016)");
arrDate[0] = in.next();
if (!arrDate[0].equalsIgnoreCase("2016"))
{
System.out.println("Wrong Input. '2016' only! Try again.");
}
else
{
arrDate[0] = "2016";
}
} while(!arrDate[0].equalsIgnoreCase("2016"));
// Month
do
{
System.out.println("Enter a month (01)");
arrDate[1] = in.next();
if (!arrDate[1].equalsIgnoreCase("01"))
{
System.out.println("Wrong Input. '01' only! Try again!");
}
else
{
arrDate[1] = "01";
}
} while(!arrDate[1].equalsIgnoreCase("01"));
// Day
do
{
System.out.println("Enter a Day (04-10)");
arrDate[2] = in.next();
//if (arrDate[2] > 10 || arrDate[2] < 4)
if (!arrDate[2].equalsIgnoreCase("04"))
{
System.out.println("Wrong Inpit. '04' - '10' only! Try again!");
}
//else if (arrDate[2] == 4)
else if (!arrDate[2].equalsIgnoreCase("05"))
{
System.out.println("Error! Invalid day. Try again!");
}
else if (!arrDate[2].equalsIgnoreCase("06"))
{
System.out.println("Error! Invalid day. Try again!");
}
else if (!arrDate[2].equalsIgnoreCase("07"))
{
System.out.println("Error! Invalid day. Try again!");
}
else if (!arrDate[2].equalsIgnoreCase("08"))
{
System.out.println("Error! Invalid day. Try again!");
}
else if (!arrDate[2].equalsIgnoreCase("09"))
{
System.out.println("Error! Invalid day. Try again!");
}
else if (!arrDate[2].equalsIgnoreCase("10"))
{
System.out.println("Error! Invalid day. Try again!");
}
else
{
arrDate[2] = "04";
day = false;
arrDate[2] = "05";
day = false;
arrDate[2] = "06";
day = false;
arrDate[2] = "07";
day = false;
arrDate[2] = "08";
day = false;
arrDate[2] = "09";
day = false;
arrDate[2] = "10";
day = false;
}
} while (day);
do {
System.out.println("which data? 'w' for wind, 'b' for baro pressure, 't' for temp");
arrDate[3] = in.next();
if (!arrDate[3]. equalsIgnoreCase ("w") && !arrDate[3].equalsIgnoreCase("b") &&
!arrDate[3].equalsIgnoreCase("t"))
{
System.out.println("Wrong input. 'w' / 'b' / 't' only! Try again");
}
//while(!arrDate[2].equalsIgnoreCase("04") && !arrDate[2].equalsIgnoreCase("05") &&
!arrDate[2].equalsIgnoreCase("05"));
if (arrDate[3].equalsIgnoreCase("w"))
{
System.out.println("w");
}
else if (arrDate[3].equalsIgnoreCase("b"))
{
System.out.println("b");
}
else if (arrDate[3].equalsIgnoreCase("t"))
{
System.out.println("t");
}
} while (!arrDate[3].equalsIgnoreCase("w") && !arrDate[3].equalsIgnoreCase("b") &&
!arrDate[3].equalsIgnoreCase("t"));
in.close();
String Date = arrDate[0] + "_" + arrDate[1] + "_" + arrDate[2];
System.out.println("------------------------------------");
System.out.println("What you typed in is below");
System.out.println("Date" + Date);
System.out.println("Date :" + arrDate[3]);
System.out.println("-----------------------------------");
if (arrDate[3].equalsIgnoreCase("w"))
{
ArrayList windGust = getWindData(Date.arrDate);
System.out.println("Wind Gust");
System.out.println(" Results of" + Date + "");
System.out.println("mean :" + mean(windGust));
System.out.println("Median: " + median(windGust));
System.out.println("-----------------------------------");
}
else if(arrDate[3].equalsIgnoreCase("b"))
{
ArrayList pressure = getPData(Date, arrDate);
System.out.println("Pressure");
System.out.println(" Results of" + Date + "");
System.out.println("mean :" + mean(pressure));
System.out.println("Median: " + median(pressure));
System.out.println("-----------------------------------");
}
else
{
ArrayList airTemp = getTdata(Date, arrDate);
System.out.println("Temperature");
System.out.println(" Results of" + Date + "");
System.out.println("mean :" + mean(airTemp));
System.out.println("Median: " + median(airTemp));
System.out.println("-----------------------------------");
}
System.out.println("Printing all data");
ArrayListweaData = getAllData(arrDate);
displayData(weaData);
}
// System.out.println("Sll Data");
// System.out.println(" Results of" + Date + "");
// else
// {
// ArrayList tempData = getbaroData(arrDate);
// }
//ArrayList barodata = getbaroData(arrDate);
//ArrayList airTemp = getData("Air_Temp", arrDate);
//ArrayList pressure = getData("Barometric_Press", arrDate);
// System.out.println("Gust: mean " + mean(windGust) + ", median " + median(windGust));
// //System.out.println("Temp: mean " + mean(airTemp) + ", median " + median(airTemp));
// //System.out.println("Pressure: mean " + mean(pressure) + ", median " +
median(pressure));
//
// displayData(weaData);
// }
// GEtting wind data
public static ArrayList getWindData(String Date, String [] arrDt) throws
NumberFormatException, IOException {
// construct the url if necessary
//URL dataSource = new URL("https://lpo.dt.navy.mil/data/DM/" + arrDt[0] + "/" + arrDt[0]
+ "_" + arrDt[1] + "_" + arrDt[2] + "/" + label);
//URL url = new URL("http://umd-fmis.d.umn.edu/cpblee/weather.txt");
//URL url = new URL("http://umd-
fmis.d.umn.edu/cpblee/data/2016/2016_01_04/2016_01_04.txt");
String newurl = "http://umd-fmis.d.umn.edu/cpblee/data/" + Date + "/" + Date + ".txt";
System.out.println("Searching " + newurl);
URL url = new URL(newurl);
//URL url = new URL("http://umd-fmis.d.umn.edu/cpblee/data/" + arrDt[0] + "/" + arrDt[0] +
"_" + arrDt[1] + "_" + arrDt[2] +"/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2]
+".txt/");
BufferedReader buffer = new BufferedReader(new
InputStreamReader(url.openConnection().getInputStream()));
// get wind gust data
ArrayList windData = new ArrayList();
String inputLine;
while ((inputLine = buffer.readLine()) != null) {
windData.add(Double.parseDouble(inputLine.substring(20,22)));
}
buffer.close();
return windData;
}
// Getting temp data.
public static ArrayList gettempData(String[] arrDt) throws NumberFormatException,
IOException {
// construct the url if necessary
//URL dataSource = new URL("https://lpo.dt.navy.mil/data/DM/" + arrDt[0] + "/" + arrDt[0]
+ "_" + arrDt[1] + "_" + arrDt[2] + "/" + label); URL url = new URL("http://umd-
fmis.d.umn.edu/cpblee/data/" + arrDt[0] + "/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2]
+".txt/");
URL url = new URL("http://umd-fmis.d.umn.edu/cpblee/data/" + arrDt[0] + "/" + arrDt[0] +
"_" + arrDt[1] + "_" + arrDt[2] +"/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2]
+".txt/");
BufferedReader buffer = new BufferedReader(new
InputStreamReader(url.openConnection().getInputStream()));
// alternatively,
//BufferedReader data = new BufferedReader(new
InputStreamReader(dataSource.openStream()));
// get wind gust data
ArrayList tempData = new ArrayList();
String inputLine;
while ((inputLine = buffer.readLine()) != null) {
tempData.add(Double.parseDouble(inputLine.substring(20)));
}
buffer.close();
return tempData;
}
// Getting Baro Data.
public static ArrayList getbaroData(String[] arrDt) throws NumberFormatException,
IOException {
// construct the url if necessary
//URL dataSource = new URL("https://lpo.dt.navy.mil/data/DM/" + arrDt[0] + "/" + arrDt[0]
+ "_" + arrDt[1] + "_" + arrDt[2] + "/" + label); URL url = new URL("http://umd-
fmis.d.umn.edu/cpblee/data/" + arrDt[0] + "/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2]
+".txt/");
URL url = new URL("http://umd-fmis.d.umn.edu/cpblee/data/" + arrDt[0] + "/" + arrDt[0] +
"_" + arrDt[1] + "_" + arrDt[2] +"/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2]
+".txt/");
BufferedReader buffer = new BufferedReader(new
InputStreamReader(url.openConnection().getInputStream()));
// alternatively,
//BufferedReader data = new BufferedReader(new
InputStreamReader(dataSource.openStream()));
// get wind gust data
ArrayList baroData = new ArrayList();
String inputLine;
while ((inputLine = buffer.readLine()) != null) {
baroData.add(Double.parseDouble(inputLine.substring(20)));
}
buffer.close();
return baroData;
}
//GEtting all data
public static ArrayList getAllData(String[] arrDt) throws NumberFormatException,
IOException {
//URL dataSource = new URL("https://lpo.dt.navy.mil/data/DM/" + arrDt[0] + "/" + arrDt[0]
+ "_" + arrDt[1] + "_" + arrDt[2] + "/" + label);
//URL url = new URL("http://umd-
fmis.d.umn.edu/cpblee/data/2016/2016_01_04/2016_01_04.txt");
//URL url = new URL("http://umd-fmis.d.umn.edu/cpblee/data/" + arrDt[0] + "/" + arrDt[0]
+ "_" + arrDt[1] + "_" + arrDt[2] +"/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2]
+".txt");
URL url = new URL ("http://umd-fmis.d.umn.edu/cpblee/data/2016/ + arrData[0] + “_”+
arrDt[1]” + “_” + arrDt[2]+“/”+“ arrDt[0]” + “_”+ “arrDt[1]” + “_” + arrDt[2]+“.txt”");
// http://umd-fmis.d.umn.edu/cpblee/data/2016/2016_01_04/2016_01_04.txt
BufferedReader buffer = new BufferedReader(new
InputStreamReader(url.openConnection().getInputStream()));
//BufferedReader data = new BufferedReader(new
InputStreamReader(dataSource.openStream()));
// get date, time, and wind gust data (replicate data)
ArrayList allData = new ArrayList();
String inputLine;
while ((inputLine = buffer.readLine()) != null) {
allData.add(inputLine.substring(0));
}
buffer.close();
return allData;
}
public static void displayData(ArrayList a) {
for (String s : a) {
System.out.println(s);
}
}
public static double mean(ArrayList a)
{
double sum = 0;
for (double i : a) {
sum += i;
}
return sum / a.size();
}
public static double median(ArrayList a)
{
Collections.sort(a);
if (a.size() / 2 * 2 == a.size()) {
return (a.get(a.size() / 2) + a.get(a.size() / 2 - 1)) / 2;
} else {
return a.get(a.size() / 2);
}
}
}
And may be you tried some methods which are not here it seems. Anyways, if you still need any
refinements, just get back to me.

More Related Content

Similar to Please fix the java code (using eclipse)package hw4p1;import jav.pdf

Modify the project so tat records are inserted into the random acess.pdf
Modify the project so tat records are inserted into the random acess.pdfModify the project so tat records are inserted into the random acess.pdf
Modify the project so tat records are inserted into the random acess.pdf
fcaindore
 
ikh331-06-distributed-programming
ikh331-06-distributed-programmingikh331-06-distributed-programming
ikh331-06-distributed-programming
Anung Ariwibowo
 
Create a JAVA program that performs file IO and database interaction.pdf
Create a JAVA program that performs file IO and database interaction.pdfCreate a JAVA program that performs file IO and database interaction.pdf
Create a JAVA program that performs file IO and database interaction.pdf
malavshah9013
 
Modify this code to change the underlying data structure to .pdf
Modify this code to change the underlying data structure to .pdfModify this code to change the underlying data structure to .pdf
Modify this code to change the underlying data structure to .pdf
adityaenterprise32
 
JavaI have the full code complete i just need it to be replace th.pdf
JavaI have the full code complete i just need it to be replace th.pdfJavaI have the full code complete i just need it to be replace th.pdf
JavaI have the full code complete i just need it to be replace th.pdf
jeeteshmalani1
 
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docxWeb CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
celenarouzie
 
DAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docx
DAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docxDAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docx
DAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docx
theodorelove43763
 
Java programs
Java programsJava programs
Java programs
jojeph
 
Write a program (any language) to randomly generate the following se.pdf
Write a program (any language) to randomly generate the following se.pdfWrite a program (any language) to randomly generate the following se.pdf
Write a program (any language) to randomly generate the following se.pdf
archanaemporium
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
Abed Bukhari
 

Similar to Please fix the java code (using eclipse)package hw4p1;import jav.pdf (20)

QA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QA Fest 2019. Saar Rachamim. Developing Tools, While TestingQA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QA Fest 2019. Saar Rachamim. Developing Tools, While Testing
 
Modify the project so tat records are inserted into the random acess.pdf
Modify the project so tat records are inserted into the random acess.pdfModify the project so tat records are inserted into the random acess.pdf
Modify the project so tat records are inserted into the random acess.pdf
 
ikh331-06-distributed-programming
ikh331-06-distributed-programmingikh331-06-distributed-programming
ikh331-06-distributed-programming
 
AJUG April 2011 Cascading example
AJUG April 2011 Cascading exampleAJUG April 2011 Cascading example
AJUG April 2011 Cascading example
 
Tugas 2
Tugas 2Tugas 2
Tugas 2
 
Create a JAVA program that performs file IO and database interaction.pdf
Create a JAVA program that performs file IO and database interaction.pdfCreate a JAVA program that performs file IO and database interaction.pdf
Create a JAVA program that performs file IO and database interaction.pdf
 
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash course
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash courseCodepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash course
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash course
 
Code
CodeCode
Code
 
Modify this code to change the underlying data structure to .pdf
Modify this code to change the underlying data structure to .pdfModify this code to change the underlying data structure to .pdf
Modify this code to change the underlying data structure to .pdf
 
DCN Practical
DCN PracticalDCN Practical
DCN Practical
 
JavaI have the full code complete i just need it to be replace th.pdf
JavaI have the full code complete i just need it to be replace th.pdfJavaI have the full code complete i just need it to be replace th.pdf
JavaI have the full code complete i just need it to be replace th.pdf
 
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docxWeb CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
 
DAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docx
DAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docxDAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docx
DAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docx
 
Wprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
Wprowadzenie do technologii Big Data / Intro to Big Data EcosystemWprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
Wprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
201913001 khairunnisa progres_harian
201913001 khairunnisa progres_harian201913001 khairunnisa progres_harian
201913001 khairunnisa progres_harian
 
Fia fabila
Fia fabilaFia fabila
Fia fabila
 
Java programs
Java programsJava programs
Java programs
 
Write a program (any language) to randomly generate the following se.pdf
Write a program (any language) to randomly generate the following se.pdfWrite a program (any language) to randomly generate the following se.pdf
Write a program (any language) to randomly generate the following se.pdf
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 

More from info961251

With which portion of an epithelial cell in the stomach would food be.pdf
With which portion of an epithelial cell in the stomach would food be.pdfWith which portion of an epithelial cell in the stomach would food be.pdf
With which portion of an epithelial cell in the stomach would food be.pdf
info961251
 
Which of the following correctly states the functions of the roug.pdf
Which of the following correctly states the functions of the roug.pdfWhich of the following correctly states the functions of the roug.pdf
Which of the following correctly states the functions of the roug.pdf
info961251
 
What is the definition of the words, and state the diffe.pdf
What is the definition of the words, and state the diffe.pdfWhat is the definition of the words, and state the diffe.pdf
What is the definition of the words, and state the diffe.pdf
info961251
 
TB is a major worldwide disease with new cases arising at an alarmin.pdf
TB is a major worldwide disease with new cases arising at an alarmin.pdfTB is a major worldwide disease with new cases arising at an alarmin.pdf
TB is a major worldwide disease with new cases arising at an alarmin.pdf
info961251
 
Question 1Theories of Law Subject__________ is a collaborative.pdf
Question 1Theories of Law Subject__________ is a collaborative.pdfQuestion 1Theories of Law Subject__________ is a collaborative.pdf
Question 1Theories of Law Subject__________ is a collaborative.pdf
info961251
 
Overview You are tasked with writing a program called Social Security.pdf
Overview You are tasked with writing a program called Social Security.pdfOverview You are tasked with writing a program called Social Security.pdf
Overview You are tasked with writing a program called Social Security.pdf
info961251
 
A geneticist Dr. O. Sophila discovers a new mutation that causes the .pdf
A geneticist Dr. O. Sophila discovers a new mutation that causes the .pdfA geneticist Dr. O. Sophila discovers a new mutation that causes the .pdf
A geneticist Dr. O. Sophila discovers a new mutation that causes the .pdf
info961251
 

More from info961251 (20)

With which portion of an epithelial cell in the stomach would food be.pdf
With which portion of an epithelial cell in the stomach would food be.pdfWith which portion of an epithelial cell in the stomach would food be.pdf
With which portion of an epithelial cell in the stomach would food be.pdf
 
Write the interface (.h file) of a class Accumulator containing A d.pdf
Write the interface (.h file) of a class Accumulator containing  A d.pdfWrite the interface (.h file) of a class Accumulator containing  A d.pdf
Write the interface (.h file) of a class Accumulator containing A d.pdf
 
You are carrying out PCRs in lab. Why do you not need helicase, SSB,.pdf
You are carrying out PCRs in lab. Why do you not need helicase, SSB,.pdfYou are carrying out PCRs in lab. Why do you not need helicase, SSB,.pdf
You are carrying out PCRs in lab. Why do you not need helicase, SSB,.pdf
 
Write your own definition of cloning. No plagarism!SolutionClo.pdf
Write your own definition of cloning. No plagarism!SolutionClo.pdfWrite your own definition of cloning. No plagarism!SolutionClo.pdf
Write your own definition of cloning. No plagarism!SolutionClo.pdf
 
Write appropriate SQL DDL statements (Create Table Statements) for d.pdf
Write appropriate SQL DDL statements (Create Table Statements) for d.pdfWrite appropriate SQL DDL statements (Create Table Statements) for d.pdf
Write appropriate SQL DDL statements (Create Table Statements) for d.pdf
 
Write a class called Student that extends the provided Person class..pdf
Write a class called Student that extends the provided Person class..pdfWrite a class called Student that extends the provided Person class..pdf
Write a class called Student that extends the provided Person class..pdf
 
why NADH and FADH2 are a type of energy currencySolutionEnergy.pdf
why NADH and FADH2 are a type of energy currencySolutionEnergy.pdfwhy NADH and FADH2 are a type of energy currencySolutionEnergy.pdf
why NADH and FADH2 are a type of energy currencySolutionEnergy.pdf
 
Who is D.L ShellSolutionHi friend,Donald L. Shell (March 1,.pdf
Who is D.L ShellSolutionHi friend,Donald L. Shell (March 1,.pdfWho is D.L ShellSolutionHi friend,Donald L. Shell (March 1,.pdf
Who is D.L ShellSolutionHi friend,Donald L. Shell (March 1,.pdf
 
Which of the following correctly states the functions of the roug.pdf
Which of the following correctly states the functions of the roug.pdfWhich of the following correctly states the functions of the roug.pdf
Which of the following correctly states the functions of the roug.pdf
 
What is isomerism How many kinds are there Define each kind and.pdf
What is isomerism How many kinds are there Define each kind and.pdfWhat is isomerism How many kinds are there Define each kind and.pdf
What is isomerism How many kinds are there Define each kind and.pdf
 
What is the definition of the words, and state the diffe.pdf
What is the definition of the words, and state the diffe.pdfWhat is the definition of the words, and state the diffe.pdf
What is the definition of the words, and state the diffe.pdf
 
Two sources of radio waves (call them 1 and 2) are separated by a dis.pdf
Two sources of radio waves (call them 1 and 2) are separated by a dis.pdfTwo sources of radio waves (call them 1 and 2) are separated by a dis.pdf
Two sources of radio waves (call them 1 and 2) are separated by a dis.pdf
 
Use the information in the table to select the image that represents .pdf
Use the information in the table to select the image that represents .pdfUse the information in the table to select the image that represents .pdf
Use the information in the table to select the image that represents .pdf
 
Triggers can only be used to update table values. PLSQL blocks have.pdf
Triggers can only be used to update table values.  PLSQL blocks have.pdfTriggers can only be used to update table values.  PLSQL blocks have.pdf
Triggers can only be used to update table values. PLSQL blocks have.pdf
 
TB is a major worldwide disease with new cases arising at an alarmin.pdf
TB is a major worldwide disease with new cases arising at an alarmin.pdfTB is a major worldwide disease with new cases arising at an alarmin.pdf
TB is a major worldwide disease with new cases arising at an alarmin.pdf
 
7. How did printing technology impact literacy and educationSol.pdf
7. How did printing technology impact literacy and educationSol.pdf7. How did printing technology impact literacy and educationSol.pdf
7. How did printing technology impact literacy and educationSol.pdf
 
Question 1Theories of Law Subject__________ is a collaborative.pdf
Question 1Theories of Law Subject__________ is a collaborative.pdfQuestion 1Theories of Law Subject__________ is a collaborative.pdf
Question 1Theories of Law Subject__________ is a collaborative.pdf
 
Q Describe the 2 types of homologs. (1) Orthologs (2) ParalogsS.pdf
Q Describe the 2 types of homologs. (1) Orthologs (2) ParalogsS.pdfQ Describe the 2 types of homologs. (1) Orthologs (2) ParalogsS.pdf
Q Describe the 2 types of homologs. (1) Orthologs (2) ParalogsS.pdf
 
Overview You are tasked with writing a program called Social Security.pdf
Overview You are tasked with writing a program called Social Security.pdfOverview You are tasked with writing a program called Social Security.pdf
Overview You are tasked with writing a program called Social Security.pdf
 
A geneticist Dr. O. Sophila discovers a new mutation that causes the .pdf
A geneticist Dr. O. Sophila discovers a new mutation that causes the .pdfA geneticist Dr. O. Sophila discovers a new mutation that causes the .pdf
A geneticist Dr. O. Sophila discovers a new mutation that causes the .pdf
 

Recently uploaded

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Recently uploaded (20)

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 

Please fix the java code (using eclipse)package hw4p1;import jav.pdf

  • 1. Please fix the java code (using eclipse) package hw4p1; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class MeanMedianHWv2 { public static void main(String[] args) throws IOException { String[] arrDate = { "", "", "","" }; Scanner in = new Scanner(System.in); Boolean day = true; // Year do { System.out.println("Enter a year (2016)"); arrDate[0] = in.next(); if (!arrDate[0].equalsIgnoreCase("2016")) { System.out.println("Wrong Input. '2016' only! Try again."); } else { arrDate[0] = "2016"; } } while(!arrDate[0].equalsIgnoreCase("2016")); // Month do
  • 2. { System.out.println("Enter a month (01)"); arrDate[1] = in.next(); if (!arrDate[1].equalsIgnoreCase("01")) { System.out.println("Wrong Input. '01' only! Try again!"); } else { arrDate[1] = "01"; } } while(!arrDate[1].equalsIgnoreCase("01")); // Day do { System.out.println("Enter a Day (04-10)"); arrDate[2] = in.next(); //if (arrDate[2] > 10 || arrDate[2] < 4) if (!arrDate[2].equalsIgnoreCase("04")) { System.out.println("Wrong Inpit. '04' - '10' only! Try again!"); } //else if (arrDate[2] == 4) else if (!arrDate[2].equalsIgnoreCase("05")) { System.out.println("Error! Invalid day. Try again!"); } else if (!arrDate[2].equalsIgnoreCase("06")) {
  • 3. System.out.println("Error! Invalid day. Try again!"); } else if (!arrDate[2].equalsIgnoreCase("07")) { System.out.println("Error! Invalid day. Try again!"); } else if (!arrDate[2].equalsIgnoreCase("08")) { System.out.println("Error! Invalid day. Try again!"); } else if (!arrDate[2].equalsIgnoreCase("09")) { System.out.println("Error! Invalid day. Try again!"); } else if (!arrDate[2].equalsIgnoreCase("10")) { System.out.println("Error! Invalid day. Try again!"); } else { arrDate[2] = "04"; day = false; arrDate[2] = "05"; day = false; arrDate[2] = "06"; day = false; arrDate[2] = "07"; day = false; arrDate[2] = "08"; day = false;
  • 4. arrDate[2] = "09"; day = false; arrDate[2] = "10"; day = false; } } while (day); do { System.out.println("which data? 'w' for wind, 'b' for baro pressure, 't' for temp"); arrDate[3] = in.next(); if (!arrDate[3]. equalsIgnoreCase ("w") && !arrDate[3].equalsIgnoreCase("b") && !arrDate[3].equalsIgnoreCase("t")) { System.out.println("Wrong input. 'w' / 'b' / 't' only! Try again"); } //while(!arrDate[2].equalsIgnoreCase("04") && !arrDate[2].equalsIgnoreCase("05") && !arrDate[2].equalsIgnoreCase("05")); if (arrDate[3].equalsIgnoreCase("w")) { System.out.println("w"); } else if (arrDate[3].equalsIgnoreCase("b")) { System.out.println("b"); } else if (arrDate[3].equalsIgnoreCase("t")) { System.out.println("t"); } } while (!arrDate[3].equalsIgnoreCase("w") && !arrDate[3].equalsIgnoreCase("b") && !arrDate[3].equalsIgnoreCase("t")); in.close(); String Date = arrDate[0] + "_" + arrDate[1] + "_" + arrDate[2]; System.out.println("------------------------------------");
  • 5. System.out.println("What you typed in is below"); System.out.println("Date" + Date); System.out.println("Date :" + arrDate[3]); System.out.println("-----------------------------------"); if (arrDate[3].equalsIgnoreCase("w")) { ArrayList windGust = getWindData(Date.arrDate); System.out.println("Wind Gust"); System.out.println(" Results of" + Date + ""); System.out.println("mean :" + mean(windGust)); System.out.println("Median: " + median(windGust)); System.out.println("-----------------------------------"); } else {arrDate[3].equalsIgnoreCase("b"); { ArrayList pressure = getPData(Date, arrDate); System.out.println("Pressure"); System.out.println(" Results of" + Date + ""); System.out.println("mean :" + mean(pressure)); System.out.println("Median: " + median(pressure)); System.out.println("-----------------------------------"); } else { ArrayList airTemp = getTdata(Date, arrDate); System.out.println("Temperature"); System.out.println(" Results of" + Date + ""); System.out.println("mean :" + mean(airTemp)); System.out.println("Median: " + median(airTemp)); System.out.println("-----------------------------------"); } System.out.println("Printing all data"); ArrayListweaData = getAllData(Date, arrDate); displayData(weaData);
  • 6. } // System.out.println("Sll Data"); // System.out.println(" Results of" + Date + ""); // else // { // ArrayList tempData = getbaroData(arrDate); // } //ArrayList barodata = getbaroData(arrDate); //ArrayList airTemp = getData("Air_Temp", arrDate); //ArrayList pressure = getData("Barometric_Press", arrDate); // System.out.println("Gust: mean " + mean(windGust) + ", median " + median(windGust)); // //System.out.println("Temp: mean " + mean(airTemp) + ", median " + median(airTemp)); // //System.out.println("Pressure: mean " + mean(pressure) + ", median " + median(pressure)); // // displayData(weaData); // } // GEtting wind data public static ArrayList getWindData(String Date, String [] arrDt) throws NumberFormatException, IOException { // construct the url if necessary //URL dataSource = new URL("https://lpo.dt.navy.mil/data/DM/" + arrDt[0] + "/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] + "/" + label); //URL url = new URL("http://umd-fmis.d.umn.edu/cpblee/weather.txt"); //URL url = new URL("http://umd- fmis.d.umn.edu/cpblee/data/2016/2016_01_04/2016_01_04.txt"); String newurl = "http://umd-fmis.d.umn.edu/cpblee/data/" + Date + "/" + Date + ".txt"; System.out.println("Searching " + newurl);
  • 7. URL url = new URL(newurl); //URL url = new URL("http://umd-fmis.d.umn.edu/cpblee/data/" + arrDt[0] + "/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] +"/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] +".txt/"); BufferedReader buffer = new BufferedReader(new InputStreamReader(url.openConnection().getInputStream())); // get wind gust data ArrayList windData = new ArrayList(); String inputLine; while ((inputLine = buffer.readLine()) != null) { windData.add(Double.parseDouble(inputLine.substring(20,22))); } buffer.close(); return windData; } // Getting temp data. public static ArrayList gettempData(String[] arrDt) throws NumberFormatException, IOException { // construct the url if necessary //URL dataSource = new URL("https://lpo.dt.navy.mil/data/DM/" + arrDt[0] + "/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] + "/" + label); URL url = new URL("http://umd-fmis.d.umn.edu/cpblee/data/" + arrDt[0] + "/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] +".txt/"); URL url = new URL("http://umd-fmis.d.umn.edu/cpblee/data/" + arrDt[0] + "/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] +"/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] +".txt/"); BufferedReader buffer = new BufferedReader(new InputStreamReader(url.openConnection().getInputStream())); // alternatively,
  • 8. //BufferedReader data = new BufferedReader(new InputStreamReader(dataSource.openStream())); // get wind gust data ArrayList tempData = new ArrayList(); String inputLine; while ((inputLine = buffer.readLine()) != null) { tempData.add(Double.parseDouble(inputLine.substring(20))); } buffer.close(); return tempData; } // Getting Baro Data. public static ArrayList getbaroData(String[] arrDt) throws NumberFormatException, IOException { // construct the url if necessary //URL dataSource = new URL("https://lpo.dt.navy.mil/data/DM/" + arrDt[0] + "/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] + "/" + label); URL url = new URL("http://umd-fmis.d.umn.edu/cpblee/data/" + arrDt[0] + "/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] +".txt/"); URL url = new URL("http://umd-fmis.d.umn.edu/cpblee/data/" + arrDt[0] + "/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] +"/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] +".txt/"); BufferedReader buffer = new BufferedReader(new InputStreamReader(url.openConnection().getInputStream())); // alternatively, //BufferedReader data = new BufferedReader(new InputStreamReader(dataSource.openStream())); // get wind gust data ArrayList baroData = new ArrayList(); String inputLine; while ((inputLine = buffer.readLine()) != null) {
  • 9. baroData.add(Double.parseDouble(inputLine.substring(20))); } buffer.close(); return baroData; } //GEtting all data public static ArrayList getAllData(String[] arrDt) throws NumberFormatException, IOException { //URL dataSource = new URL("https://lpo.dt.navy.mil/data/DM/" + arrDt[0] + "/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] + "/" + label); //URL url = new URL("http://umd- fmis.d.umn.edu/cpblee/data/2016/2016_01_04/2016_01_04.txt"); //URL url = new URL("http://umd-fmis.d.umn.edu/cpblee/data/" + arrDt[0] + "/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] +"/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] +".txt"); URL url = new URL ("http://umd-fmis.d.umn.edu/cpblee/data/2016/ + arrData[0] + “_”+ arrDt[1]” + “_” + arrDt[2]+“/”+“ arrDt[0]” + “_”+ “arrDt[1]” + “_” + arrDt[2]+“.txt”"); // http://umd-fmis.d.umn.edu/cpblee/data/2016/2016_01_04/2016_01_04.txt BufferedReader buffer = new BufferedReader(new InputStreamReader(url.openConnection().getInputStream())); //BufferedReader data = new BufferedReader(new InputStreamReader(dataSource.openStream())); // get date, time, and wind gust data (replicate data) ArrayList allData = new ArrayList(); String inputLine; while ((inputLine = buffer.readLine()) != null) { allData.add(inputLine.substring(0)); }
  • 10. buffer.close(); return allData; } public static void displayData(ArrayList a) { for (String s : a) { System.out.println(s); } } public static double mean(ArrayList a) { double sum = 0; for (double i : a) { sum += i; } return sum / a.size(); } public static double median(ArrayList a) { Collections.sort(a); if (a.size() / 2 * 2 == a.size()) { return (a.get(a.size() / 2) + a.get(a.size() / 2 - 1)) / 2; } else { return a.get(a.size() / 2); } } } **** this is the error i am getting: Exception in thread "main" java.lang.Error: Unresolved compilation problems: arrDate cannot be resolved or is not a field arrDate cannot be resolved to a variable Syntax error on token "else", delete this token arrDate cannot be resolved to a variable arrDate cannot be resolved to a variable Syntax error, insert "}" to complete Block at hw4p1.MeanMedianHWv2.main(MeanMedianHWv2.java:153)
  • 11. Solution There is a minor mistake in the else block you wrote. You just mistyped it seems. An open paranthesis ( should be there in the else if condition, but you used open braces { it seems. Here is the modificeation for you: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class MeanMedian { public static void main(String[] args) throws IOException { String[] arrDate = { "", "", "","" }; Scanner in = new Scanner(System.in); Boolean day = true; // Year do { System.out.println("Enter a year (2016)"); arrDate[0] = in.next(); if (!arrDate[0].equalsIgnoreCase("2016")) { System.out.println("Wrong Input. '2016' only! Try again."); } else { arrDate[0] = "2016"; } } while(!arrDate[0].equalsIgnoreCase("2016"));
  • 12. // Month do { System.out.println("Enter a month (01)"); arrDate[1] = in.next(); if (!arrDate[1].equalsIgnoreCase("01")) { System.out.println("Wrong Input. '01' only! Try again!"); } else { arrDate[1] = "01"; } } while(!arrDate[1].equalsIgnoreCase("01")); // Day do { System.out.println("Enter a Day (04-10)"); arrDate[2] = in.next(); //if (arrDate[2] > 10 || arrDate[2] < 4) if (!arrDate[2].equalsIgnoreCase("04")) { System.out.println("Wrong Inpit. '04' - '10' only! Try again!"); } //else if (arrDate[2] == 4) else if (!arrDate[2].equalsIgnoreCase("05")) { System.out.println("Error! Invalid day. Try again!"); }
  • 13. else if (!arrDate[2].equalsIgnoreCase("06")) { System.out.println("Error! Invalid day. Try again!"); } else if (!arrDate[2].equalsIgnoreCase("07")) { System.out.println("Error! Invalid day. Try again!"); } else if (!arrDate[2].equalsIgnoreCase("08")) { System.out.println("Error! Invalid day. Try again!"); } else if (!arrDate[2].equalsIgnoreCase("09")) { System.out.println("Error! Invalid day. Try again!"); } else if (!arrDate[2].equalsIgnoreCase("10")) { System.out.println("Error! Invalid day. Try again!"); } else { arrDate[2] = "04"; day = false; arrDate[2] = "05"; day = false; arrDate[2] = "06"; day = false; arrDate[2] = "07";
  • 14. day = false; arrDate[2] = "08"; day = false; arrDate[2] = "09"; day = false; arrDate[2] = "10"; day = false; } } while (day); do { System.out.println("which data? 'w' for wind, 'b' for baro pressure, 't' for temp"); arrDate[3] = in.next(); if (!arrDate[3]. equalsIgnoreCase ("w") && !arrDate[3].equalsIgnoreCase("b") && !arrDate[3].equalsIgnoreCase("t")) { System.out.println("Wrong input. 'w' / 'b' / 't' only! Try again"); } //while(!arrDate[2].equalsIgnoreCase("04") && !arrDate[2].equalsIgnoreCase("05") && !arrDate[2].equalsIgnoreCase("05")); if (arrDate[3].equalsIgnoreCase("w")) { System.out.println("w"); } else if (arrDate[3].equalsIgnoreCase("b")) { System.out.println("b"); } else if (arrDate[3].equalsIgnoreCase("t")) { System.out.println("t"); } } while (!arrDate[3].equalsIgnoreCase("w") && !arrDate[3].equalsIgnoreCase("b") && !arrDate[3].equalsIgnoreCase("t")); in.close();
  • 15. String Date = arrDate[0] + "_" + arrDate[1] + "_" + arrDate[2]; System.out.println("------------------------------------"); System.out.println("What you typed in is below"); System.out.println("Date" + Date); System.out.println("Date :" + arrDate[3]); System.out.println("-----------------------------------"); if (arrDate[3].equalsIgnoreCase("w")) { ArrayList windGust = getWindData(Date.arrDate); System.out.println("Wind Gust"); System.out.println(" Results of" + Date + ""); System.out.println("mean :" + mean(windGust)); System.out.println("Median: " + median(windGust)); System.out.println("-----------------------------------"); } else if(arrDate[3].equalsIgnoreCase("b")) { ArrayList pressure = getPData(Date, arrDate); System.out.println("Pressure"); System.out.println(" Results of" + Date + ""); System.out.println("mean :" + mean(pressure)); System.out.println("Median: " + median(pressure)); System.out.println("-----------------------------------"); } else { ArrayList airTemp = getTdata(Date, arrDate); System.out.println("Temperature"); System.out.println(" Results of" + Date + ""); System.out.println("mean :" + mean(airTemp)); System.out.println("Median: " + median(airTemp)); System.out.println("-----------------------------------"); }
  • 16. System.out.println("Printing all data"); ArrayListweaData = getAllData(arrDate); displayData(weaData); } // System.out.println("Sll Data"); // System.out.println(" Results of" + Date + ""); // else // { // ArrayList tempData = getbaroData(arrDate); // } //ArrayList barodata = getbaroData(arrDate); //ArrayList airTemp = getData("Air_Temp", arrDate); //ArrayList pressure = getData("Barometric_Press", arrDate); // System.out.println("Gust: mean " + mean(windGust) + ", median " + median(windGust)); // //System.out.println("Temp: mean " + mean(airTemp) + ", median " + median(airTemp)); // //System.out.println("Pressure: mean " + mean(pressure) + ", median " + median(pressure)); // // displayData(weaData); // } // GEtting wind data public static ArrayList getWindData(String Date, String [] arrDt) throws NumberFormatException, IOException { // construct the url if necessary //URL dataSource = new URL("https://lpo.dt.navy.mil/data/DM/" + arrDt[0] + "/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] + "/" + label); //URL url = new URL("http://umd-fmis.d.umn.edu/cpblee/weather.txt"); //URL url = new URL("http://umd- fmis.d.umn.edu/cpblee/data/2016/2016_01_04/2016_01_04.txt"); String newurl = "http://umd-fmis.d.umn.edu/cpblee/data/" + Date + "/" + Date + ".txt";
  • 17. System.out.println("Searching " + newurl); URL url = new URL(newurl); //URL url = new URL("http://umd-fmis.d.umn.edu/cpblee/data/" + arrDt[0] + "/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] +"/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] +".txt/"); BufferedReader buffer = new BufferedReader(new InputStreamReader(url.openConnection().getInputStream())); // get wind gust data ArrayList windData = new ArrayList(); String inputLine; while ((inputLine = buffer.readLine()) != null) { windData.add(Double.parseDouble(inputLine.substring(20,22))); } buffer.close(); return windData; } // Getting temp data. public static ArrayList gettempData(String[] arrDt) throws NumberFormatException, IOException { // construct the url if necessary //URL dataSource = new URL("https://lpo.dt.navy.mil/data/DM/" + arrDt[0] + "/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] + "/" + label); URL url = new URL("http://umd- fmis.d.umn.edu/cpblee/data/" + arrDt[0] + "/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] +".txt/"); URL url = new URL("http://umd-fmis.d.umn.edu/cpblee/data/" + arrDt[0] + "/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] +"/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] +".txt/"); BufferedReader buffer = new BufferedReader(new InputStreamReader(url.openConnection().getInputStream()));
  • 18. // alternatively, //BufferedReader data = new BufferedReader(new InputStreamReader(dataSource.openStream())); // get wind gust data ArrayList tempData = new ArrayList(); String inputLine; while ((inputLine = buffer.readLine()) != null) { tempData.add(Double.parseDouble(inputLine.substring(20))); } buffer.close(); return tempData; } // Getting Baro Data. public static ArrayList getbaroData(String[] arrDt) throws NumberFormatException, IOException { // construct the url if necessary //URL dataSource = new URL("https://lpo.dt.navy.mil/data/DM/" + arrDt[0] + "/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] + "/" + label); URL url = new URL("http://umd- fmis.d.umn.edu/cpblee/data/" + arrDt[0] + "/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] +".txt/"); URL url = new URL("http://umd-fmis.d.umn.edu/cpblee/data/" + arrDt[0] + "/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] +"/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] +".txt/"); BufferedReader buffer = new BufferedReader(new InputStreamReader(url.openConnection().getInputStream())); // alternatively, //BufferedReader data = new BufferedReader(new InputStreamReader(dataSource.openStream())); // get wind gust data ArrayList baroData = new ArrayList(); String inputLine;
  • 19. while ((inputLine = buffer.readLine()) != null) { baroData.add(Double.parseDouble(inputLine.substring(20))); } buffer.close(); return baroData; } //GEtting all data public static ArrayList getAllData(String[] arrDt) throws NumberFormatException, IOException { //URL dataSource = new URL("https://lpo.dt.navy.mil/data/DM/" + arrDt[0] + "/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] + "/" + label); //URL url = new URL("http://umd- fmis.d.umn.edu/cpblee/data/2016/2016_01_04/2016_01_04.txt"); //URL url = new URL("http://umd-fmis.d.umn.edu/cpblee/data/" + arrDt[0] + "/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] +"/" + arrDt[0] + "_" + arrDt[1] + "_" + arrDt[2] +".txt"); URL url = new URL ("http://umd-fmis.d.umn.edu/cpblee/data/2016/ + arrData[0] + “_”+ arrDt[1]” + “_” + arrDt[2]+“/”+“ arrDt[0]” + “_”+ “arrDt[1]” + “_” + arrDt[2]+“.txt”"); // http://umd-fmis.d.umn.edu/cpblee/data/2016/2016_01_04/2016_01_04.txt BufferedReader buffer = new BufferedReader(new InputStreamReader(url.openConnection().getInputStream())); //BufferedReader data = new BufferedReader(new InputStreamReader(dataSource.openStream())); // get date, time, and wind gust data (replicate data) ArrayList allData = new ArrayList(); String inputLine; while ((inputLine = buffer.readLine()) != null) { allData.add(inputLine.substring(0));
  • 20. } buffer.close(); return allData; } public static void displayData(ArrayList a) { for (String s : a) { System.out.println(s); } } public static double mean(ArrayList a) { double sum = 0; for (double i : a) { sum += i; } return sum / a.size(); } public static double median(ArrayList a) { Collections.sort(a); if (a.size() / 2 * 2 == a.size()) { return (a.get(a.size() / 2) + a.get(a.size() / 2 - 1)) / 2; } else { return a.get(a.size() / 2); } } } And may be you tried some methods which are not here it seems. Anyways, if you still need any refinements, just get back to me.