Results 1 to 14 of 14
  1. #1
    alihht is offline Member
    Join Date
    Nov 2009
    Posts
    19
    Rep Power
    0

    Default I need help here

    I'm a beginner;

    I need some one to help me to solve this problem:

    Write a Temperature class tha represents temperatures in degrees in both Celsius and Fahrenheit. Use a floating-point number for the temperature and a charcter for the sclae: eather 'C' for Celsius or 'F' for Fahrenheit. he class should have:
    • four constructors: one for the number of degrees, one for the scale, one for the both degrees and scale, and a defult construstor. For each of these construcores assume zero degrees if no balue is specified and Celsius if no scale is given.

      two accessor methods: one toreturn the temperature in degrees Celsius, the other to return it in degrees Fahrenhit.

      Three comparsion methods: one to test whether two temperatures are equal, one to test whether one temperature is grater than another , and one to test whether one temperature is less than another.

      Three set methods: one to set the number of degrees, one to set the scale and one to set both.

    Write a driver program that tsts all the methods. Be sureto invoke each of the constructors, o include at least one true and one false case for each comparison method, and to testa leastthe following three temperaure pairs for equality: 0.0 degree C and 32.0 degres F, -40.0 degrees C and -40.0 degrees F and 100.0 degrees C and 212.0 degrees F.
    Regards,

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    What you've done is to post your entire assignment without showing what work you've done, without asking a specific question, and that is not how to get help here (or at any forum). For one, we have no idea what you're having trouble with, so we won't know how to advise you. For another, if you don't at least try to solve what you can first, you're cheating yourself out a valuable part of your learning experience, and finally it suggests that you want someone to post a complete solution, thereby doing your homework for you, and I know that this was not your intent.

    So please try to solve as much of the problem that you can first, then post what you've done using code tags (see my signature), and then ask a specific question. Do this and you'll have many folks willing to help you.

    Much luck!

  3. #3
    alihht is offline Member
    Join Date
    Nov 2009
    Posts
    19
    Rep Power
    0

    Default

    Sorry, I'm not a student.

    I just bought a book and I want to try solving as much as I can from that book to learn something. I didn't think that there is somebody will doubt that I'm a student.

    Any way, thank you for your "doubting":

    This is what I have done so far:

    Java Code:
    import java.util.*;
    public class Tempreture();
    {
    	private char scale;
    	private char obsScale;
    	private double TempretureDegree;
    	private double celsius;
    	private double fahrenhiet;
    	
    	public Tempreture ()
    	{
    		scale = 'C';
    		obsScale = 'F';
    		TempretureDegree = 0.0;
    		celsius = 0.0;
    		fahrenhiet =0.0;
    		
    	}
    	
    	public void readInputs()
    	{
    		System.out.println("Enter the scale of the degree: ");
    		System.out.println("Enter the value of the Tempreture: ");
    	}
    	
    	public void writeOutputs()
    	{
    		System.out.println("The Tempreture degree in" + scale + " is: " + TempretureDegree);
    		System.out.println("It equles in" + obsScale + ": " + TempretureDegree);
    	}
    	
    	public Tempreture numberOfDegree()
    	{
    		return TempretureDegree;
    	} 
    		public Tempreture scale;
    		{
    			return scale;
    		}
    	
    	public static double Celsius()
    	{
    		double result = 0;
    		if (scale == 'C')
    			TempretureDegree = celsius;
    			result = ((9(celsius)/5)+32);
    			result = fahrenhiet;
    			fahrenhiet = TempretureDegree;
    			return result;
    	}
    	public static double Fahrenhiet()
    		if (sclae == 'F' )
    			TempretureDegree = fahrenhiet;
    			celsius = (5(fahrenhiet - 32)/9);
    			celsius = TempretureDegree; 
    				return celsius;
        }
        
    }
    Thank you for your reply.
    Last edited by alihht; 11-12-2009 at 05:10 AM.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by alihht View Post
    Sorry, I'm not a student.
    Doesn't really matter. The first post was a problem-dump whether the poster was a student or not. Now you are posting code, so this is much better. Now all you need to do is to post a specific question, and we'll be really getting somewhere.

    Much luck!

  5. #5
    alihht is offline Member
    Join Date
    Nov 2009
    Posts
    19
    Rep Power
    0

    Default

    Dosen't matter!!!!

    Any way,

    1- I don't know how can I use the constructors. Am I in the right way or not?
    2- I don't know how can I use the set methods also and where I sould put them in the code.
    3- The Jcreator found problems in my code; I tried to solve them, but I the problems still exist.

    Thank ya.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I've looked through your code and it's chock full of mistakes, in fact too many to correct, and I recommend that you chuck it.

    A few suggestions:
    1) Always code with a plan first. Write out an outline of what you are trying to code before typing in code.
    2) When creating a program, compile often, perhaps after adding every line. If you get a compile error, then don't add another line until the error has been fixed. Do this and you'll usually keep your compile errors down to a manageable few. Don't do it and you'll end up with a rat's nest of errors. If you eventually use an IDE such as Eclipse, it will flag the errors for you as you type.
    3) Before creating a class, find a simple class example (in your book or the Sun tutorials) and use that as a template. You'll see for instance that there is no parenthesis () in the class declaration line, nor is there ever a semicolon.
    4) Read, read, read. There's no substitute for this.

    You can find the Sun tutorials here:
    The Sun Java Tutorials
    Much luck!

  7. #7
    alihht is offline Member
    Join Date
    Nov 2009
    Posts
    19
    Rep Power
    0

    Default

    You helped me a lot!!! thanks

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    specifics:
    Problems:

    Java Code:
    public class Tempreture();
    check the spelling of Temperature
    class declarations don't have a parenthesis
    nor semicolon

    Java Code:
       public void readInputs()
       {
          System.out.println("Enter the scale of the degree: ");
          System.out.println("Enter the value of the Tempreture: ");
       }
    Best to keep your Temperature class "pure" and not have this kind of code within the class. Myself I'd have this user interaction type code in a class that uses the Temperature class, either that or the main method.

    Java Code:
       public Tempreture numberOfDegree()
       {
          return TempretureDegree;
       }
    Are you sure this method returns a Temperature object? What type is numberOfDegree? Perhaps you want that to be the method's return type.

    Java Code:
          public Tempreture scale;
          {
             return scale;
          }
    This method is completely borked as Java thinks that you're re-declaring the scale variable as type "Tempreture". Reread how to declare a method and emulate the examples you see.

    Java Code:
    public static double Celsius()...
    This and the next method mix static methods and non-static variables in a way that just won't work. Read up on the difference between the two as it will be important as you go on.

  9. #9
    alihht is offline Member
    Join Date
    Nov 2009
    Posts
    19
    Rep Power
    0

    Default

    This is what I've done so far:

    Temperature Calss:

    Java Code:
    import java.util.*;
     public class Temperature
     {
     	private Float temperature;
     	private char scale;
     	private Float result;
     	
     	
      	public Temperature()
     	{
     	/*
      	 * To set temperature to 0.0.
      	 * To set scale to C.
     	 */
     		setTemp(new Float(0.0));
     		setScale('C');	
     	}
     	
     	public Temperature(Float degree)
     	{
     	/*
     	 * To set temperature to a degree value
     	 * To set scale to C as a defult.
     	 */
     		setTemp(degree);
     		setScale('C');
     	}
     	
     	public Temperature(char scaleChar)
     	{
     	/* 
     	 * To set scale to a value (C or F) 
     	 * To set temperature to 0.0.
     	 */
     		setScale(scaleChar); 
     		setTemp(new Float(0.0));
     	}
     	
     	public Temperature(char scaleChar, Float degree)
     	{
     	/*
     	 * To set scale (C or F) and temperature (degree) to defult value.
     	 */
     		setScale(scaleChar); 
     		setTemp(degree);
     	}
     	
     	public void setTemp(Float degree)
     	{
     	/*
     	 * Assigning temperature to degree.
     	 */
     	 
     		temperature = degree;
     	}
     	
     	public Float getTemp()
     	{
     	/*
     	 * To return the temperature
     	 */
     	 
     	 
     		return temperature;
     	}
     	
     	public void setScale(char scaleValue)
     	{
     	/*
     	 * Assigning scale to scaleValue.
     	 */
     	 
     	 
     	 scale = scaleValue;
     	 	  		
     	}
     	
     	public char getScale()
     	{
     	/*
     	 * To return scale.
     	 */
     		return scale;
     	}
     	
     	public void setResult(Float resultValue)
     	{
     	/*
     	 * Assiging result to resultValue.
     	 */
     		result = resultValue;
     	}
     	
     	public Float getResult()
     	{
     	/*
     	 * To return the result.
     	 */
     		return result;
     	}
     	
     	public void setValues(char scaleValue, Float result)
     	{
     	/*
     	 * To set scale in scaleVlue and temperature in result.
     	 */
     		setScale(scaleValue);
     		setTemp(result);
     	}
     	
     	public Float FahrenheitToCelsius(Float value)
     	{
     	/*
     	 *Converting Fahrenheit to Celsius.
     	 */
     	  
     		return (5*(value - 32))/9;
     	}
     	
     	public Float CelsiusToFahrenheit(Float value)
     	{
     	/*
     	 * Converting Celsius to Fahrenheit.
     	 */
     	   
     		return ((9*value)/5) + 32;
     	}
     	
     	public boolean ifEqual(Float temperature1, Float temperature2)
     	{
     	/*
     	 * Testing the equality of the first tempreture and the second one.
     	 */
     		if (temperature1 == temperature2)
     		{
     			return true;
     		}
     		else 
     		{
     			return false;
     		}
     	}
     	
     	public boolean ifGreater(Float temperature1, Float temperature2)
     	{
     	/*
     	 * Testing if one of the temperatures is grater than the other.
     	 */
     		if (temperature1 > temperature2)
     		{
     			return true;
     		}
     		else 
     		{
     			return false;
     		}
     	}
     	
     	public boolean ifLess(Float temperature1, Float temperature2)
     	{
     	/*
     	 * Testing if one of the temeratures is less than the other.
     	 */
     		if (temperature1 < temperature2)
     		{
     			return true;
     		}
     		else 
     		{
     			return false;
     		}
     	}
     	
     }
    Test class:

    Java Code:
     
    public class Test
    {
    	
    	/*
    	 * test values: 
    	 */
    	 
    	public static void main(String args[])
    	{
    		
    		System.out.println("testing the First temperature");
    		Temperature temperatureNo1 = new Temperature();
    		System.out.println("Current Value of Scale: " + temperatureNo1.getScale());
    		System.out.println("Current Value of Temperature: " + temperatureNo1.getTemp());
    		
    		
    		System.out.println("Equal: " + temperatureNo1.ifEqual(temperatureNo1.CelsiusToFahrenheit(new Float(0.0)), temperatureNo1.FahrenheitToCelsius(new Float(32.0))));
    		
    		System.out.println("Less: " + temperatureNo1.ifLess(temperatureNo1.CelsiusToFahrenheit(new Float(0.0)), temperatureNo1.FahrenheitToCelsius (new Float(32.0))));
    		
    		System.out.println("Greater: " + temperatureNo1.ifGreater(temperatureNo1.CelsiusToFahrenheit(new Float(0.0)), temperatureNo1.FahrenheitToCelsius (new Float(32.0))));
    		
    		
    		System.out.println("");
    		System.out.println("");
    		
    		System.out.println("testing the Second temperature");
    		Temperature temperatureNo2 = new Temperature();
    		
    		System.out.println("Current Value of Scale: " + temperatureNo2.getScale());
    		System.out.println("Current Value of Temperature: " + temperatureNo2.getTemp());		
    		
    		System.out.println("Equal: " + temperatureNo2.ifEqual(temperatureNo2.CelsiusToFahrenheit(new Float(-40.0)), temperatureNo2.FahrenheitToCelsius (new Float(-40.0))));
    		
    		System.out.println("Less: " + temperatureNo2.ifLess(temperatureNo2.CelsiusToFahrenheit(new Float(-40.0)), temperatureNo2.FahrenheitToCelsius (new Float(-40.0))));
    		
    		System.out.println("Greater: " + temperatureNo2.ifGreater(temperatureNo2.CelsiusToFahrenheit(new Float(-40.0)), temperatureNo2.FahrenheitToCelsius (new Float(-40.0))));
    		
    		System.out.println("");
    		System.out.println("");
    		
    		System.out.println("testing the third temperature");
    		Temperature temperatureNo3 = new Temperature();
    		
    		System.out.println("Current Value of Scale: " + temperatureNo3.getScale());
    		System.out.println("Current Value of Temperature: " + temperatureNo3.getTemp());		
    		
    		System.out.println("Equal: " + temperatureNo3.ifEqual(temperatureNo3.CelsiusToFahrenheit(new Float(100.0)), temperatureNo3.FahrenheitToCelsius (new Float(212.0))));
    		
    		System.out.println("Less: " + temperatureNo3.ifLess(temperatureNo3.CelsiusToFahrenheit(new Float(100.0)), temperatureNo3.FahrenheitToCelsius (new Float(212.0))));
    		
    		System.out.println("Greater: " + temperatureNo3.ifGreater(temperatureNo3.CelsiusToFahrenheit(new Float(100.0)), temperatureNo3.FahrenheitToCelsius (new Float(212.0))));
    		
    		
    		
    	}
    }
    The problem with me is : I just tride to make like what I saw in the book in some of my codes of both classes.

    however, the program didn't give me the right answers.

    So, can anybody help me.

    don't tell me read in that website or in that book.

    if you want to help me, just show me how can to fix my problem.

  10. #10
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by alihht View Post
    don't tell me read in that website or in that book.
    Don't read that book! It'll make your eyes bleed and your ears fall off!

    kind regards,

    Jos ;-)

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by alihht View Post
    if you want to help me, just show me how can to fix my problem.
    Um,... by reading more and understanding what you read? I mean seriously, what kind of request is this??

  12. #12
    alihht is offline Member
    Join Date
    Nov 2009
    Posts
    19
    Rep Power
    0

    Default

    I mean you don't have to tell me read. I bought the book to read; so do you think I'm waiting for you to tell me: read the book??

    Thank you for your advice. but I don't need it here. I need some one to tell me how can I do this not to tell me about reading the book that I bought it to read it.

    If you can help me just help me. If you can't say sorry I can't help you. That will end it, won't it?

    Thank you any way.

  13. #13
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    If you want help then at least be specific, otherwise you'll be told to go and read the book until you are able to post a specific question. You just said

    The problem with me is : I just tride to make like what I saw in the book in some of my codes of both classes.

    however, the program didn't give me the right answers.

    So, can anybody help me.
    What does that mean? What answers did you get and what answers did you expect?

    Did you put System.out.println statements to track the values of the variables and therefore be able to tell why you got your current output?

    The idea is that you learn not that you get solutions.

  14. #14
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by r035198x View Post
    The idea is that you learn not that you get solutions.
    Amen to that!

Posting Permissions

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