title: how to get the difference between 2 objects fields in java
body: <p>I have 2 objects in my java project and I want to take a field from each object(let's say for example we have 2 hotel rooms that among other fields they have also a field "price") and put em in a method and return a variable(in the previous example let's say the difference of those 2 rooms). My main question is after you create the method, how do you call it in the main class?
  I did a try (code below) but I know it's not right.So if you could give me an advice on how to do it or approach it would be really helpful. </p>
  
  <pre><code>difference = priceDifference(roomA.price, roomB.price);
  </code></pre>
  
  <p>full code 
  main class </p>
  
  <pre><code>   package project1;
      import java.util.Scanner;
  
  public class TestRoom {
  
  public static void main(String[] args) {
      String roomNumber, category, view;
      int numberOfBeds;
      double price;
      double difference;
      Room roomA = new Room("C101",2,"Standard","Sea",95.89);
  
  
  
      Scanner sc = new Scanner(System.in);
      System.out.println("Give room number \n");
      roomNumber=sc.next();
      System.out.println("Give number of beds \n");
      numberOfBeds=sc.nextInt();
      System.out.println("Give category \n");
      category=sc.next();
      System.out.println("Give view \n");
      view=sc.next();
      System.out.println("Give price \n");
      price=sc.nextDouble();
  
      Room roomB = new Room(roomNumber, numberOfBeds, category, view, price);
      System.out.println(roomA.toString());
      System.out.println(roomB.toString());
  
      difference = priceDifference(roomA.getprice(), roomB.getprice());
  
  
  }
  
   }
  </code></pre>
  
  <p>class Room</p>
  
  <pre><code>  package project1;
  
   public class Room {
  
  public String roomNumber;
  public int numberOfBeds;
  private String category;
  private String view;
  private double price;
  
  
  
  
      public Room(String roomNumber, int numberOfBeds, String category, String view, double price){
      this.roomNumber = roomNumber;
      this.numberOfBeds = numberOfBeds;
      this.category = category;
      this.view = view;
      this.price = price;
  }
  
  
  
  
  
  
  
  
  public void setroomNumber(String roomnumber){
      this.roomNumber = roomnumber;
  }
  public String getroomNumber(){
      return this.roomNumber;
  }
  
  public void setnumberOfBeds(int numberofbeds){
      this.numberOfBeds = numberofbeds;
  }
  public int getnumberOfBeds(){
      return this.numberOfBeds;
  }
  
  public void setcategory(String category){
      this.category = category;
  }
  public String getcategory(){
      return this.category;
  }
  
  public void setview(String view){
      this.view = view;
  }
  public String getview(){
      return this.view;
  }
  
  public void setprice(double price){
      this.price = price;
  }
  public double getprice(){
      return this.price;
  }
  
  
  public double priceDifference(double double1 ,double double2){
  
      double difference = 0;
      difference = double1 - double2; 
      return difference;
  }
  
  @Override
  public String toString() {
      return "Room number:" + this.roomNumber + ",\n "
              + "Number of beds:" + this.numberOfBeds + ",\n " + "Category:"
              + this.category + ",\n " + "View:" + this.view + ",\n " + "Price:" + this.price;
  }
  </code></pre>
  
  <p>}</p>