title: Simple yet in depth explanation of this code
body: <p>I am just a beginner to programming, and Java. As I have very, very little experience with Java, I would like a simple, yet in depth explanation of this code. This code uses two classes and many methods. </p>
  
  <p>Class Apples:</p>
  
  <pre><code>package jacob;
  import java.util.Scanner;
  
  class apples {
  public static void main (String args[]){
      Scanner input = new Scanner(System.in);
      grapes gobject = new grapes();
  
      System.out.println("Enter name of first gf here: ");
      String temp = input.nextLine();
      gobject.setName(temp);
      gobject.saying();
  
  
  
  }
  }
  </code></pre>
  
  <p>Class Grapes: </p>
  
  <pre><code>package jacob;
  public class grapes {
  private String girlName;
  public void setName(String name){
      girlName=name;
  }
  public String getName(){
      return girlName;
  }
  public void saying(){
      System.out.printf("Your first gf was %s", getName());
  }
  }
  </code></pre>
  
  <p>I get confused when I get to these two parts: </p>
  
  <pre><code>gobject.setName(temp);
      gobject.saying();
  </code></pre>
  
  <p>AND</p>
  
  <pre><code>private String girlName;
  public void setName(String name){
      girlName=name;
  }
  public String getName(){
      return girlName;
  }
  public void saying(){
      System.out.printf("Your first gf was %s", getName());
  </code></pre>
  
  <p>Why would one go through so much trouble when they could have done: </p>
  
  <pre><code>package jacob;
  import java.util.Scanner;
  public class test {
  public static void main (String args[]){
      Scanner input = new Scanner(System.in);
      System.out.println("Enter name of first gf here: ");
      String gfname = input.nextLine();
      System.out.println("The name of your first gf is " + gfname + ".");
  }
  }
  </code></pre>
  
  <p>Please note that the original code is from TheNewBoston and is not mine. The second bit of code is what I have created.</p>