Results 1 to 3 of 3
  1. #1
    snobbysteven is offline Member
    Join Date
    Oct 2012
    Posts
    17
    Rep Power
    0

    Unhappy what am I doing wrong?

    heres what I have so far. When I try to do (take note for my returns I just put a temp random return to come back to later to set.)

    Java Code:
    public class Temperature0000
    {
      public static void main(String[] args)
      {
        Temperature t2;
        t2 = new Temperature();
        
     
    }
    it Errors but I just did a program with the same setup and it worked fine.

    Java Code:
    public class Temperature0000
    {
      public static void main(String[] args)
      {
        Temperature t2;
        t2 = new Temperature();
        
        
        System.out.println ("Welcome to the Temperature Converter");
        
        System.out.println ("please enter a degree");
        t1.setNewDegrees();
        
      }
    }

    Java Code:
    import java.util.*;
    
    public class Temperature
    {
     
        
        Scanner keyboard = new Scanner(System.in);
        
         
        
        private double degrees;
        private char units;
        
        
        private boolean C;
        private boolean F;
        
        
        public Temperature(double NewDegrees, char newUnits)
        {
          set(NewDegrees, newUnits);
        }
        
        public Temperature(double newDegrees)
        {
         set(newDegrees);
        }
        
        public Temperature(char newUnits)
        {
          set (newUnits);
        }
       
        
        
       
        
        // set methods
        
        public void set(double newDegrees, char newUnits)
        {
          newDegrees = 0;
          newUnits = 0;
        }
        
        public void set(double newDegrees)
        {
          newDegrees = 0;
        }
        
        public void set(char newUnits)
        {
          newUnits = 0;
        }
        
        //public get accessors
        
        public double getC()
        {
          return 5;
        }
        
        public double getF()
        {
          return 5;
        }
        
        
        //comoparison methods
        
        
        public boolean equals()
        {
          if( C == F)
          
          System.out.println("hello");
          return C;
            
          }
        
          
          
        
        public boolean isGreaterThan()
        {
          if(C && F) 
          
            System.out.println("C.isgreaterthen F");
          return true;
          
        }
        
        
        public double isLessThan()
        {
          if( C && F)
          {
            System.out.println("C is less then F");
          }
          System.out.println("C is not less then F");
          return 3.4 + 2.5;
        }
        
    }
    Last edited by Tolls; 11-02-2012 at 11:23 AM. Reason: Fixed code tags

  2. #2
    sibernewf is offline Member
    Join Date
    Mar 2011
    Posts
    48
    Rep Power
    0

    Default Re: what am I doing wrong?

    ok, for a start, have another look at your class name.

    Its Temperature0000
    yet you are using a constructor of Temperature().

    Cheers

  3. #3
    sibernewf is offline Member
    Join Date
    Mar 2011
    Posts
    48
    Rep Power
    0

    Default Re: what am I doing wrong?

    With a quick look, you create a Temperature variable t2,
    yet you call t1.setNewDegrees();
    when you have no t1 variable created

    I would also recommend you move the Scanner out of the temperature class. Its probably more appropriate in your class with the main method.

    Try to consider your Temperature class as an object, so it may have 'things' that all objects have. For example a person, has arms, legs etc.
    You can consider these items in an object as defining the 'state' of an object.
    your Temperature object may have :

    temperature in degrees,
    units - Fahrenheight or Celsius,
    maybe a maximum temperature and minimum temperature
    etc..

    other than state, objects also have behaviour.

    for example, you can :
    increase or decrease the temperature,
    convert the temperature to other units
    etc..

    So try to think of things as objects having state (things that identify it) and behaviour (actions that the object can perform).
    If you think about it like this, I find it much easier to create more useable classes.


    I know the above is slightly off topic, but I believe it's useful to understand object oriented practices in order to create better applications.


    See how it goes after you look at what I put in the top of my post and if there are still errors, post more details, perhaps include the error you are getting.
    Last edited by sibernewf; 11-02-2012 at 06:20 AM.

Similar Threads

  1. Replies: 4
    Last Post: 06-11-2013, 02:37 AM
  2. I can't find anything wrong with this but somehow it's wrong.
    By Biscuit Tickler in forum New To Java
    Replies: 2
    Last Post: 09-12-2012, 10:28 PM
  3. What am I doing wrong?
    By DuncanHollows in forum New To Java
    Replies: 2
    Last Post: 04-08-2012, 06:33 PM
  4. What did I do wrong?
    By Astralogic in forum New To Java
    Replies: 6
    Last Post: 04-05-2012, 01:16 PM
  5. what wrong
    By pro85 in forum New To Java
    Replies: 3
    Last Post: 02-09-2009, 02:07 PM

Posting Permissions

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