# Can anyone help point out what I'm doing wrong? Centigrade-Fahrenh

• (2 Pages)
• 1
• 2

## 23 Replies - 1045 Views - Last Post: 16 November 2012 - 01:41 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=300088&amp;s=26f3dd041fd1267c1b825c25c74ec132&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 DtP1337

Reputation: 0
• Posts: 145
• Joined: 15-October 12

# Can anyone help point out what I'm doing wrong? Centigrade-Fahrenh

Posted 13 November 2012 - 08:29 PM

```
import java.text.DecimalFormat;

public class ConvertClass
{
private double tempC;

public ConvertClass()
{
setTempC(0.0);
}

public void setTempC(double c)
{
tempC = c;
}

public double getTempC()
{
return tempC;
}

public double getFahrenheit()
{
double F;
return F = (9*tempC)/5+32;
}

public void prt()
{
DecimalFormat dec = new DecimalFormat("#0.000");
System.out.println("Fahrenheit:" +dec.format(getFahrenheit()));
}

}

import java.util.Scanner;

public class ConvertDemo{
public static void main(String[] args)
{
double bTime,
eTime,
num = 1.0;

Scanner input = new Scanner(System.in);

System.out.println("What is the beginning temperature in centigrade?");
bTime = input.nextDouble();

System.out.println("What is the ending temperature in centigrade?");
eTime = input.nextDouble();

ConvertClass convert = new ConvertClass();
convert.setTempC(bTime);

If(!(bTime <= eTime))
{
System.out.println("Please enter valid Beginning Time and Ending Time.");
}

do {System.out.println("Results: " +convert.prt())}

while(bTime<=eTime);

while(bTime<=eTime)
{
System.out.println("Results: " +convert.prt());
}

for(bTime<=eTime)
{
System.out.println("Results: " +convert.prt());
}

}

```

Its giving me a bunch of ";" or ")" that I know aren't supposed to be there. Also how would I use the beginning and ending numbers to get centigrade and fahrenhiet from the class?

Is This A Good Question/Topic? 0

## Replies To: Can anyone help point out what I'm doing wrong? Centigrade-Fahrenh

### #2 raghav.naganathan

• Perfectly Squared ;)

Reputation: 410
• Posts: 1,449
• Joined: 14-September 12

## Re: Can anyone help point out what I'm doing wrong? Centigrade-Fahrenh

Posted 13 November 2012 - 08:34 PM

You have not used closing braces correctly...check if each opening brace has its corresponding closing brace...that should probably solve the problem.

regards,
Raghav

This post has been edited by raghav.naganathan: 13 November 2012 - 08:35 PM

### #3 DtP1337

Reputation: 0
• Posts: 145
• Joined: 15-October 12

## Re: Can anyone help point out what I'm doing wrong? Centigrade-Fahrenh

Posted 13 November 2012 - 08:41 PM

raghav.naganathan, on 13 November 2012 - 08:34 PM, said:

You have not used closing braces correctly...check if each opening brace has its corresponding closing brace...that should probably solve the problem.

regards,
Raghav

Yes, my mistake for not posting up to date, but I found that. I;m still gettings errors for lines 43, 50, 2 on 59, 61, and 65. Most of them involving a ; after the statement of the loops I need.

### #4 raghav.naganathan

• Perfectly Squared ;)

Reputation: 410
• Posts: 1,449
• Joined: 14-September 12

## Re: Can anyone help point out what I'm doing wrong? Centigrade-Fahrenh

Posted 13 November 2012 - 08:56 PM

Can you post the error log that you are getting...preferably a printscreen of your error log would do.

regards,
Raghav

### #5 DtP1337

Reputation: 0
• Posts: 145
• Joined: 15-October 12

## Re: Can anyone help point out what I'm doing wrong? Centigrade-Fahrenh

Posted 13 November 2012 - 09:08 PM

raghav.naganathan, on 13 November 2012 - 08:56 PM, said:

Can you post the error log that you are getting...preferably a printscreen of your error log would do.

regards,
Raghav

And what do I do with the begin and end times? I don't understand their purpose if TempC is involved.

### #6 raghav.naganathan

• Perfectly Squared ;)

Reputation: 410
• Posts: 1,449
• Joined: 14-September 12

## Re: Can anyone help point out what I'm doing wrong? Centigrade-Fahrenh

Posted 13 November 2012 - 09:12 PM

Ok I am guessing you need to add another closing braces after line 81...do that and see if it works.

regards,
Raghav

### #7 DtP1337

Reputation: 0
• Posts: 145
• Joined: 15-October 12

## Re: Can anyone help point out what I'm doing wrong? Centigrade-Fahrenh

Posted 13 November 2012 - 09:21 PM

Same errors.

I put the bracket in btw. Those errors are from post }

### #8 raghav.naganathan

• Perfectly Squared ;)

Reputation: 410
• Posts: 1,449
• Joined: 14-September 12

## Re: Can anyone help point out what I'm doing wrong? Centigrade-Fahrenh

Posted 13 November 2012 - 09:36 PM

Well, I think the bTime and eTime are redundant here as you will be directly inputting the temperature. You can remove those and just use the tempC values to do the conversion.

regards,
Raghav

This post has been edited by raghav.naganathan: 13 November 2012 - 09:38 PM

### #9 ChillyWilly

Reputation: 16
• Posts: 41
• Joined: 21-October 11

## Re: Can anyone help point out what I'm doing wrong? Centigrade-Fahrenh

Posted 13 November 2012 - 09:47 PM

Some of your if-statements don't have {} after them, also I see the while-loop on line 70 also does not have the correct curly braces.

proper syntax;

if()
{
}

while()
{
}

there should not be a semicolon after these statments.

### #10 DtP1337

Reputation: 0
• Posts: 145
• Joined: 15-October 12

## Re: Can anyone help point out what I'm doing wrong? Centigrade-Fahrenh

Posted 13 November 2012 - 09:52 PM

ChillyWilly, on 13 November 2012 - 09:47 PM, said:

Some of your if-statements don't have {} after them, also I see the while-loop on line 70 also does not have the correct curly braces.

proper syntax;

if()
{
}

while()
{
}

there should not be a semicolon after these statments.

That while is apart of a Do..While... and a semicolon I'm pretty sure ends the loop. The if statement also has brackets they are all left aligned.

### #11 raghav.naganathan

• Perfectly Squared ;)

Reputation: 410
• Posts: 1,449
• Joined: 14-September 12

## Re: Can anyone help point out what I'm doing wrong? Centigrade-Fahrenh

Posted 13 November 2012 - 11:34 PM

DtP1337, on 14 November 2012 - 10:22 AM, said:

ChillyWilly, on 13 November 2012 - 09:47 PM, said:

Some of your if-statements don't have {} after them, also I see the while-loop on line 70 also does not have the correct curly braces.

proper syntax;

if()
{
}

while()
{
}

there should not be a semicolon after these statments.

That while is apart of a Do..While... and a semicolon I'm pretty sure ends the loop. The if statement also has brackets they are all left aligned.

Well, what he meant about the if was that it should not be capitalized as If but it should be in small case if.

regards,
Raghav

### #12 DtP1337

Reputation: 0
• Posts: 145
• Joined: 15-October 12

## Re: Can anyone help point out what I'm doing wrong? Centigrade-Fahrenh

Posted 14 November 2012 - 07:30 AM

I am just now down to about 6 errors and still don't understand the need of the bTime / eTime Beginning and End times. Could anyone help me figure why I would and how I would use them to display with getTempC/getFahrenheit in the class?

### #13 DtP1337

Reputation: 0
• Posts: 145
• Joined: 15-October 12

## Re: Can anyone help point out what I'm doing wrong? Centigrade-Fahrenh

Posted 14 November 2012 - 07:29 PM

Whhat is wrong with the for loop? I get 3 errors all on it. And if you see anything else please advise.

```
import java.text.DecimalFormat;

public class ConvertClass
{
private double tempC;

public ConvertClass()
{
setTempC(0.0);
}

public void setTempC(double c)
{
tempC = c;
}

public double getTempC()
{
return tempC;
}

public double getFahrenheit()
{
double F;
return F = (9*tempC)/5+32;
}

public void prt()
{
DecimalFormat dec = new DecimalFormat("#0.000");
System.out.println("Fahrenheit:" +dec.format(getFahrenheit()));
}

}

-------------------------------------------------------------------------------------------------

import java.util.Scanner;

public class ConvertDemo{
public static void main(String[] args)
{
double bTime,
eTime,
num = 1.0;

Scanner input = new Scanner(System.in);

System.out.println("What is the beginning temperature in centigrade?");
bTime = input.nextDouble();

System.out.println("What is the ending temperature in centigrade?");
eTime = input.nextDouble();

ConvertClass convert = new ConvertClass();

while(!(bTime <= eTime))
{
System.out.println("Please enter valid Beginning Time and Ending Time.");

System.out.println("What is the beginning temperature in centigrade?");
bTime = input.nextDouble();

System.out.println("What is the ending temperature in centigrade?");
eTime = input.nextDouble();
}

num = bTime;

do
{
System.out.println("Results: " +convert.prt(num));
num++;
}

while(num<=eTime);

num = bTime;

while(num<=eTime)
{
System.out.println("Results: " +convert.prt(num));
num++;
}

num=bTime;

for(num<=eTime;bTime<=eTime;num++;)/>
{
System.out.println("Results: " +convert.prt(num));
}

}
}

```

### #14 DtP1337

Reputation: 0
• Posts: 145
• Joined: 15-October 12

## Re: Can anyone help point out what I'm doing wrong? Centigrade-Fahrenh

Posted 14 November 2012 - 07:35 PM

found the ; I didn't need, still getting 1 error saying num<=bTime is not a statement in my for loop...

### #15 raghav.naganathan

• Perfectly Squared ;)

Reputation: 410
• Posts: 1,449
• Joined: 14-September 12

## Re: Can anyone help point out what I'm doing wrong? Centigrade-Fahrenh

Posted 14 November 2012 - 09:20 PM

That is happening because the first part of a for loop is the initialization and not a condition.

You need to do something like this.
```for(num=eTime;bTime<=eTime;num++)
{
//code
}
```

The logic of this loop is not correct, nevertheless it will remove the error.

regards,
Raghav

This post has been edited by raghav.naganathan: 14 November 2012 - 09:23 PM