Java Assignment: Reading and Comparing City Temperatures, Assignments of Computer Science

The instructions for assignment 5 of computer science 121, where students are required to write a java application that reads temperature information for five cities from the keyboard and displays the average temperature and comparison with normal high temperature.

Typology: Assignments

Pre 2010

Uploaded on 08/09/2009

koofers-user-61t-1
koofers-user-61t-1 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Computer Science 121
Assignment 5
Due: November 1, 1999
Write a Java application that will read information about 5 cities from the keyboard. The
information should include the city's name, it's high temperature, low temperature and normal
high temperature. After the data for each city is read in, the program should display the average
temperature and whether or not the high temperature is above, equal to, or below the normal high
temperature.
Use the declarations for the classes below.
public class CityTemps
{
public static void main (String [] args)
{
City ourCity = new City ();
ourCity.readAndCompareTemperatures ();
} // method main
} // class CityTemps
class City
{
private String cityName;
private int highTemp, lowTemp, normalHigh, averageTemp;
public City ()
{
cityName = "";
highTemp = 0;
lowTemp = 0;
normalHigh = 0;
averageHigh = 0;
} // constructor
public void readDataFromKeyboard ()
{
// Fill in code to read cityName, highTemp and lowTemp from the keyboard.
} // method readDataFromKeyboard
public int calculateAverage ()
{
// Fill in the code to calculate and return the average temperature.
} // method calculateAverage
public void displayAverageTemp ()
{
// Fill in the code to display the average temperature.
} // method displayAverageTemp
public void readAndCompareTemperatures ()
pf2

Partial preview of the text

Download Java Assignment: Reading and Comparing City Temperatures and more Assignments Computer Science in PDF only on Docsity!

Computer Science 121 Assignment 5 Due: November 1, 1999 Write a Java application that will read information about 5 cities from the keyboard. The information should include the city's name, it's high temperature, low temperature and normal high temperature. After the data for each city is read in, the program should display the average temperature and whether or not the high temperature is above, equal to, or below the normal high temperature. Use the declarations for the classes below. public class CityTemps { public static void main (String [] args) { City ourCity = new City (); ourCity.readAndCompareTemperatures (); } // method main } // class CityTemps class City { private String cityName; private int highTemp, lowTemp, normalHigh, averageTemp; public City () { cityName = ""; highTemp = 0; lowTemp = 0; normalHigh = 0; averageHigh = 0; } // constructor public void readDataFromKeyboard () { // Fill in code to read cityName, highTemp and lowTemp from the keyboard. } // method readDataFromKeyboard public int calculateAverage () { // Fill in the code to calculate and return the average temperature. } // method calculateAverage public void displayAverageTemp () { // Fill in the code to display the average temperature. } // method displayAverageTemp public void readAndCompareTemperatures ()

// Fill in the code to read the data for five cities from the keyboard. After each city's // data has been read, display the average temperature and whether the high temperature // is above, equal to or below the normal high temperature. } // method readAndCompareTemperatures } // class City