im having a bit of a problem. i have 2 classes. one called machine and the other is just the main class.

im trying to pass a value from the main class to the machine class where an operation is done on it then it is returned and displayed to the user. whats happening is that it returns an incorrect value.
i found a work around but my professor said even though it does what is required it doesnt follow the procedure outlined. below is my code. im not asking you guys to do this for me. im just asking for a hint maybe. guide me. im poofed ive been making modifications and nothing works.

Code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package vendingmachine10;

public class VendingMachine {
    
   private String brand = "Fanta";
   private double price = 1.50;
   private double balance = 100;
   private int number_of_sodas = 200;
   
   
   public VendingMachine(String sbrand,double sprice,double bal,int numsodas)
   {
       brand = sbrand;
       price = sprice;
       balance = bal;
       number_of_sodas = numsodas;
       
   }

   
   public String getBrand()
   {
       return brand;
   }
   
   public double getPrice()
   {
       return price;
   }
    
   public double getBalance()
   {
       return balance;
   }
     
   public int getSodaNumbers()
   {
       return number_of_sodas;
   }
      
      
   public void setBrand(String b)
   {
       brand = b;
   }
   
   public void setPrice(double p)
   {
       price = p;
   }
   
   public void setBalance(double bal)
   {
       balance = bal;
   }
   
   
   public void setNumOfSodas(int numofsodas)
   {
       number_of_sodas = numofsodas;
   }
   
   public double buy(double c)
   {
       double change;
       change = c - price;
       balance = balance + price;
       number_of_sodas = number_of_sodas -1;
       return change;
   }

    
   }

Code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package vendingmachine10;

import javax.swing.JOptionPane;


public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        String brand;
        double money;
        
               
        brand = JOptionPane.showInputDialog("Enter brand choice.");
        
        
        VendingMachine V = new VendingMachine(brand,1.50,50,100);
        
        double b=V.getBalance();
        JOptionPane.showMessageDialog(null,"Current balance is="+ b);
        String sbrand=V.getBrand();
        JOptionPane.showMessageDialog(null,"Current brand is="+ sbrand);
        double p=V.getPrice();
        JOptionPane.showMessageDialog(null,"Current price of "+sbrand+" is="+ p);
        int sodanum=V.getSodaNumbers();
        JOptionPane.showMessageDialog(null,"Current amount of "+sbrand+" is="+ sodanum);
        V.buy(50);
        double newb=V.getBalance();
        int newsodanum=V.getSodaNumbers();
        
        JOptionPane.showMessageDialog(null,"New balance is="+ newb);
        JOptionPane.showMessageDialog(null,"New number of "+sbrand+" soda left is="+ newsodanum);
        
        JOptionPane.showMessageDialog(null,"Your Change is=$"+ V.buy(p));
    }

}