This is an assignment for my beginning programming class that I have been workin
ID: 3678848 • Letter: T
Question
This is an assignment for my beginning programming class that I have been working on for the past 12 hours and have gotten nowhere. I attempted to figure it out piece by piece but every time I tried to teach myself, it called for things in java we haven't heard of yet.
So the basic idea of the program is that given the low temperature (int), high temperature (int), and precipitation (double) of multiple days, the ending message dialog would pop up with the number of days, the number of rainy days, the total precipitation, average low, average high, the lowest low and the highest high.
To end the program, the same number is entered into the 3 inputs(temps and precip) and the program will show the dialog I mentioned above. I could tell you how to calculate each aspect of the output but I just can't translate it into the java program.
This is an example of inputs and their output;
Inputs:
45, 59, 0.0
49, 80, 1.3
56, 81, 0.3
-200, -200, -200
Output:
Reported days: 3
Rainy days: 2
Total Precip: 1.6
Average low: 50
Average high: 73.3
lowest low: 45
highest high: 81
Any sort of help/push in the right direction will be greatly appreciated!
Explanation / Answer
import java.util.*;
class low_high_temp
{
public static void main(String args[])
{
int low[]=new int[10];
int high[]=new int[10];
double per[]=new double[10];
int x,i=0,h=0,l=0,suml=0,sumh=0,avl,avh,ra=0,min=0,max=0;
double p=0.0,sump=0,avp;
Scanner scan = new Scanner(System.in);
System.out.println("Inputs");
while(true)
{
l=scan.nextInt();
h=scan.nextInt();
p=scan.nextDouble();
if(l!=-200 && h!=-200 && p!=-200)
{
if(p>0)
ra++;
low[i]=l;
high[i]=h;
per[i]=p;
suml=suml+low[i];
sumh=sumh+high[i];
sump=sump+per[i];
i++;
}
else
break;
}
min=low[0];
for(x=0;x<i;x++)
{
if(low[x]<min)
min=low[x];
}
max=high[0];
for(x=0;x<i;x++)
{
if(high[x]>max)
max=high[x];
}
avl=suml/i;
avh=sumh/i;
avp=sump/i;
System.out.println("Output:");
System.out.println("Reported days:"+i);
System.out.println("Rainy days:"+ra);
System.out.println("Total Precip:"+sump);
System.out.println("Average low:"+avl);
System.out.println("lowest low:"+min);
System.out.println("highest high:"+max);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.