Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE HELP IN JAVA: There are 2 input files, one contains days - one day (String) per line - and the other contains temperatures -

PLEASE HELP IN JAVA:

There are 2 input files, one contains days - one day (String) per line - and the other contains temperatures - again one (double) per line. You are to read in one day and one temp, and make a Temperature object. Do not try to separate month and date, just treat April 23 as a single String. You will need to create a Temperature class. You need only code the methods you need but make sure it has a compareTo (compares temps).

I have given you the main method. You will see that once you input all the data , create objects, and fill the array, you then print it out , and then find the hottest day in the year. Note that I just used a random number generator and it is as likely there were very hot days in December as very cold ones in July.

ask the user for a month, and then print the hottest day in that month. Note that you will need 2 different findLargest methods.

public static void main(String[] args) { Temperature [] myArray = new Temperature[365]; readData(myArray); printData (myArray); Temperature big=findLargest(myArray); System.out.println("Hottest day was " + big); System.out.println("Which month ?"); Scanner s = new Scanner(System.in); String month=s.nextLine(); big= findLargest(month, myArray); System.out.println("Hottest day in " + month + " was " + big); } public static void readData(Temperature[] t) { Scanner scan1=null, scan2=null; try{ scan1 = new Scanner(new BufferedInputStream(new FileInputStream("days.txt"))); //daya.txt contains the days //temps.txt contains the temperature for each corresponding day //so the first temperature (double) in temps.txt is the temperature for //January 1, the second is for January 2 etc. scan2 = new Scanner(new BufferedInputStream(new FileInputStream("temps.txt"))); } catch (FileNotFoundException e){ } //Input data, create Temperature objects, and fill array } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions