aspose file tools*
The moose likes Beginning Java and the fly likes A class to encapsulate the concept of daily temperatures for a week Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A class to encapsulate the concept of daily temperatures for a week" Watch "A class to encapsulate the concept of daily temperatures for a week" New topic
Author

A class to encapsulate the concept of daily temperatures for a week

H. O.
Greenhorn

Joined: Dec 03, 2008
Posts: 1
So, these are the instructions:

1. Create a class encapsulating the concept of daily temperatures for a week. Prompt the user for 7 values; store the values in an array.

This class must include the following methods to manage the array: Accessors, mutators, toString and equals methods

Method to calculate number of days below freezing
Method to determine and return largest temperature change between any 2 consecutive days

2.Write a client class to create objects from the class in step 1. In the client class main, you need to create a second array using an initializer list containing the following data:
32, 45, 52, 66, 76, 53, 31

Write the following method calls in your main:

A. Call the method to calculate the number of days below and freezing for each of the arrays.
B. Use the equals method to compare the 2 arrays.
C. Call the method that determines and returns the largest temperature change for each of the arrays.
D. Use the toString method to print out each of the arrays.

______________________________________________________

This is what I have come up with so far:



import java.util.Scanner;

public class Weather
{

int [] tempWeather = new int [7];

Scanner scan = new Scanner(System.in);

//--------------
//Mutator method
//--------------

public void inputTemps()
{
for (int i=0; i<tempWeather.length; i++ )
{
System.out.print( "Enter temperature for day " + (i+1) + "/t" );

tempWeather[i] = scan.nextInt();
}
}

//---------------
//Accessor method
//---------------

public int [] getTempWeather()
{
int [] temp = new int [tempWeather.length];
for (int i = 0; i < tempWeather.length; i++)
{
temp[i] = tempWeather[i];
}
return temp;
}

//----------------------------------
//Method to calculate freezing temps
//----------------------------------

public int getFreezing()
{
int temp = 0;

for (int i=0; i<tempWeather.length; i++)
{
if ((tempWeather[i] < 32) || (tempWeather[i] == 32))
temp++;
}
return temp;
}

//---------------------------------------
//Method to calculate largest temp change
//---------------------------------------

public int getMaxChange()
{
int i = 0;
int max = tempWeather[0];
int temp = Math.abs(tempWeather[i]-tempWeather[i+1]);

for (i=1; i<tempWeather.length-2; i++)
{
if (temp > max)
max = temp;
}
return max;
}

//---------------
//toString method
//---------------

public String toString(int [] tempWeather)
{
for (int i=0; i<tempWeather.length; i++)
{
return "Temperatures:/t" + String.valueOf(tempWeather[i]);
}

}


}


--------------------------------------------------------------

I need help writing this program. I know for fact that my toString method is incorrect. If anyone could let me know what I've done wrong so far or what I've done right or guide me with the correct path I should take to finish this- anything at all really, I would greatly appreciate it! I've been trying to find the solution or anything that will help, but I haven't been too successful.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

"H.O"
Please check your private messages for an important administrative matter.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A class to encapsulate the concept of daily temperatures for a week
 
Similar Threads
i changed a folder name and now my program wont run
Some Simple(??) Java problems.
help compiling
catch statements
comparison methods