Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2011
    Posts
    2
    Rep Power
    0

    Default Programing problem with objects and classes.

    Write a program that creates two Rectangle objects, one with width 4 and height 40 and the other with width 3.5 and height 35.9. Display the width, height, area, and perimeter of each rectangle in this order.

    Okay, so i have the whole thing written but im getting an issue with it saying i do not have a main method and i do, i HAVE to be doing something wrong, here is the code i have

    public class Problem1 {
    public static void main(String[] args)
    {
    Rectangle R1 = new Rectangle(40,4);
    Rectangle R2 = new Rectangle(35.9,3.5);
    System.out.println(" Area is " + R1.getArea() + " perimeter is " + R1.getPerimeter());
    System.out.println(" Area is " + R2.getArea() + " perimeter is " + R2.getPerimeter());
    }
    }
    public class Rectangle()
    {
    private double width;
    private double height;

    public Rectangle()
    {
    width =1.0;
    height= 1.0;
    }
    public Rectangle(double l,double w)
    {
    width =w;
    height= l;
    }

    public double getArea()
    {
    return width*height;
    }
    public double getPerimeter()
    {
    return 2*(width+height);
    }

    }
    Last edited by shadowwyvern99; 11-14-2011 at 06:52 AM.

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

  3. #3
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default Re: Programing problem with objects and classes.

    public class Rectangle() {
    this is not correct!
    You have defined a new class, and the syntax is wrong, look at the top of your other class
    public class Problem1 {

    you see the difference?

  4. #4
    Join Date
    Nov 2011
    Posts
    2
    Rep Power
    0

    Default Re: Programing problem with objects and classes.

    Quote Originally Posted by eRaaaa View Post
    public class Rectangle() {
    this is not correct!
    You have defined a new class, and the syntax is wrong, look at the top of your other class
    public class Problem1 {

    you see the difference?
    Wow, i'm an idiot, thanks a bunch! It's working now, i moved my main method to the bottom and took out public class Rectangle and also replaced all of my Rectangle's with Problem1's =)

Similar Threads

  1. OOP Objects and Classes help
    By richlan in forum New To Java
    Replies: 5
    Last Post: 03-05-2011, 05:50 PM
  2. Classes and Objects Help
    By collin389 in forum New To Java
    Replies: 1
    Last Post: 12-14-2009, 12:44 AM
  3. classes as objects
    By kroiz in forum New To Java
    Replies: 4
    Last Post: 07-25-2009, 05:22 AM
  4. help with passing objects between classes
    By aruna1 in forum New To Java
    Replies: 7
    Last Post: 03-22-2009, 02:41 PM
  5. Objects and Classes
    By Aleve in forum New To Java
    Replies: 8
    Last Post: 12-31-2007, 08:05 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
  •