title: How do I use set and get methods to ask and retrieve user input for my program?
body: <p>I'm new to coding and taking a college course in java coding. I'm learning how to code different classes that work together and needed help writing code that ask for user input using set and get methods. My homework asks to make 2 classes, rectangle and House, that take area and width of 4 rooms in a house, then calculate the total area of all the rooms combined. I created and ran both classes, House being the main. Below is the code for the rectangle class:</p>
  
  <pre><code>import java.text.NumberFormat;
  import java.util.Scanner;
  
  public class Rectangle
  {
  
      // the instance variables
      private double length, width;
  
      //gets and processes the user input
      public void getUserInput()
      {
          Scanner input = new Scanner(System.in);
          System.out.print("Length: ");
          length = input.nextInt();
          System.out.print("Width: ");
          width = input.nextInt();
      }
  
      // methods of the rectangle class
      public void setLength(double len)
      {
          length = len;
      }
  
      public void setWidth(double w)
      {
          width = w;
      }
  
      public double getLength()
      {
          return length;
      }
  
      public double getWidth()
      {
          return width;
      }
  
      public double getArea()
      {
          return length * width;
      }
      }
  </code></pre>
  
  <p>This is the code for the rectangle class:</p>
  
  <pre><code>import java.util.Scanner;
  import java.text.NumberFormat;
  
  public class House
  {
  public static void main(String args[])
  {
      // display a welcome message
      System.out.println();
      System.out.println("Welcome to the House Total Area Calculator!");
      System.out.println();
  
      Scanner user_input = new Scanner(System.in);
      String choice = "y";
      while (choice.equalsIgnoreCase("y"))
      {
          /**
          creates 4 instances(objects) of the rectangle class.
          each instance represents a room in a 4 bedroom house
          */
          Rectangle rect1 = new Rectangle();
          Rectangle rect2 = new Rectangle();
          Rectangle rect3 = new Rectangle();
          Rectangle rect4 = new Rectangle();
  
          // get input for length / width of each room from the user 
              //room 1
          System.out.println("Enter length and Width of room 1: ");
          rect1.getUserInput();
          System.out.println();
  
              //room 2
          System.out.println("Enter length and width of room 2: ");
          rect2.getUserInput();
          System.out.println();
  
              //room 3
          System.out.println("Enter length and width of room 3: ");
          rect3.getUserInput();
          System.out.println();
  
              //room 4
          System.out.println("Enter length and width of room 4: ");
          rect4.getUserInput();
          System.out.println();
  
          double totalArea = rect1.getArea() * rect2.getArea() * rect3.getArea() * rect4.getArea();
          System.out.println("The total area of all rooms in the house is: " + totalArea);
  
          // ask if user wants to continue or exit the program
          System.out.print("Continue? (y/n): ");
          choice = user_input.next();
          System.out.println();
      }
  }
  }
  </code></pre>
  
  <p>Program runs fine, but my HW assignment asks to use set methods for "accepting an argument to store in the length and width fields" and use get methods for "returning the methods stored in the length and width fields as well as the area of each room". I saw however that if I remove the set and get methods for length and width from my rectangle class (only leaving the getArea method in tact), the program still runs the same without any problems. So my question is how do I write code for the set / get methods to retrieve data input from the user without using the getUserInput method (if thats possible)?</p>