Results 1 to 13 of 13
  1. #1
    helpme is offline Member
    Join Date
    Apr 2009
    Posts
    5
    Rep Power
    0

    Unhappy I seriously need help.

    So yea I am a High school kid which takes college class which is taking computer program thinking it would be easy for me ... I seriously don't understand anything in the class not because I don't pay attention I just don't get the concept of the class...
    I've been trying to do homeworks but I just DON'T GET IT. I've missed all my homeworks so far and now I have this main homework which would save my grade. Now I'm here begging for someone to help me. I tried asking people at my school to help but they don't know anything either.. so please can someone help me out doing this last homework that I have and save my grade... ?


    Here what I have to do...



    You will be creating the following classes:
    Circle class, Rectangle class, Triangle class, Driver class.

    The circle class will contain the following methods:
    Constructor
    CalculateArea
    CalculateCircumference
    toString

    The rectangle class will contain the following methods:
    Constructor
    CalculateArea
    CalculatePerimeter
    toString

    The triangle class will contain the following methods:
    Constructor
    CalculateArea
    toString

    The driver class will be a modified version of Assignment #4. Instead of doing the calculations in the driver class, you will create the appropriate object (circle, rectangle or triangle) and then call the appropriate methods to get the correct output.


    Write a program that displays the following menu:

    Geometry Calculator

    1. Circle
    2. Rectangle
    3. Triangle
    4. Quit

    Enter your choice (1-4)


    If someone can help me i Would be really please... I can't pay you but help a poor soul.

  2. #2
    logicbug's Avatar
    logicbug is offline Member
    Join Date
    Jan 2009
    Location
    The Great White North, eh?
    Posts
    76
    Rep Power
    0

    Default

    Can you be more specific on your problem? This looks like a pretty strait forward assignment. Im guessing you have never used a OOP language before?

  3. #3
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    Looks like the OP is completely lost because he didn't do the first assignments and #4 is part of this assignment. I guess he's fukd.

  4. #4
    helpme is offline Member
    Join Date
    Apr 2009
    Posts
    5
    Rep Power
    0

    Default

    yea i have never used OOBB language... I was just sick of those classes where u read books and then answer the question... so I tried something new and look at me now I am screwed ! lol

    Yea u r supposed to change some stuff on this..






    //************************************************** ************************************************** ***
    //Author: Leticia Melchor
    // Class Time: 8:20 am
    //************************************************** ************************************************** *******





    import java.util.Scanner;
    public class asign4 {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub

    double choice;
    double radius;
    double area;
    double circumference;
    double length;
    double width;
    double perimeter;
    double base;
    double height;


    Scanner scan= new Scanner (System.in);

    System.out.print ("Geometry Calculator" + "\n\n" );

    System.out.print ("1. Circle" + "\n");
    System.out.print ("2. Rectangle" + "\n");
    System.out.print ("3. Triangle" + "\n");
    System.out.print ("4. Quit" + "\n\n");
    System.out.print ("Enter choice:");
    choice = scan.nextInt();

    while (choice < 1 || choice > 4)
    {
    System.out.print ("reenter: ");
    choice = scan.nextInt();
    }

    if (choice==1)
    {
    System.out.print ("enter radius: ");
    radius = scan.nextDouble();

    while (radius < 0 )
    {
    System.out.print ("reenter: ");
    radius = scan.nextDouble();
    }
    System.out.print ("Circle" + "\n");
    System.out.print ("The Radius:" + radius + "\n");
    area = (3.14159*(radius*radius));
    System.out.print ("The Area:" + area + "\n");
    circumference = (radius*3.14159*2);
    System.out.print ("The Circumference:" + circumference + "\n");


    }





    if (choice==2)
    {
    System.out.print ("enter length:");
    length = scan.nextDouble();
    while (length < 0)
    {
    System.out.print ("reenter: ");
    length = scan.nextDouble();
    }

    System.out.print ("enter width:");
    width = scan.nextDouble();
    while (width < 0)
    {
    System.out.print ("reenter: ");
    width = scan.nextDouble();
    }
    System.out.print ("Rectangle" + "\n\n");
    System.out.print ("the Length:" + length + "\n");
    System.out.print ("The Width:" + width + "\n");
    area = (length * width);
    System.out.print ("The Area:" + area + "\n");
    perimeter = (2*length + 2*width);
    System.out.print ("The Perimeter:" + perimeter + "\n");



    }

    if (choice==3)
    {
    System.out.print ("enter base:");
    base = scan.nextDouble();
    while (base < 0)
    {
    System.out.print ("reenter: ");
    base = scan.nextDouble();
    }
    System.out.print ("enter height:");
    height = scan.nextDouble();
    while (height < 0)
    {
    System.out.print ("reenter: ");
    height = scan.nextDouble();
    }

    System.out.print ("Triangle" + "\n\n");
    System.out.print ("The Base:" + base + "\n");
    System.out.print ("The Height:" + height + "\n");
    area = (base * height*.5);
    System.out.print ("The Area:" + area + "\n");





    }

    }

    }


    U r supposed to modify the stuffs based on this

  5. #5
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    So, where are you stuck? Start coding the Circle, Rectangle and Triangle classes.

  6. #6
    logicbug's Avatar
    logicbug is offline Member
    Join Date
    Jan 2009
    Location
    The Great White North, eh?
    Posts
    76
    Rep Power
    0

    Default

    So what you need to do is take this very linear program and convert it to OO which means creating classes with methods.
    i.e.
    Java Code:
    public class circle {
         class circle() { // your code here} // This is your constructor
         public double CalculateArea() {// your code here }
         public double CalculateCircumference() {// your code here}
         public String toString() { // your code here }
    }
    
    // in your Main, when your menu item has selected the circle
    circle myCircle = new circle();
    myCircle.CalculateArea();
    myCircle.CalculateCircumference();
    hopefully that helps point you in the right direction.

  7. #7
    helpme is offline Member
    Join Date
    Apr 2009
    Posts
    5
    Rep Power
    0

    Default

    oh okay cool so this is it for circle...?
    Then U gotta change the formula a lil bit cuz triangle it is like 1/2 base*height

    and the same goes for rectangle right ?

  8. #8
    helpme is offline Member
    Join Date
    Apr 2009
    Posts
    5
    Rep Power
    0

    Default

    I'm stuck in all of them... I mean I started doing circle right now


    and so far all i got it is this


    public class circle {

    double r;

    double circarea;

    double circicumference;

    public circle (double r)
    {
    r = radius;

    }

    void Calculatecircarea (){

    circarea = r * r = 3.14159

  9. #9
    helpme is offline Member
    Join Date
    Apr 2009
    Posts
    5
    Rep Power
    0

    Default

    triangle too...


    public class triangle {

    double r;


    double Triarea;

    double Tricircumfrience;

    double base;

    double height;


    public triangle (double Base, double Height)

    base = Base;



    but class is over... I am out I will come back in when i get home

    Thx for your help guys =]

  10. #10
    logicbug's Avatar
    logicbug is offline Member
    Join Date
    Jan 2009
    Location
    The Great White North, eh?
    Posts
    76
    Rep Power
    0

    Default

    yep, each one of your shapes will be a class of its own with its own methods. The code you need to create the methods are already provided for you. There are a few different way's you can go about doing this.

    You really should read up on classes and methods. As much as you may be sick of it, you probably realize by now that you have to read the book.

  11. #11
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    Uhm, you know that that first shot won't even compile, don't you?

    You don't need
    Java Code:
    double circarea;
    
    double circicumference;
    You can calculate them on the fly:

    Java Code:
    public double calcArea(){
      return Math.Pi *r *r;
    }

  12. #12
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    PhHein... you are correct that they can be calculated on the fly, however, you WOULD most likely need the declared variables. The OP is getting somewhere, however this will take some work. I would personally suggest starting with Rectangle or Triangle, and saving Circle until you are close to finishing, as the formulae for circles are far more complex than those of rectangles and triangles. In fact, it is probably best to start with Rectangle, as you can probably avoid use of the Math class for Rectangle, but it will be needed for Circle and Triangle.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  13. #13
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    To the OP... you may want to PM a moderator and ask them to move this thread, as this should be in the New To Java subforum.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

Posting Permissions

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