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

  • (2 Pages)
  • +
  • 1
  • 2

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

#16 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 15 November 2012 - 07:02 AM

Thank you, but after fixing that lines 82, 92, 100.


    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));  

    }  




Why do they throw errors about not being the right length? I'm currently at school waiting on my proffessor but after he showed me some examples I've got to where I am also stumping him with the same problem. Any ideas?

This post has been edited by pbl: 15 November 2012 - 07:18 AM
Reason for edit:: Fixed posted code ... again

Was This Post Helpful? 0
  • +
  • -

#17 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,908
  • Joined: 06-March 08

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

Posted 15 November 2012 - 07:20 AM

    num=bTime;          
    for(num<eTime;bTime<=eTime;num++;)/>/>/>/>  
    {  


for(num<etime;
is not a valid loop initializer
Was This Post Helpful? 1
  • +
  • -

#18 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 15 November 2012 - 07:26 AM

So num=bTime would be?
Was This Post Helpful? 0
  • +
  • -

#19 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,908
  • Joined: 06-March 08

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

Posted 15 November 2012 - 07:48 AM

always depends what you want to do
for sure that

for(num<eTime;bTime<=eTime;num++;)
should be
for(num = eTime; bTime <= eTime; num++) // without the last ;

but this is an ackward loop if you do not change bTime or eTime inside the loop then
bTime <= eTime
will be true for ever and the loop will be infinite

usually a for() loop has this format

for(num = eTime; <test on num here>; num++)

Happy coding
Was This Post Helpful? 2
  • +
  • -

#20 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 15 November 2012 - 07:54 AM

Thanks i'll try that when I get home.
Was This Post Helpful? 0
  • +
  • -

#21 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 16 November 2012 - 01:16 PM

I believe this will be my final post on this subject if anyone can answer how I am to get the correct output for centigrade and fahrenheit. I have almost got it I believe just missing the correct output.


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;
	
	System.out.println("_______________________________________");
	do 
{
	System.out.println("Results:");
	convert.prt();
	num++;
}
	
	while(num<=eTime);
	
	num = bTime;
	
	
	System.out.println("_______________________________________");
	
	while(num<=eTime)
{
	System.out.println("Results:");
	convert.prt();	
	num++;
}

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

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

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()));
}


}



Was This Post Helpful? 0
  • +
  • -

#22 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 16 November 2012 - 01:36 PM

Nevermind I found it ... needed a convert.SetTempC(num); command to send TempC to the num variable so that it would be processed in both getTempC / getFahrenheit... Hooty Hoo!!!


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;
	
	System.out.println("_______________________________________");
	do 
{
	System.out.println("Results:");
	convert.setTempC(num);
	convert.prt();
	num++;
}
	
	while(num<=eTime);
	
	num = bTime;
	
	
	System.out.println("_______________________________________");
	
	while(num<=eTime)
{
	System.out.println("Results:");
	convert.setTempC(num);
	convert.prt();	
	num++;
}

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

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

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()));
}


}



Was This Post Helpful? 0
  • +
  • -

#23 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,908
  • Joined: 06-March 08

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

Posted 16 November 2012 - 01:37 PM

Gheeezzz you made it complicated for nothing
with a lot of useless while and unsused methods
I guess this is what you want

import java.text.DecimalFormat;
import java.util.Scanner;

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

		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();


		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;


		System.out.println("Results:");
		for(num=bTime; num <= eTime; num++)
		{
			ConvertClass cc = new ConvertClass(num);
			cc.prt();
		}

	}

}

class ConvertClass
{
	DecimalFormat dec = new DecimalFormat("#0.000");
	private double tempC;

	public ConvertClass(double tempC)
	{
		this.tempC = tempC;
	}
	private double getFahrenheit()
	{
		return (9*tempC)/5+32;
	}

	public void prt()
	{
		System.out.print("Temperature Centigrade: " +dec.format(tempC));
		System.out.println("    Fahrenheit: " +dec.format(getFahrenheit()));
	}
}


Was This Post Helpful? 1
  • +
  • -

#24 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 16 November 2012 - 01:41 PM

It was required in the project to understand each one used.

I think the unused methods are put to use now. :)

This post has been edited by DtP1337: 16 November 2012 - 01:44 PM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2