The Artima Developer Community
Sponsored Link

Java Answers Forum
Large arrays with lots of stuff

2 replies on 1 page. Most recent reply: Apr 23, 2011 2:25 PM by Mark Johnson

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Aaron S

Posts: 6
Nickname: bigtex1973
Registered: Dec, 2009

Large arrays with lots of stuff Posted: Dec 31, 2009 3:30 PM
Reply to this message Reply
Advertisement
Below is a programming assignment that I have and I have ZERO programming experience and am completely lost. Can anyone at least help me get started?

New York city temperature ranges for 12 months is given below:

Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
25–38 26-40 34-48 43-58 52-68 62-77 68-83 60-75 49-65 41-54 31-43 47-61

Write a program as described below:
1. Create an int array of size 365 to save the daily temperatures for one year.
2. Fill the array with randomly generated numbers between the ranges for that month. For
example, for the first 31 days of the year (that is the month of January) randomly
generate numbers between 25 and 38. For the next 29 days (the Month of February)
randomly generate numbers between 26 and 40, and so on for every month.
The formula for generating random numbers between two numbers m and n is,
(int)Math.floor(m+Math.random()*(n-m+1));
3. Print the average temperature for each month.
4. Print the hottest day for the entire year, in the format Hottest day was Thursday July …
(You have think and see how to do this). Assume January 1 was a Monday.
5. Print the coldest day for the entire year, in the format Hottest day was Tuesday Feb …
6. How many days in a year it was below 33 F and how many more than 75 F


Aaron S

Posts: 6
Nickname: bigtex1973
Registered: Dec, 2009

Temperature Tracking Assignment. Posted: Jan 4, 2010 10:23 PM
Reply to this message Reply
> I have an assignment to track average temps of a year in NYC and tell the averages for each month, the highest and lowest temps for the year, and print how many days were below 33F or above 75F. Below is the program that I have come up with for the averages of each month and the Highest and lowest temps. The problem is that the highs and lows are supposed to be in the format of "The hottest (coldest) day was Tuesday January 2". I can't seem to figure out how to get this to work from where I am. I tried a couple of switch statements, but didn't have much luck. I also can't seem to figure out the whole how many days were above 75 or below 33 issue either. Can anyone help.

import java.util.*;
class Assignment0702
{
public static void main(String args[])
{
int year[]=new int[365];
int sum=0;
for (int x=0; x<31; x++) {year[x] = (int)Math.floor(25+Math.random()*14);
sum+=year[x];
}
System.out.println("Avera ge temperature for January: " +sum/31);
{
int sum2=0;
for (int x=31; x<59; x++) {year[x] = (int)Math.floor(26+Math.random()*15);
sum2+=year[x];
}
System.out.println("Aver age temperature for February: " +sum2/28);
}
{
int sum3=0;
for (int x=59; x<90; x++) {year[x] = (int)Math.floor(34+Math.random()*15);
sum3+=year[x];
}
System.out.println("Aver age temperature for March: " +sum3/31);
}
{
int sum4=0;
for (int x=90; x<120; x++) {year[x] = (int)Math.floor(43+Math.random()*16);
sum4+=year[x];
}
System.out.println("Aver age temperature for April: " +sum4/30);
}
{
int sum5=0;
for (int x=120; x<151; x++) {year[x] = (int)Math.floor(52+Math.random()*17);
sum5+=year[x];
}
System.out.println("Aver age temperature for May: " +sum5/31);
}
{
int sum6=0;
for (int x=151; x<181; x++) {year[x] = (int)Math.floor(62+Math.random()*16);
sum6+=year[x];
}
System.out.println("Aver age temperature for June: " +sum6/30);
}
{
int sum7=0;
for (int x=181; x<212; x++) {year[x] = (int)Math.floor(68+Math.random()*16);
sum7+=year[x];
}
System.out.println("Aver age temperature for July: " +sum7/31);
}
{
int sum8=0;
for (int x=212; x<243; x++) {year[x] = (int)Math.floor(60+Math.random()*16);
sum8+=year[x];
}
System.out.println("Aver age temperature for August: " +sum8/31);
}
{
int sum9=0;
for (int x=243; x<273; x++) {year[x] = (int)Math.floor(49+Math.random()*17);
sum9+=year[x];
}
System.out.println("Aver age temperature for September: " +sum9/30);
}
{
int sum10=0;
for (int x=273; x<304; x++) {year[x] = (int)Math.floor(41+Math.random()*14);
sum10+=year[x];
}
System.out.println("Ave rage temperature for October: " +sum10/31);
}
{
int sum11=0;
for (int x=303; x<334; x++) {year[x] = (int)Math.floor(31+Math.random()*13);
sum11+=year[x];
}
System.out.println("Ave rage temperature for November: " +sum11/30);
}
{
int sum12=0;
for (int x=334; x<365; x++) {year[x] = (int)Math.floor(47+Math.random()*15);
sum12+=year[x];
}
System.out.println("Ave rage temperature for December: " +sum12/31);
}
{
int largst=year[0];

for(int x=1;x<364;x++)

if(year[x]>largst)largst=year[x];

System.out.println("The highest temperature="+largst);
}
{
int smallst=year[0];
for(int x=1;x<364;x++)
if(year[x]<smallst)smallst=year[x];
System.out.println("The lowest temperature="+smallst);

}
}
}

Mark Johnson

Posts: 1
Nickname: shawn001gu
Registered: Apr, 2011

Re: Temperature Tracking Assignment. Posted: Apr 23, 2011 2:25 PM
Reply to this message Reply
I have been trying to add some coding to the program to get the hottest and coldest days, but for some reason its not adding up. Can somebody else help with this program? Pls.

Flat View: This topic has 2 replies on 1 page
Topic: Delete my account/posts please? Previous Topic   Next Topic Topic: Please help with swiching program to inher

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use