External Exam Download Resources Web Applications Games Recycle Bin

methods


//save as methods.java
public class methods {    
    
    public static int diff(int x, int y){
      int difference = x;
      if(y > x)
      {
        difference = y - x;
      }
      else
      {
        difference = x - y;
      }
      return difference;
    }
    
    public static void main(String[] args) {
       int answer = diff(13,37);
       System.out.println(answer);
    }
}

CS:GO
//save as csgo.java
public class csgo {
    final static double GST = 0.1;
    static int numberOfKeys;
    static double moneySpent = 0;

    public static void getTaxReceipt(){
        System.out.println("Money Spent: " + moneySpent);
        System.out.println("Number of Keys: " + numberOfKeys);
        System.out.println("GST: " + (moneySpent * GST));
    }
    
    public static double buyCsGoCaseKey(double mS){
        //mS = moneySpent
        double priceOfKey = 2.30;
        numberOfKeys++;
        return priceOfKey + mS;
    }
    
    public static void main(String[] args) {
       numberOfKeys = 0;
       moneySpent = buyCsGoCaseKey(moneySpent);
       getTaxReceipt();
    }
}

bank
//save as bank.java
public class bank {
    public static int mySavings;
    
    public static void deposit(int amount){
         mySavings = mySavings + amount;
    }
    public static void withdrawal(int amount){
         mySavings = mySavings - amount;
    }
    
    public static void accountBalance(){
         System.out.println(mySavings);  }
    
    public static void main(String[] args) { 
         mySavings = 100;
         deposit(50);
         withdrawal(25);
         accountBalance();
    }
}