Results 1 to 13 of 13
  1. #1
    Goff256 is offline Member
    Join Date
    Apr 2011
    Posts
    9
    Rep Power
    0

    Default Another easy program I should be able to do

    public class Radius {

    public static void main(String[] args) {
    // TODO code application logic here
    double myRadius = 1;
    calculateArea();
    calculateDiameter();
    thefirst();

    }
    public static void calculateDiameter(double myRadius)
    { double theDiameter;
    theDiameter = myRadius * 2;
    }
    public static void calculateArea(double myRadius)
    { double theRadius;
    theFirst = myRadius * 3.14;
    theArea = theFirst * theFirst;
    System.out.println("The Circle with Radius"+myRadius+"has Diameter of"+theDiameter+"and area"+theArea);


    }
    }


    It's supposed to have:
    a default constructor that sets the radius to 1
    a method to set the value of the radius
    a method to return the value of the radius
    a method to compute and return the circle's diameter
    a method to compute and return the circle's area

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Quote Originally Posted by Goff256 View Post
    It's supposed to have:
    Then you had better start writing the code. If you have any problems then ask a specific question and you will get a specific answer. (Other than asking for the code)

  3. #3
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    The code isn't quite right. You don't have a constructor and a setter and getter. You should also have an instance variable for the class. Which is manipulated in the getter, and setter. The constructor initializes an object with the radius of 1.

  4. #4
    Goff256 is offline Member
    Join Date
    Apr 2011
    Posts
    9
    Rep Power
    0

    Default

    Quote Originally Posted by Junky View Post
    Then you had better start writing the code. If you have any problems then ask a specific question and you will get a specific answer. (Other than asking for the code)
    I thought I had all of it. D:

    I wasn't asking for code, merely stating the rules of the game

    The code isn't quite right. You don't have a constructor and a setter and getter. You should also have an instance variable for the class. Which is manipulated in the getter, and setter. The constructor initializes an object with the radius of 1.
    *smacks forehead* Now I feel like a massive idiot.

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Hope you were able to solve it. Your main method should only really be creating objects and calling the methods on it, sort of like this.

    Java Code:
    public static void main(String[] args){
      Orange o = new Orange(); //constructor
      int ripeness = o.getRipeness(); //getter
      o.setWeight(10); //setter
      int calories = o.calculateCalories(); //method to do something
    }

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Read your first post. It was a code dump and some requirements. No information about problems you have (errors, incorrect behaviour) and no question. Yet you expect someone to help you. Luckily sunde took pity upon you and provided some guidance but in future ask a specific question so we don't have to guess as to what you want.

  7. #7
    Goff256 is offline Member
    Join Date
    Apr 2011
    Posts
    9
    Rep Power
    0

    Default

    Java Code:
    public class Radius {
    
        public Radius
    	myRadius = 1;
    	 
        public static void main(String[] args) {
            double myRadius = 1;
            calculateArea(myRadius); 
            calculateDiameter(myRadius); 
            thefirst(myRadius);
            
        }
        public static void calculateDiameter(double myRadius)             
        { double theDiameter;
            theDiameter = myRadius * 2;    
                    }
        public static void calculateArea(double myRadius)
        {  double theRadius;
             theFirst = myRadius * 3.14;
             theArea = theFirst * theFirst;
             System.out.println("The Circle with Radius"+myRadius+"has Diameter of"+theDiameter+"and area"+theArea);
             
        
        }
    }
    Compiling 1 source file to C:\Users\Michael\Documents\NetBeansProjects\Radius \build\classes
    C:\Users\Michael\Documents\NetBeansProjects\Radius \src\radius\Radius.java:4: incompatible types
    found : int
    required: Radius
    public Radius myRadius = 1;
    C:\Users\Michael\Documents\NetBeansProjects\Radius \src\radius\Radius.java:10: cannot find symbol
    symbol : method theFirst(double)
    location: class Radius
    theFirst(myRadius);
    C:\Users\Michael\Documents\NetBeansProjects\Radius \src\radius\Radius.java:11: cannot find symbol
    symbol : variable theFirst
    location: class Radius
    theArea(theFirst);
    C:\Users\Michael\Documents\NetBeansProjects\Radius \src\radius\Radius.java:17: cannot find symbol
    symbol : variable theDiameter
    location: class Radius
    theDiameter = myRadius * 2;
    C:\Users\Michael\Documents\NetBeansProjects\Radius \src\radius\Radius.java:20: cannot find symbol
    symbol : variable thefirst
    location: class Radius
    thefirst = myRadius * 3.14;
    C:\Users\Michael\Documents\NetBeansProjects\Radius \src\radius\Radius.java:24: cannot find symbol
    symbol : variable theArea
    location: class Radius
    { theArea = theFirst * theFirst;
    C:\Users\Michael\Documents\NetBeansProjects\Radius \src\radius\Radius.java:24: cannot find symbol
    symbol : variable theFirst
    location: class Radius
    { theArea = theFirst * theFirst;
    C:\Users\Michael\Documents\NetBeansProjects\Radius \src\radius\Radius.java:24: cannot find symbol
    symbol : variable theFirst
    location: class Radius
    { theArea = theFirst * theFirst;
    C:\Users\Michael\Documents\NetBeansProjects\Radius \src\radius\Radius.java:25: cannot find symbol
    symbol : variable theDiameter
    location: class Radius
    System.out.println("The Circle with Radius"+myRadius+"has Diameter of"+theDiameter+"and area"+theArea);
    C:\Users\Michael\Documents\NetBeansProjects\Radius \src\radius\Radius.java:25: cannot find symbol
    symbol : variable theArea
    location: class Radius
    System.out.println("The Circle with Radius"+myRadius+"has Diameter of"+theDiameter+"and area"+theArea);
    10 errors

    I know I'm horrible at Java. It's why I'm coming to you guys.

  8. #8
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Did you forget a bunch of parentheses, brackets, and instance variables there?

  9. #9
    Goff256 is offline Member
    Join Date
    Apr 2011
    Posts
    9
    Rep Power
    0

    Default

    parenthesis- Dunno
    brackets- Don't think so
    variables- isn't that the 'double' whatever? If I'm asking dumb questions, tell me. If I'm being an idiot, tell me.

    Java Code:
    public class Radius {
    
        public Radius myRadius = 1;
    
        public static void main(String[] args) {
            double myRadius = 1;
            calculateArea(myRadius);
            calculateDiameter(myRadius);
            theFirst(myRadius);
            theArea(theFirst);
            
    
        }
    
        public static void calculateDiameter(double myRadius) {
            double theDiameter;
            theDiameter = myRadius * 2;
        }
        public static void calculateFirst(double myRadius){
            double thefirst;
            thefirst = myRadius * 3.14;
                    }
    
        public static void calculateArea(double myRadius)
        {   double theArea;
            theArea = theFirst * theFirst;
             System.out.println("The Circle with Radius"+myRadius+"has Diameter of"+theDiameter+"and area"+theArea);
             
        
        }
    }

  10. #10
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Then why the heck do you assign 1 to an object??

    EDIT: Taking another look at this, you seem to not understand methods and variables. Please take a look at the tutorials to get up to speed.
    Last edited by ra4king; 04-16-2011 at 05:53 AM.

  11. #11
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You seem to not understand how to build a class correctly. We could show you however it may be better to send you to the tutorials first. They should have examples that can help you quite a bit. Check them(link in above post) and come back if you still don't quite understand.

  12. #12
    Goff256 is offline Member
    Join Date
    Apr 2011
    Posts
    9
    Rep Power
    0

    Default

    I don't know what it is, but I keep looking through those tutorials and I keep drawing a big blank on how to do one thing. I must have tried to rewrite my code at least fifteen times, last night and this morning, and I keep running into a new error that epitomizes sunde being right.

    Java Code:
    import javax.swing.*;
    
    public class Radius{
        
        private Double myRadius;
        public Radius(double myRadius){
            myRadius = 1;}      
        public void main(Double [] args){
            double theRadius;
            double theDiameter;
            double theArea;
            theRadius = myRadius;
            theDiameter = myRadius * 2;
            theArea = myRadius * myRadius * 3.14;
        }
        public void theRadius(Double [] args){
            double theRadius;
            theRadius = Double.parseDouble(JOptionPane.showInputDialog("Enter the Radius"));
        }
        public void theDiameter(Double [] args){
            double theDiameter;
            theDiameter = myRadius * 2;
        }
        public void theArea(Double [] args){
            double theArea;
            theArea = myRadius * myRadius * 3.14;
                    
        }
                }
    No main classes found shows when I try to run it. I don't get it. I could easily make a VB program that does this exact thing, but the instant I try to make a Java program I come up with this mess.

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

    Default

    The class above doesn't have a proper main method for it to run. A main method must look like this:

    Java Code:
    public static void main(String[] args) {
       //... your code goes in here.
    }

    Also: What's with all the double[] args parameters that are never used? Please keep studying the tutorials as that is where you have the best shot at getting a grip on the basics.

    Edit: your code is still chock-full of errors as if you're just guessing at this stuff, and that never works. Again, you must study the tutorials and do things one at a time. This will not be easy in the beginning but if you apply yourself, it will make sense. Also you may want to consider getting a tutor.
    Last edited by Fubarable; 04-16-2011 at 07:43 PM.

Similar Threads

  1. Simple program, probably easy solution?
    By falkon114 in forum New To Java
    Replies: 6
    Last Post: 01-18-2011, 08:31 PM
  2. how easy it is?
    By ron87 in forum New To Java
    Replies: 0
    Last Post: 04-01-2009, 06:36 PM
  3. Easy program...need help (urgent)
    By Zebra in forum New To Java
    Replies: 25
    Last Post: 05-30-2008, 08:51 AM
  4. What does this mean (Very Easy)
    By Zebra in forum New To Java
    Replies: 6
    Last Post: 05-01-2008, 01:46 PM
  5. help me with a realy easy program (substring)
    By michcio in forum New To Java
    Replies: 7
    Last Post: 01-27-2008, 12:41 AM

Posting Permissions

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