Results 1 to 2 of 2
Thread: Unresolved Compilation Problems
- 05-19-2011, 12:05 PM #1
Member
- Join Date
- May 2011
- Posts
- 1
- Rep Power
- 0
Unresolved Compilation Problems
Hello World!
I'm new to the Java programming language and I have never been the best when it comes to programming. Im preparing to study Java semester 2 this year, so I have managed to get my hands on an old assignment.
The program that I am trying to create is the program will record 12 temperatures which the user will input (using ConsoleReader).
The Program will record each input for each month, then print a line with all the numbers stored in the array. It will then work out, lowest, highest and average temperature. The last task that the program will run, is a count of number of months that fall between a certain temperature range.
So here's the program:
Java Code://Assignment 3 // Winston Ho // S3274617 import java.io.*; public class TempCalc { /** * @param args */ ConsoleReader console = new ConsoleReader(); public static void main(String[] args) { // recording input from user into array, using while conditions to test if values are within -10 and 40 range System.out.println( "Welcome to TempCalc" ); System.out.println("Reading Temperature Values for 12 Months"); int[] tempnum = new int[12]; int index; for(index = 0 ; index < 12 ; index = index + 1) { System.out.println("Please enter the value For Month " + index ); tempnum[index] = console.readInt(); boolean flag = false; while (flag == false) { if (tempnum[index] > 40 || tempnum[index] <= -10) { System.out.println ("The value must be within -10 and 40. Try again:"); tempnum[index] = console.readInt(); index--; } else { tempnum[index] = tempnum[index]; flag = true; } } } // working maximum temperature int highest; highest = tempnum[0]; for (index = 0; index < 12; index = index + 1) { if (tempnum[1] > highest) { highest = tempnum[index]; } } System.out.println ("The highest value was:" + highest); // working minimum temperature int lowest; lowest = tempnum[0]; for (index = 0; index < 12; index = index + 1) { if (tempnum[1] < lowest ) { lowest = tempnum[index]; } } System.out.println ("The lowest value was:" + lowest); // average temperature int avgtemp; avgtemp = 0; for (index = 0; index < 12; index = index + 1) { avgtemp = avgtemp + tempnum[index]; } System.out.println ("Average temp is:" + avgtemp ); // printing number of values between -10 and -1 int countone; for (index = 0; index <12 ; index = index + 1) { if (tempnum[index] >= -10 || tempnum[index]<= -1) { countone = countone + 1; } } System.out.println (" The number of months with values between -10 and -1 was:" + countone); // printing number of values between 0 and 9 int counttwo = 0; for (index = 0; index <12 ; index = index + 1); { if (tempnum[index] >= 0 || tempnum[index]<= 9) { counttwo = counttwo + 1; } } System.out.println (" The number of months with values between 0 and 9 was:" + counttwo); // printing number of values between 10 and 19 int countthree = 0; for (index = 0; index <12 ; index = index + 1) { if (tempnum[index] >= 10 || tempnum[index]<= 19) { countthree = countthree + 1; } } System.out.println (" The number of months with values between 10 and 19 was:" + countthree); // printing number of values between 20 and 29 int countfour = 0; for (index = 0; index <12 ; index = index + 1) { if (tempnum[index] >= 20 || tempnum[index]<= 29) { countfour = countfour + 1; } } System.out.println (" The number of months with values between 20 and 29 was:" + countfour); // printing number of values between and 0 int countfive = 0; for (index = 0; index <12 ; index = index + 1) { if (tempnum[index] >= 30 || tempnum[index]<= 40) { countfive = countfive + 1; } } System.out.println ( "The number of months with values between 30 and 40 was:" + countfive); System.out.println ("Thank you for using TempCalc"); } }
The ConsoleReader
Java Code:import java.io.*; public class ConsoleReader { public ConsoleReader() { reader = new BufferedReader(new InputStreamReader(System.in)); } private BufferedReader reader; public int readInt() { String inputString = readLine(); int n = Integer.parseInt(inputString); return n; } public String readLine() { String inputLine = ""; try { inputLine = reader.readLine(); } catch (IOException e) { System.out.println(e); System.exit(1); } return inputLine; } }
Now the issue I am having is that when I try and run the program, it throws an error stating:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The local variable countone may not have been initialized
The local variable countone may not have been initialized
at TempCalc.main(TempCalc.java:102)
Im puzzled at what I have done wrong, can anyone point me in the right direction?
- 05-19-2011, 12:17 PM #2
Similar Threads
-
Unresolved compilation problem
By ls7897 in forum New To JavaReplies: 9Last Post: 03-09-2011, 01:42 AM -
Java ME Referenced Jar gives Unresolved compilation problems
By tripleA in forum EclipseReplies: 0Last Post: 06-20-2010, 05:23 PM -
java.lang.Error: Unresolved compilation problems
By jon80 in forum New To JavaReplies: 0Last Post: 06-07-2009, 10:04 PM -
Unresolved compilation problem
By mew in forum New To JavaReplies: 2Last Post: 12-30-2007, 07:17 PM -
Unresolved compilation problem
By mew in forum New To JavaReplies: 3Last Post: 12-11-2007, 11:49 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks