You are on page 1of 8

public class Rainfall {

private static String[] months =


{"January","February","March","April","May","June","July","August","September","October","Nov
ember","December"};
public static double[][] avg (double a[][])
{
System.out.println("Average Rainfall of 2015 per Region: ");
for (int month = 0; month < a.length; month++) {
double sum = 0.0;
for (int region = 0; region< a[month].length; region++)
{
sum += a[month][region];
}
double average = sum/a[month].length;
if (average > 11)
System.out.println("South: " + average);
if (average >7.1 && average < 8)
{
System.out.println("North: " + average);
}
if (average == 7.0)
{
System.out.println("West: " + average);
}
if (average < 7)
{
System.out.println("East: " + average);
}

}
return a;
}
public static double[][] driest (double a[][])
{

double dryavg = 0;
int dryMonth = 0;
for (int month = 0; month < a[0].length; month++)
{
double sum = 0.0;
for (int region = 0; region< a.length; region++)
{
sum += a[region][month];
}
double average = sum/a.length;

if(month == 0)
{
dryavg = average;
}
if(average<dryavg)
{
dryavg = average;
dryMonth = month;
}
}
System.out.println("");
System.out.println("Driest month of 2015: "+ months[dryMonth]+ "\nAverage
rainfall for this month: " + dryavg);
return a;

public static double[][] wettest(double a[][], double b[])


{
double sum = 0.0;
double average = 0.0;
double[] c = new double[b.length];
int count = -1;
for(int month = 0; month< a[0].length; month++)
{
for(int region = 0; region< a.length; region++)
{

sum += a[region][month];
}

average = sum/4;
sum = 0;
c[month] = average;

System.out.println("");
double[] added = new double[c.length];
for(int i = 0;i<added.length;i++)
{
added[i] = c[i] + b[i];
}

double max = 0;
int index = 0;
for (int x = 0; x < added.length; x++)
{
if (max < added[x])
{
max = added[x];
index = x;

}
}
if (index > 11)
System.out.println("The greatest rainfall month(s) over the two years
occured at " + months[index-12]);
if (index <= 11)
System.out.println("The greatest rainfall month(s) over the two years
occured at " + months[index]);

return a;
}

public static String greatestChange(double a[][], double b[])


{
double sum = 0.0;
double average = 0.0;
double[] c = new double[b.length];

for(int month = 0; month< a[0].length; month++)


{
for(int region = 0; region< a.length; region++)
{

sum += a[region][month];
}

average = sum/4;
sum = 0;
c[month] = average;

System.out.println("");
String biggestChange = "";

double biggestChangeNum = 0.0d;

for(int i = 0;i<b.length;i++)
{
double currentChange = Math.abs(b[i] - c[i]);
if(currentChange>biggestChangeNum)
{
biggestChangeNum = currentChange;
biggestChange = months[i];
}
else if(currentChange == biggestChangeNum)
{
biggestChange+=months[i];
}
}

System.out.println(biggestChange);
return biggestChange;

public static void main(String[] args) {


// TODO Auto-generated method stub
double[][] Rainfall2015 = {{14,13,11,9,5,3,1,1,4,8,7,12},
{17,18,15,13,11,9,7,8,9,8,15,15}, {9,8,6,4,2,1,0,1,3,9,7,10}, {12,11,9,6,4,2,1,3,5,8,10,13}};
double[]avgRain2014 = {15,11,15,9,5,7,4,3,4,8,12,12};
avg(Rainfall2015);
driest(Rainfall2015);
wettest(Rainfall2015,avgRain2014);
greatestChange(Rainfall2015,avgRain2014);
}
}
import java.util.Scanner;

public class Diving {


private double [][] scores;
public int numberOfDivers;
static Scanner keyboard = new Scanner(System.in);
public Diving()
{
System.out.println("How many divers are being scored?");
int numberOfDivers = keyboard.nextInt();

scores = new double [numberOfDivers][8];

for (int diver=0; diver< numberOfDivers; diver++)


{
System.out.println("Enter the degree of difficulty for this dive (must be
within 1.2 and 3.8): ");
scores[diver][0]= keyboard.nextDouble();
while ((scores[diver][0]>3.8) || (scores[diver][0]<1.2))
{
System.out.println("Degree must be between 1.2 and 3.8. Please
reenter the difficulty");
scores[diver][0]= keyboard.nextDouble();
}
for (int judge=1; judge< 8; judge++)
{
System.out.println("Enter the judge's score (must be between 0
and 10): ");
scores[diver][judge]= keyboard.nextDouble();
while ((scores[diver][judge]>10) || (scores[diver][judge]<0))
{
System.out.println("Judge's scores must be between 0 and
10. Please reenter the judge's scores.");
scores[diver][judge]= keyboard.nextDouble();
}
}
}

double [][] sumOfScores = new double [numberOfDivers][2];


for (int diver=0; diver<numberOfDivers; diver++)
{
scores[diver][lowest(scores[diver])] = 0;
scores[diver][highest(scores[diver])] = 0;
}

for (int diver=0; diver<numberOfDivers; diver++){


sumOfScores[diver][0] = scores[diver][0];
sumOfScores[diver][1] = sum(scores[diver]);
}
double [] finalScores = new double [numberOfDivers];
for (int diver=0; diver<numberOfDivers; diver++){
finalScores[diver] = sumOfScores[diver][0] * sumOfScores[diver][1];
finalScores[diver] *= 0.6;
}

int counter=1;
for (double element: finalScores){
System.out.println("Diver number: " + counter + ": " + element);
counter++;
}

public static int highest(double [] a){


double max = a[1];
int index = 1;
for (int i=2; i<8; i++){
if (a[i]>max){
max = a[i];
index = i;
}
}
return index;
}

public static int lowest(double [] a){


double min = a[1];
int index = 1;
for (int i=2; i<8; i++){
if (a[i]<min){
min = a[i];
index = i;
}
}

return index;
}

public static double sum(double [] score){


double sum = 0.0;
for (int i=1; i<score.length; i++){
sum += score[i];
}
return sum;
}

public static void main(String[] args)


{
Diving Results = new Diving();

You might also like