Created
September 22, 2015 12:51
-
-
Save NathanJang/9a58859c54a217e78268 to your computer and use it in GitHub Desktop.
APCS Unit 1 Troll FRQ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.swing.JOptionPane; | |
public class DailyTemp | |
{ | |
public static void main(String[] args) { | |
String numDays = JOptionPane.showInputDialog("Please enter the number of days"); | |
int intnumDays = Integer.parseInt(numDays); | |
// number 2 | |
int[] dates = new int[intnumDays]; /* | |
*/ | |
// number 3 | |
for (int i = 0; i < intnumDays; i++) { | |
dates[i] = i+1; // 22 | |
} // int a = a; \\ this is a comment | |
// number 4 | |
int[] dailyTemps = new int[intnumDays]; | |
{ | |
// number 5 | |
int range = 100 - (-100); | |
int minimum = -100; | |
for (int i = 0; i < dailyTemps.length; i++) { | |
dailyTemps[i] = (int)(range * Math.random() + minimum); | |
} // new System(); | |
} // end number 5 | |
// number 6 | |
String[] forecast = new String[intnumDays]; // | |
/* number 7 */ for (int i = 0; i < forecast.length; i++) { | |
int temp = dailyTemps[i]; | |
String aForecast = temp >= 80 ? "Hot!" : (temp >= 50 ? "Moderate" : | |
(temp >= 32 ? "Cold" : "Freezing!")); | |
forecast[i] = aForecast; | |
} // args[args.length] = 0118999; | |
// number 8 | |
System.out.println("Date\tDaily Temperature (f)\tForecast"); | |
// number 9 | |
for (int i = 0; i < intnumDays; i++) { | |
int date = dates[i], temp = dailyTemps[i]; | |
String aForecast = forecast[i]; | |
System.out.println(String.format("%d\t%d\t%s", date, temp, aForecast)); | |
} // woohoo! | |
{{{{{ } /* have a great day! */ } /* } } { | |
} } */ } } } // end nothing | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment