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 7 of 7

Thread: how convert everthing to private

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how convert everthing to private

     
     
     
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    package houseroom;
     
     
     
     
    import java.util.Scanner;
    public class HouseRoom {
     
     
     
    public class Room {
     
        double l;
    double w;
    double roomSide;
    }
     
        public static void main(String[] args) {
            Scanner sc = new Scanner (System.in);
           // Scanner scc = new Scanner (System.in);
     
           System.out.println("Please enter the length of the First room");
           Room Room1 = new Room();
           Room Room2 = new Room();
     
           Room1.l = sc.nextDouble();
                  System.out.println("Please enter the width of the First room");
     
           Room1.w = sc.nextDouble();
     
           Room1.roomSide= Room1.l * Room1.w;
                  System.out.println("Please enter the length of the Second room");
       Room1.roomSide= Room1.l * Room1.w;
             Room2.l = sc.nextDouble();
                    System.out.println("Please enter the width of the second room");
     
           Room2.w = sc.nextDouble();    
     
           Room2.roomSide= Room2.l * Room2.w;
     
           if(Room1.roomSide > Room2.roomSide)
           {
     
           System.out.println("room one is the parent Room; Room size of "+ Room1.roomSide
                   + " Room 2 is the children room ; Room Side " + Room2.roomSide);
           } 
                  else if(Room1.roomSide < Room2.roomSide)
           {
           System.out.println("room 2 is the parent Room size of "+ Room2.roomSide
                   + " Room 1 is the children room ; Room Side " + Room1.roomSide);
     
           } 
                  else System.out.println("Room are the same size "
                          + "pick which ever room you like");
        }
     
    }
    Last edited by gcabada; September 26th, 2014 at 07:03 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: how convert everthing to private

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.

    Did you have any specific java programming questions?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how convert everthing to private

    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    package houseroom;
     
     
     
     
    import java.util.Scanner;
    public class HouseRoom {
     
     
     
    public class Room {
     
        double l;
    double w;
    double roomSide;
    }
     
        public static void main(String[] args) {
            Scanner sc = new Scanner (System.in);
           // Scanner scc = new Scanner (System.in);
     
           System.out.println("Please enter the length of the First room");
           Room Room1 = new Room();
           Room Room2 = new Room();
     
           Room1.l = sc.nextDouble();
                  System.out.println("Please enter the width of the First room");
     
           Room1.w = sc.nextDouble();
     
           Room1.roomSide= Room1.l * Room1.w;
                  System.out.println("Please enter the length of the Second room");
       Room1.roomSide= Room1.l * Room1.w;
             Room2.l = sc.nextDouble();
                    System.out.println("Please enter the width of the second room");
     
           Room2.w = sc.nextDouble();    
     
           Room2.roomSide= Room2.l * Room2.w;
     
           if(Room1.roomSide > Room2.roomSide)
           {
     
           System.out.println("room one is the parent Room; Room size of "+ Room1.roomSide
                   + " Room 2 is the children room ; Room Side " + Room2.roomSide);
           } 
                  else if(Room1.roomSide < Room2.roomSide)
           {
           System.out.println("room 2 is the parent Room size of "+ Room2.roomSide
                   + " Room 1 is the children room ; Room Side " + Room1.roomSide);
     
           } 
                  else System.out.println("Room are the same size "
                          + "pick which ever room you like");
        }
     
    }


    --- Update ---

    I been trying learn how to used private so im trying convert this program to private class

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: how convert everthing to private

    What have you tried? What happened?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how convert everthing to private

    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    package houseroom;
     
    /**
     *
     * @author Gilbert
     */
     
     
    import java.util.Scanner;
    public class HouseRoom {
     
    package houseroom;
     
    public class Room {
     
        private double length;
        private double wigth;
        private double roomSide;
     
        public Room(double l,double w,double RoomSide)
    {
    length = l;
    wigth =w;
    roomSide = RoomSide;
    }
        public double getL()
        { return length;
    }
        public double getW()
        {return wigth;}
        public double getRoomSide()
        {return roomSide;}
    }
        public static void main(String[] args) {
            Scanner sc = new Scanner (System.in);
           // Scanner scc = new Scanner (System.in);
     
           System.out.println("Please enter the length of the First room");
           Room Room1 = new Room();
           Room Room2 = new Room();
     
     
     
    }


    --- Update ---

    im stuck here get error

    Room Room1 = new Room();
    Room Room2 = new Room();

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: how convert everthing to private

    get error
    Please copy the full text of the error message and paste it here. It has important info about the error.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    May 2013
    Posts
    106
    My Mood
    Amused
    Thanks
    16
    Thanked 9 Times in 9 Posts

    Default Re: how convert everthing to private

    You shouldn't have your package declaration inside the body of a class. Also you shouldn't have it twice.

    To change things to private, just precede them with the private keyword instead of public.

    --- Update ---

    Quote Originally Posted by gcabada View Post
    [code=java]

    [/COLOR]im stuck here get error

    Room Room1 = new Room();
    Room Room2 = new Room();
    Well that statement creates two new Room objects, using a no-argument constructor. Except your Room class doesn't have a no-argument constructor. It just has the one that asks for 3 double values. You would need to pass 3 doubles. Also you declared a Scanner object but forgot to use it.

Similar Threads

  1. private constuctor
    By swagat in forum Java Theory & Questions
    Replies: 2
    Last Post: February 19th, 2013, 12:22 PM
  2. Accessability/Visability Private
    By EmSaint in forum Object Oriented Programming
    Replies: 1
    Last Post: March 15th, 2010, 06:50 PM
  3. Convert string to private and public key
    By Ganezan in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: January 5th, 2010, 08:37 AM
  4. Private Constructor
    By Ganezan in forum Object Oriented Programming
    Replies: 4
    Last Post: November 7th, 2009, 04:02 PM
  5. Private or public variables??
    By igniteflow in forum Java Theory & Questions
    Replies: 2
    Last Post: September 17th, 2009, 08:07 AM