Advertisement
oona

weather check (not all well complete)

Apr 4th, 2014
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.92 KB | None | 0 0
  1. package oop;
  2.  
  3. class weatherReport //what arrays will be included
  4. {
  5.  
  6.     String date; // day and month
  7.     String sunriseTime; // hour and minute
  8.     String sunsetTime; // hour and minute
  9.     double tempHighC; // hot days in degrees celsius
  10.     double tempLowC; // cold days in degrees celsius
  11.     boolean rain; // rainy days
  12. }
  13.  
  14. public class weatherCheck { // program starts
  15.  
  16.     public static void main(String[] args) { // main starts
  17.         // TODO Auto-generated method stub
  18.        
  19.             weatherReport data[] = new weatherReport[10];
  20.            
  21.             for(int i=0; i<10; i++)
  22.             { // beginning of for loop
  23.                 data[i] = new weatherReport();
  24.             } // end of for loop
  25.            
  26.             int currentPos = 0;
  27.             char choice = 'A';
  28.            
  29.             while(choice!= 'Q')
  30.             {
  31.                 System.out.println("Add new day weather data");
  32.                 System.out.println("Print weather statistics");
  33.                 System.out.println("Quit");
  34.                 System.out.println("Enter key to continue (A,P,Q)");
  35.                
  36.                 choice = TextIO.getChar();
  37.                
  38.                 if(choice == 'A')
  39.                 {
  40.                     data[currentPos].date = TextIO.getWord();
  41.                     data[currentPos].sunriseTime = TextIO.getWord();
  42.                     data[currentPos].sunsetTime = TextIO.getWord();
  43.                     data[currentPos].tempHighC = TextIO.getDouble();
  44.                     data[currentPos].tempLowC = TextIO.getDouble();
  45.                     data[currentPos].rain = TextIO.getBoolean();
  46.                    
  47.                     currentPos = currentPos + 1;
  48.                    
  49.                 }
  50.                 if(choice == 'P');
  51.                 {
  52.                     double totalTemp = data[currentPos].tempHighC + data[currentPos].tempLowC;
  53.                     double averageTemp = totalTemp/10;
  54.                     System.out.println("Average temperature of this week: " + averageTemp + " degrees C");
  55.                    
  56.                    
  57.                     if(data[currentPos].rain == true)
  58.                     {
  59.                         System.out.println(data[currentPos].date + " had rain");
  60.                     }
  61.                    
  62.                 }
  63.                 if(choice == 'Q')
  64.                 {
  65.                     System.out.println("No more data to be received");
  66.                 }
  67.                
  68.             }
  69.            
  70.            
  71.            
  72.            
  73.            
  74.        
  75.  
  76.     }// main ends here
  77.  
  78. }// program ends here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement