CS 102: Quiz #1, September 9, 2009SOLUTION1. Write method called maxOfTwo that accepts two integer parameters andreturns the larger of the two.Solution: Using if-else statements, you can write it aspublic static int maxOfTwo(int a, int b){if (a>b)return a;elsereturn b;}Or you may use the java ternary operator ?:public static int maxOfTwo(int a, int b){return (a>b) ? a : b;}2. For this problem, you should refer to the Account class listed on thefollowing page (this class is exactly the same as the one from Lewis &Loftus which we discussed in class).What is the output (to the screen)?public class AccountDriver{public static void main(String[] args){Account acct1 = new Account("Juan Suarez", 56309, 86);Account acct2 = new Account("Henrietta Jones", 70809, 503.25);System.out.println("Account 1 balance: " + acct1.deposit(14));System.out.println("Account 2 balance: " +acct2.withdraw(60,1.50));acct1.addInterest();acct2.deposit(100);System.out.println(acct1);System.out.println(acct2);}}Solution:Account 1 balance: 100.0Account 2 balance: 441.7556309 Juan Suarez $103.5070809 Henrietta Jones $541.75import java.util.Locale;import java.text.NumberFormat;public class Account {private final double RATE = 0.035;private long acctNumber;private double balance;private String name;public Account (String owner, long account, double initial){name = owner;acctNumber = account;balance = initial;}public double deposit (double amount){balance = balance + amount;return balance;}public double withdraw (double amount, double fee){balance = balance - amount - fee;return balance;}public double addInterest (){balance += (balance * RATE);return balance;}public double getBalance (){return balance;}public String toString (){NumberFormat fmt = NumberFormat.getCurrencyInstance(Locale.US);return (acctNumber + "\t" + name + "\t" +
View Full Document