Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: I can't get classes to work.

  1. #1
    Junior Member
    Join Date
    Feb 2019
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I can't get classes to work.

    I have two files. I tried coding a program where one file is my Rectangle class that finds and calculates area and perimeter, while the other file uses the Rectangle class and creates two objects. But I can't seem to get it to work. What's wrong with it?
    "MyRectangleClassProgram"
    import Rectangle.pkg.Rectangle;
     
    public class MyRectangleClassProgram
    {
       public static void main(String args[])
       {
            Rectangle = new rectangle1();
            Rectangle = new rectangle1();
     
            rectangle1.setLW(10.0);
            rectangle1.setLW(5.0);
            rectangle2.setLW(7.0);
            rectangle2.setLW(3.0);
     
     
            System.out.println("Perimeter of rectangle1 is ");
            System.out.println(rectangle1.calculatePerimeter());
            System.out.println("\n");
            System.out.println("Area of rectangle1 is ");
            System.out.println(rectangle1.calculateArea());
            System.out.println("\n");
            System.out.println("Perimeter of rectangle2 is ");
            System.out.println(rectangle2.calculatePerimeter());
            System.out.println("\n");
            System.out.println("Area of rectangle2 is ");
            System.out.println(rectangle2.calculateArea());
            System.out.println("\n");
     
     
          System.exit(0);
       }
    }
    "Rectangle"
    class Rectangle
    {
    	public double length, width;
     
     
    	public double getLW(double len, double wid){
            return length;
            return width;
        }
     
        public double setLW(double len, double wid){
            length = len;
            width = wid;
            return;
        }
     
    	public double calculateArea(){
            return width * length;
        }
     
    	public double calculatePerimeter(){
            return 2 * (width + length);
        }
    }
    Here are my errors:
    MyRectangleClassProgram.java:1: error: package Rectangle.pkg does not exist
    import Rectangle.pkg.Rectangle;
                        ^
    MyRectangleClassProgram.java:7: error: cannot find symbol
            Rectangle = new rectangle1();
            ^
      symbol:   variable Rectangle
      location: class MyRectangleClassProgram
    MyRectangleClassProgram.java:7: error: cannot find symbol
            Rectangle = new rectangle1();
                            ^
      symbol:   class rectangle1
      location: class MyRectangleClassProgram
    MyRectangleClassProgram.java:8: error: cannot find symbol
            Rectangle = new rectangle1();
            ^
      symbol:   variable Rectangle
      location: class MyRectangleClassProgram
    MyRectangleClassProgram.java:8: error: cannot find symbol
            Rectangle = new rectangle1();
                            ^
      symbol:   class rectangle1
      location: class MyRectangleClassProgram
    MyRectangleClassProgram.java:10: error: cannot find symbol
            rectangle1.setLW(10.0);
            ^
      symbol:   variable rectangle1
      location: class MyRectangleClassProgram
    MyRectangleClassProgram.java:11: error: cannot find symbol
            rectangle1.setLW(5.0);
            ^
      symbol:   variable rectangle1
      location: class MyRectangleClassProgram
    MyRectangleClassProgram.java:12: error: cannot find symbol
            rectangle2.setLW(7.0);
            ^
      symbol:   variable rectangle2
      location: class MyRectangleClassProgram
    MyRectangleClassProgram.java:13: error: cannot find symbol
            rectangle2.setLW(3.0);
            ^
      symbol:   variable rectangle2
      location: class MyRectangleClassProgram
    MyRectangleClassProgram.java:17: error: cannot find symbol
            System.out.println(rectangle1.calculatePerimeter());
                               ^
      symbol:   variable rectangle1
      location: class MyRectangleClassProgram
    MyRectangleClassProgram.java:20: error: cannot find symbol
            System.out.println(rectangle1.calculateArea());
                               ^
      symbol:   variable rectangle1
      location: class MyRectangleClassProgram
    MyRectangleClassProgram.java:23: error: cannot find symbol
            System.out.println(rectangle2.calculatePerimeter());
                               ^
      symbol:   variable rectangle2
      location: class MyRectangleClassProgram
    MyRectangleClassProgram.java:26: error: cannot find symbol
            System.out.println(rectangle2.calculateArea());
                               ^
      symbol:   variable rectangle2
      location: class MyRectangleClassProgram
    Rectangle.java:14: error: incompatible types: missing return value
            return;
            ^
    14 errors
    Error: Could not find or load main class MyRectangleClassProgram

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,487
    Thanks
    53
    Thanked 2,407 Times in 2,360 Posts

    Default Re: I can't get classes to work.

    MyRectangleClassProgram.java:1: error: package Rectangle.pkg does not exist
    What folders are the source files located in?
    What is the current directory where the javac command is executed?
    What is the contents of the command line when the javac command is executed?

    Is all of the source code posted? The Rectangle class is missing a package statement.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2019
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I can't get classes to work.

    All the information I have is given here. I'm given two tabs and I have to code in them. https://gyazo.com/a755525d125f1933cf0a14a507394611 It's online on a site called Cengage.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,487
    Thanks
    53
    Thanked 2,407 Times in 2,360 Posts

    Default Re: I can't get classes to work.

    Is all of the source code posted? The Rectangle class is missing a package statement.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Feb 2019
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I can't get classes to work.

    Yes all the code I have is there

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,487
    Thanks
    53
    Thanked 2,407 Times in 2,360 Posts

    Default Re: I can't get classes to work.

    Did you miss this from previous posts?
    The Rectangle class is missing a package statement.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Feb 2019
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I can't get classes to work.

    What do you mean by that?

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,487
    Thanks
    53
    Thanked 2,407 Times in 2,360 Posts
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Feb 2019
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I can't get classes to work.

    ok

Similar Threads

  1. Replies: 2
    Last Post: July 11th, 2014, 03:02 AM
  2. Replies: 1
    Last Post: July 11th, 2014, 02:01 AM
  3. [SOLVED] My fleet of squares doesnt work (simple high school work)
    By macko939 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 20th, 2014, 02:56 PM
  4. Replies: 3
    Last Post: January 26th, 2014, 11:51 PM
  5. Classes of classes? [Very beginner asking a question] [w/ Codes]
    By UhKindaAwkward in forum Object Oriented Programming
    Replies: 6
    Last Post: December 24th, 2013, 03:05 AM