The Artima Developer Community
Sponsored Link

Java Answers Forum
Hel...help...help...

3 replies on 1 page. Most recent reply: Jun 14, 2004 10:23 AM by Daniel Ray

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 3 replies on 1 page
dino

Posts: 2
Nickname: dino13
Registered: May, 2004

Hel...help...help... Posted: May 31, 2004 6:41 PM
Reply to this message Reply
Advertisement
i have a problem !
I nedd a help with this program. I use java just for couple of months and am not very good at it :(
i need to write this progrm:
the program should ask for - the postcode to udentify the rainfall region and - the year to identify the rainfall year.

ask user to enter the rainfall figure in milimetersfor each month. Clearly indicate the month number. eg. may = 5.

the screen message should read: "please input rainfallfor month 5"
the rainfall figure will be stored in a single dimensional array. output should be like this:
rainfall figures in milimeters
region 3802
year 2001
1 2 3 4 5 6 7 8 9 10 11 12
12 60 120 30 35 300 123 123 35 25 12 1

pleeeeeeeeease help!!!!!!!


twc

Posts: 129
Nickname: twc
Registered: Feb, 2004

Re: Hel...help...help... Posted: Jun 1, 2004 5:42 AM
Reply to this message Reply
Show what you have done, and I can look at it for you. But I'm not going to do your homework for you.

dino

Posts: 2
Nickname: dino13
Registered: May, 2004

Re: Hel...help...help... Posted: Jun 4, 2004 12:19 AM
Reply to this message Reply
i'm having a problem to display it in line! i'm not sure how to display array in single line!
so far...
//*Assignment2 - Programming*//
//*Author: Dino Buljubasic*//
//*Date: May-Jun 2004*//

public class rain1 //Declaring the class//
{

//Program which stores 12 months of rainfall figures for region//

public static void main(String [] args)
{

//Declaring the variables//
int i=0;
int postcode ;
int year;
double[] rainfall = new double [12];

//Input the data into the program//

System.out.print("Enter the PostCode: ");
postcode =MyInput.readInt();

System.out.print("Enter the year: ");
year=MyInput.readInt();

//Using the "for" loop to enter the rainfall figure//
for( i=0; i<12;i++)
{
System.out.print("Please input rainfall for month " +(i+1) + ":");
rainfall = MyInput.readDouble();



}
{
System.out.println("\n\n\t\t\tRAINFALL FIGURES IN MILIMETERS\t");

System.out.println("\t\t\t\tRegion " +postcode);

System.out.println("\t\t\t\tYear " + year);


}}}


note: it runs somehow ;) but i dont know how to display the arrays in lines!!!

Daniel Ray

Posts: 53
Nickname: budoray
Registered: Oct, 2002

Re: Hel...help...help... Posted: Jun 14, 2004 10:23 AM
Reply to this message Reply
Not sure if this is what you wanted, but it will show you how to iterate through an array and print the data on separate lines. Post your desired output if I read your post incorrectly.


public class RainFall {

public double[] rainFor12Months = { 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.1, 2.2, 2.3 };
public String[] postalCodes = { "32210", "32211", "32212" };
public String[] years = { "1971", "1972", "1973" };

public RainFall(){

}

private void printRainFallForYear(String postalCode, String year){
int length = rainFor12Months.length;

for(int i=0; i<length; i++){
System.out.println(rainFor12Months + "\t\t" + postalCode + "\t\t" + year);
}
System.out.println();
}

public void printRainFallForAllYears(){
int length = years.length;

for(int i=0; i<length; i++){
System.out.println("Rainfall PostalCode Year");
printRainFallForYear(postalCodes, years);
}
}

public static void main(String[] args) {
new RainFall().printRainFallForAllYears();
}

}

Flat View: This topic has 3 replies on 1 page
Topic: activating JTextFields Previous Topic   Next Topic Topic: the answer for this book

Sponsored Links



Google
  Web Artima.com   

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