Question

In: Computer Science

20.1: Checking on the Drought [(JAVA, ECLIPSE), Please keep the program as short as possible] The...

20.1: Checking on the Drought

[(JAVA, ECLIPSE), Please keep the program as short as possible]

  • The California drought is a topic that is weighing heavily on the minds of many people in this state.
  • With all the rain we have gotten this year, we are all hoping the drought is over
  • Let's examine some rainfall data for Silicon Valley to get a sense of how this year's rainfall compares to the average rainfall.
  • For this assignment, you will be practicing arrays and File I/O.
  • First, create a new file called average_rain.txt.
  • Then, copy and paste the following data into your file. Make sure that each value is on its own line and that there are no blank lines between values.

2.99
3.31
2.05
1.06
0.39
0.08
0.08
0.08
0.24
0.79
1.89
2.13

  • This data represents the average monthly rainfall for San Jose as measured between 1961-1990.
  • Note that each data point is the total rainfall for one of the 12 months of the year. The first data point represents the average rainfall in January and the last data point represents the average rainfall in December.
  • Save your file and then create a new text file called rain2018_19.txt.
  • Copy and paste the following data into this file. Again make sure that each data point is on its own line and that there are no blank lines between data points.

2.89
5.61
3.20
0.00
0.00
0.00
0.00
0.00
0.00
0.00
1.92
1.53

  • This data represents the rainfall in San Jose from March 2018-February 2019, with the first number representing the rainfall in January 2018 and the last number representing the rainfall in December 2018
  • Note that each data point is the average rainfall for one of the 12 months of the year.
  • The first data point represents the average rainfall in January, and the last data point represents the average rainfall in December.
  • Now, open Eclipse and create a new Java source file named Rainfall.java.
  • The first goal of our program is to read the input data from our two files and store the data in two separate arrays - one array for the 2018-19 rainfall data and one array for the average rainfall data.
  • What size should you make these arrays? Hint: How many months are there in the year?
  • After you have declared your arrays, you need to open each file and, using a loop, write the data into the slots of your array.
  • What kind of loop do you need here? Hint: Do you know in advance how many data points are in each file? Try a for loop.
  • You will need to open two different files and write the contents into two different arrays.
  • Therefore, you will need to close the stream for one file before you open the other file, like so:

input.close();

input = new Scanner(averageFile);

  • Your program should write the results to a file in the form of a table that looks like this:

Rainfall in San Jose: A Comparison

Average        2018-9        Deficit
2.99        2.89        0.10
3.31        5.61        -2.30
2.05        3.2        -1.15
1.06        0.0        1.06
0.39        0.0        0.39
0.08        0.0        0.08
0.08        0.0        0.08
0.08        0.0        0.08
0.24        0.0        0.24
0.79        0.0        0.79
1.89        1.92        -0.03
2.13        1.53        0.60

Total deficit: -0.06

  • To do so, you will need another loop to write the contents of your arrays to the file. Create another textfile called rain_comparison.txt and write the above data to the file.
  • Note that you will need to adjust the number of tabs until your data is lined up properly as in the image above.
  • Note that you should also print the total deficit below the table, as shown above. Hint: keep a running sum of the deficit inside your final for loop

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// average_rain.txt

2.99
3.31
2.05
1.06
0.39
0.08
0.08
0.08
0.24
0.79
1.89
2.13

_________________

// rain2018_19.txt

2.89
5.61
3.20
0.00
0.00
0.00
0.00
0.00
0.00
0.00
1.92
1.53

__________________

// Rainfall.java

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Rainfall {

   public static void main(String[] args) {
       //Declaring one Dimensional Array
       double averageRain[]=new double[12];
       double rain2018_19[]=new double[12];
       //Declaring variables
       double totalDeficit=0,def=0;
       Scanner sc=null;
try {
   //Opening the file and read the data and populate the values into an array
           sc=new Scanner(new File("average_rain.txt"));
           for(int i=0;i<averageRain.length;i++)
           {
               averageRain[i]=sc.nextDouble();
           }
           sc.close();
           sc=new Scanner(new File("rain2018_19.txt"));
           for(int i=0;i<rain2018_19.length;i++)
           {
               rain2018_19[i]=sc.nextDouble();
           }
           sc.close();
       } catch (FileNotFoundException e) {
           e.printStackTrace();
       }
//Displaying the Results
System.out.println("Average\t2018-9\t\tDeficit");
for(int i=0;i<averageRain.length;i++)
{
   def=averageRain[i]-rain2018_19[i];
   System.out.printf("%.2f\t\t%.2f\t\t%.2f\n",averageRain[i],rain2018_19[i],def);
   totalDeficit+=def;
}
//Displaying the output
System.out.printf("Total deficit:%.2f",totalDeficit);

   }

}
______________________

Output:

Average   2018-9       Deficit
2.99       2.89       0.10
3.31       5.61       -2.30
2.05       3.20       -1.15
1.06       0.00       1.06
0.39       0.00       0.39
0.08       0.00       0.08
0.08       0.00       0.08
0.08       0.00       0.08
0.24       0.00       0.24
0.79       0.00       0.79
1.89       1.92       -0.03
2.13       1.53       0.60
Total deficit:-0.06

_______________Could you plz rate me well.Thank You


Related Solutions

(Keep the response as short as possible please) What is a liquidated damages clause in a...
(Keep the response as short as possible please) What is a liquidated damages clause in a contract?     a) Is it a good thing?     b) Why might the clause not be enforced by the courts? What is specific performance? In which situation would specific performance more likely be granted...sale of land contract or personal services contract? Why?
Please use Java Eclipse and show code/output Please create a program that determines when a good...
Please use Java Eclipse and show code/output Please create a program that determines when a good day to go to the beach is. Please use the users input and its returning output. If the weather is 70 degree or greater, the program should say yes it is a good day to go If the weather is less than 70 degrees to say no the weather is not a good day to go
USE C++ and please keep program as simple as possible and also comment so it is...
USE C++ and please keep program as simple as possible and also comment so it is easy to understad Create a structure called time. Its three members, all type int, should be called hours, minutes, and seconds. Write a program that prompts the user to enter a time value in hours, minutes, and seconds. This should be in 12:59:59 format. This entire input should be assigned first to a string variable. Then the string should be tokenized thereby assigning the...
Must be using Java Eclipse Please 4. Test program LinkedList.java, and make sure that you understand...
Must be using Java Eclipse Please 4. Test program LinkedList.java, and make sure that you understand each operation in the program. (refer to linkedListApplication.java) 6. (Programming) Use LinkedList as a reference, add the following operations in the class LinkedList; a) Find the average data values of the linked list. b) Find the node with largest key, and then delete the node. (Note, you must return the node, not just the largest key) c) Test ALL operations (Search, Insert, Delete, Append/Remove...
Hello, I need this done with Java and ran in Eclipse if possible. A university wants...
Hello, I need this done with Java and ran in Eclipse if possible. A university wants to demonstrate its political correctness by applying the Supreme Court’s “Separate but equal is inherently unequal” doctrine to gender as well as race. As such, the university has decided that both genders will use the same bathroom facilities. However, in order to preserve some tradition, it decrees that when a woman is in the bathroom, only other women may enter, and when a man...
Program: Java (using eclipse) Write a program that asks the user to enter today’s sales for...
Program: Java (using eclipse) Write a program that asks the user to enter today’s sales for five stores. The program should then display a bar chart comparing each store’s sales. Create each bar in the bar chart by displaying a row or asterisks. Each asterisk should represent $100 of sales. You must use a loop to print the bar chart!!!! If the user enters a negative value for the sales amount, the program will keep asking the user to enter...
Write a Java program in Eclipse to calculate the total cost to enter into a waterpark...
Write a Java program in Eclipse to calculate the total cost to enter into a waterpark for a family/group Ticket rates are listed below kids (Age 12 and under)=$ 12.50 Regular( Age between12 -55) =$ 18.25 Seniors (55 and above) = $15.00 Tax =7% Your program should ask the user to enter the total number of members in their group. User needs to enter the ages for all members. Write appropriate error messages for invalid entries. An array should be...
C++ Please. Break it down barney style if possible. Instructions Create a program to keep track...
C++ Please. Break it down barney style if possible. Instructions Create a program to keep track of the statistics for a kid’s soccer team. The program will have a structure that defines what data the program will collect for each of the players. The structure will keep the following data: Players Name (string) Players Jersey Number (integer) Points scored by Player (integer) The program will have an array of 12 players (use less for testing and development, use a constant...
IN JAVA ECLIPSE PLEASE The xxx_Student class A Student has a: – Name - the name...
IN JAVA ECLIPSE PLEASE The xxx_Student class A Student has a: – Name - the name consists of the First and Last name separated by a space. – Student Id – a whole number automatically assigned in the student class – Student id numbers start at 100. The numbers are assigned using a static variable in the Student class • Include all instance variables • Getters and setters for instance variables • A static variable used to assign the student...
write on eclipse java Write a program named lab5 that will play a game of Blackjack...
write on eclipse java Write a program named lab5 that will play a game of Blackjack between the user and the computer. Create a second class named Card with the following: Define the following private instance variables: cardValue (int) & cardSuite (String) Write a constructor with no parameters that will Set cardValue to a random number between 1 and 13 Generate a second random number between 0 and 3 and assign cardSuite a string based on its value (0 –...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT