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
*/
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  );
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:");
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"); }
}```

Java Code:
```import java.io.*;
{
}

{
int n = Integer.parseInt(inputString);
return n;
}

{
String inputLine = "";
try
{

} 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?

2. Java Code:
```		int countone;
for (index = 0; index <12 ; index = index + 1)
{
if (tempnum[index] >= -10 || tempnum[index]<= -1)
{
countone = countone + 1;
}
}```
You don't set a start value for countone.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•