1. Member
Join Date
Nov 2009
Posts
1
Rep Power
0

## help :(

Howdy partners
How are you doing !!

I got a problem here and I really don't know how should I handle it ??:confused:

here the problem is :

Suppose that temperature measurements were made on 7 days of 2009 in each of 5 cities. Write a program that will read the city name followed by the temperature measurements of that city. The city name and measurements should be stored into two arrays. The program should find out the average temperature for each city. Also you should find the average temperature of each day.

I have tried so many time to understand it but NO-WAY

here what I wrote :

import java.util.*;
class assignment_7012606
{
public static void main(String args[])
{
int t;
String c;
String[] city=new String[5];
int[] temp=new int[35];
double avgc1,avgc2,avgc3,avgc4,avgc5,avgd1,avgd2,avgd3,av gd4,avgd5,avgd6,avgd7;
int d1,d2,d3,d4,d5,d6,d7,c1,c3,c4,c5;

Scanner s=new Scanner(System.in);
for (int i=0;i<5;i++){
System.out.println("enter the city name");
c=s.nextLine();
city[i]=c;
}
for (int a=0;a<35;a++){
System.out.println("enter the temperature");
t=s.nextInt();
temp[a]=t;
}
avgc1=temp[0][1][2][3][4][5][6];
temp[7][8][9][10][11][12][13]=avgc2;
temp[14][15][16][17][18][19][20]=avgc3;
temp[21][22][23][24][25][26][27]=avgc4;
temp[28][29][30][31][32][33][34]=avgc5;
temp[0][7][14][21][28]=avgd1;
temp[1][8][15][22][29]=avgd2;
temp[2][9][16][23][30]=avgd3;
temp[3][10][17][24][31]=avgd4;
temp[4][11][18][25][32]=avgd5;
temp[5][12][19][26][33]=avgd6;
temp[6][13][20][27][34]=avgd7;
c1=avgc1/5;
System.out.println("the average of first city is "+c1);
System.out.println("\n");
c2=avgc2/5;
System.out.println("the average of second city is "+c2);
System.out.println("\n");
c3=avgc3/5;
System.out.println("the average of third city is "+c3);
System.out.println("\n");
c4=avgc4/5;
System.out.println("the average of fourth city is "+c4);
System.out.println("\n");
c5=avgc5/5;
System.out.println("the average of fivth city is "+c5);
System.out.println("\n");
d1=avgd1/7;
System.out.println("the average of the first day"+d1);
System.out.println("\n");
d2=avgd2/7;
System.out.println("the average of the second day"+d2);
System.out.println("\n");
d3=avgd3/7;
System.out.println("the average of the third day"+d3);
System.out.println("\n");
d4=avgd4/7;
System.out.println("the average of the fourth day"+d4);
System.out.println("\n");
d5=avgd5/7;
System.out.println("the average of the fivith day"+d5);
System.out.println("\n");
d6=avgd6/7;
System.out.println("the average of the sixith day"+d6);
System.out.println("\n");
d7=avgd7/7;
System.out.println("the average of the seventh day"+d7);
}
}

so anyone can help me?

2. Hello and welcome.

Also, what is wrong with your current program? Are you seeing any error messages? If so, post them and place a comment in your code indicating which line of code causes the error. Any bit of information you can give us can help us help you.

Much luck.

3. You can use Util.skip(1); instead of all the \n just copy the code and put it in a new java file it contains some good stuff for computer science classes:D (the number of lines you want to skip in the parameters has no limit)

Java Code:
```class Util
{
public static void skip(int n)
{
for (int k = 1; k <= n; k++)
System.out.println();
}

public static void center(String str)
{
int len = str.length();
int tab = (80 - len) / 2;
for (int k = 1; k <= tab; k++)
System.out.print(" ");
System.out.println(str);
}

public static void rightJustify(String str)
{
int len = str.length();
int tab = 80 - len;
for (int k = 1; k <= tab; k++)
System.out.print(" ");
System.out.println(str);
}

public static String spaces(int n)
{
String temp = "";
for (int k = 1; k <= n; k++)
temp += " ";
return temp;
}

public static void tabString(String str, int tabSize)
{
int difference = tabSize - str.length();
if (difference < 0)
difference = 0;
System.out.print(str);
for (int k = 1; k <= difference; k++)
System.out.print(" ");
}

public static void heading(String name, String lab, String date, String points)
{
int nameTab   = 28 - name.length();
int labTab    = 28 - lab.length();
int dateTab   = 28 - date.length();
int pointsTab = 28 - points.length();

Util.skip(2);
System.out.println("****************************************************");
System.out.println("****************************************************");
System.out.println("**                                                **");
System.out.println("**  Student Name:     " + name + spaces(nameTab) + "**");
System.out.println("**                                                **");
System.out.println("**  Lab Assignment:   " + lab + spaces(labTab) + "**");
System.out.println("**                                                **");
System.out.println("**  Date Due:         " + date + spaces(dateTab) + "**");
System.out.println("**                                                **");
System.out.println("**  Point Version:    " + points + spaces(pointsTab) + "**");
System.out.println("**                                                **");
System.out.println("****************************************************");
System.out.println("****************************************************");
Util.skip(2);
}```
Last edited by SwEeTAcTioN; 12-03-2009 at 01:53 AM.

4. For formatting strings, you might want to check out the Formatter class.

Also, the convenience functions String.format and System.out.format.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•