Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-28-2009, 10:52 PM
Member
 
Join Date: Nov 2009
Posts: 1
Rep Power: 0
silent_gurl is on a distinguished road
Default help :(
Howdy partners
How are you doing !!

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

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

please I really need YOUR help

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?
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-28-2009, 11:12 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 5,968
Rep Power: 7
Fubarable is on a distinguished road
Default
Hello and welcome.

Please edit your post above and add code tags. This will make it easier for others to read your code and thus easier for them to help you. Please see my signature below for details on how to use these.

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.
__________________
When posting code, please use code tags so that your code is readable. To do this, place the tag [code] before your block of code and [/code] after your block of code.
How to use Code Tags
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-03-2009, 02:51 AM
SwEeTAcTioN's Avatar
Member
 
Join Date: Oct 2009
Posts: 66
Rep Power: 0
SwEeTAcTioN is on a distinguished road
Default
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 (the number of lines you want to skip in the parameters has no limit)

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);
		}
__________________
Are you suggesting that Cocunuts migrate?!! -Monty Python

Last edited by SwEeTAcTioN; 12-03-2009 at 02:53 AM.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-03-2009, 04:05 AM
CodesAway's Avatar
Senior Member
 
Join Date: Sep 2009
Location: Texas
Posts: 234
Rep Power: 1
CodesAway is on a distinguished road
Default
For formatting strings, you might want to check out the Formatter class.

Also, the convenience functions String.format and System.out.format.
__________________
CodesAway - codesaway.info
writing tools that make writing code a little easier
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +2. The time now is 12:56 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org