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

  • (2 Pages)
  • +
  • 1
  • 2

23 Replies - 721 Views - Last Post: 16 November 2012 - 01:41 PM Rate Topic: -----

#1 DtP1337  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 140
  • 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("Temperature Centigrade:" +dec.format(getTempC()));
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.");
	System.out.println("Please be sure your begining time is less than 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  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • 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

Was This Post Helpful? 1
  • +
  • -

#3 DtP1337  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 140
  • Joined: 15-October 12

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

Posted 13 November 2012 - 08:41 PM

View Postraghav.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.
Was This Post Helpful? 0
  • +
  • -

#4 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • 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
Was This Post Helpful? 0
  • +
  • -

#5 DtP1337  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 140
  • Joined: 15-October 12

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

Posted 13 November 2012 - 09:08 PM

View Postraghav.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.

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#6 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • 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
Was This Post Helpful? 0
  • +
  • -

#7 DtP1337  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 140
  • 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 }
Was This Post Helpful? 0
  • +
  • -

#8 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • 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

Was This Post Helpful? 0
  • +
  • -

#9 ChillyWilly  Icon User is offline

  • New D.I.C Head

Reputation: 16
  • View blog
  • 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.
Was This Post Helpful? 1
  • +
  • -

#10 DtP1337  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 140
  • Joined: 15-October 12

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

Posted 13 November 2012 - 09:52 PM

View PostChillyWilly, 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.
Was This Post Helpful? 0
  • +
  • -

#11 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

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

Posted 13 November 2012 - 11:34 PM

View PostDtP1337, on 14 November 2012 - 10:22 AM, said:

View PostChillyWilly, 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
Was This Post Helpful? 2
  • +
  • -

#12 DtP1337  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 140
  • 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?
Was This Post Helpful? 0
  • +
  • -

#13 DtP1337  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 140
  • 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("Temperature Centigrade:" +dec.format(getTempC()));
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("Please be sure your begining time is less than 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));
}
	
}
}



Was This Post Helpful? 0
  • +
  • -

#14 DtP1337  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 140
  • 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...
Was This Post Helpful? 0
  • +
  • -

#15 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • 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

Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2