Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package oop;
- class weatherReport //what arrays will be included
- {
- String date; // day and month
- String sunriseTime; // hour and minute
- String sunsetTime; // hour and minute
- double tempHighC; // hot days in degrees celsius
- double tempLowC; // cold days in degrees celsius
- boolean rain; // rainy days
- }
- public class weatherCheck { // program starts
- public static void main(String[] args) { // main starts
- // TODO Auto-generated method stub
- weatherReport data[] = new weatherReport[10];
- for(int i=0; i<10; i++)
- { // beginning of for loop
- data[i] = new weatherReport();
- } // end of for loop
- int currentPos = 0;
- char choice = 'A';
- while(choice!= 'Q')
- {
- System.out.println("Add new day weather data");
- System.out.println("Print weather statistics");
- System.out.println("Quit");
- System.out.println("Enter key to continue (A,P,Q)");
- choice = TextIO.getChar();
- if(choice == 'A')
- {
- data[currentPos].date = TextIO.getWord();
- data[currentPos].sunriseTime = TextIO.getWord();
- data[currentPos].sunsetTime = TextIO.getWord();
- data[currentPos].tempHighC = TextIO.getDouble();
- data[currentPos].tempLowC = TextIO.getDouble();
- data[currentPos].rain = TextIO.getBoolean();
- currentPos = currentPos + 1;
- }
- if(choice == 'P');
- {
- double totalTemp = data[currentPos].tempHighC + data[currentPos].tempLowC;
- double averageTemp = totalTemp/10;
- System.out.println("Average temperature of this week: " + averageTemp + " degrees C");
- if(data[currentPos].rain == true)
- {
- System.out.println(data[currentPos].date + " had rain");
- }
- }
- if(choice == 'Q')
- {
- System.out.println("No more data to be received");
- }
- }
- }// main ends here
- }// program ends here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement