Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 5

class SavingAccount { static int annualInterestRate; private int savingBalance; int interest; public void calculateMonthlyInterest() { interest = (savingBalance

* annualInterestRate) / 12; savingBalance = savingBalance + interest; } public static void modifyInterestRate(int rate) { annualInterestRate = rate; } public int getSavingBalance() { return savingBalance; } public void setSavingBalance(int savingBalance) { this.savingBalance = savingBalance; } public static int getAnnualInterestRate() { return annualInterestRate; } } public class SavingAccountTest { public static void main(String[] args) { String[] month = {"jan", "feb", "mar", "apr", "may", "jun", "july", "aug", "sep", "oct", "nov", "dec" }; SavingAccount.modifyInterestRate(4); SavingAccount sa1 = new SavingAccount(); SavingAccount sa2 = new SavingAccount(); sa1.setSavingBalance(200000); sa2.setSavingBalance(300000); System.out.println("Balance Before Interest"); System.out.println("Interest Rate" + SavingAccount.getAnnualInterestRate()); System.out.println("Account1" + " " + sa1.getSavingBalance()); System.out.println("Account2" + " " + sa2.getSavingBalance()); System.out.println("For Account1");

for (int i = 0; i < 12; i++) { sa1.calculateMonthlyInterest(); System.out.println("Balance After Month " + month[i] + " " + sa1.getSavingBalance()); } System.out.println("For Account2"); for (int i = 0; i < 12; i++) { sa2.calculateMonthlyInterest(); System.out.println("Balance After Month " + month[i] + " " + sa2.getSavingBalance()); } SavingAccount.modifyInterestRate(5); System.out.println("New Interest Rate" + " " + SavingAccount.getAnnualInterestRate()); System.out.println("For Account1 next month balance"); sa1.calculateMonthlyInterest(); System.out.println("Account1" + " " + sa1.getSavingBalance()); System.out.println("For Account2 next month balance"); sa2.calculateMonthlyInterest(); System.out.println("Account2" + " " + sa2.getSavingBalance()); } }

Output

init: deps-jar: compile-single: run-single: Balance Before Interest Interest Rate4 Account1 200000 Account2 300000 For Account1 Balance After Month jan 266666 Balance After Month feb 355554 Balance After Month mar 474072 Balance After Month apr 632096 Balance After Month may 842794 Balance After Month jun 1123725 Balance After Month july 1498300 Balance After Month aug 1997733 Balance After Month sep 2663644 Balance After Month oct 3551525 Balance After Month nov 4735366 Balance After Month dec 6313821 For Account2 Balance After Month jan 400000 Balance After Month feb 533333 Balance After Month mar 711110 Balance After Month apr 948146 Balance After Month may 1264194 Balance After Month jun 1685592 Balance After Month july 2247456 Balance After Month aug 2996608 Balance After Month sep 3995477 Balance After Month oct 5327302 Balance After Month nov 7103069 Balance After Month dec 9470758 New Interest Rate 5 For Account1 next month balance Account1 8944579 For Account2 next month balance Account2 13416907 BUILD SUCCESSFUL (total time: 0 seconds)

/*

* To change this template, choose Tools | Templates * and open the template in the editor. */ package amit; import java.util.Scanner; /** * * @author student */ public class DalilyCost { public static void main(String args[]) { int totalMiles; int costPerGalon; int averageMilesPerGalon; int parkingFee; int tolls; float dailyDrivingCost; Scanner s = new Scanner(System.in); System.out.println("Total Miles:"); totalMiles = s.nextInt(); System.out.println("Cost Per Galon:"); costPerGalon = s.nextInt(); System.out.println("Average Miles per Galon:"); averageMilesPerGalon = s.nextInt(); System.out.println("Parking Fee:"); parkingFee = s.nextInt(); System.out.println("Tolls:"); tolls = s.nextInt(); dailyDrivingCost = costPerGalon*(totalMiles/averageMilesPerGalon) + parkingFee + tolls; System.out.println("Daily Driving Cost: " + dailyDrivingCost);

} } Output

init: deps-jar: compile-single: run-single: Total Miles: 100 Cost Per Galon: 10 Average Miles per Galon: 10 Parking Fee: 10 Tolls: 0 Daily Driving Cost: 110.0 BUILD SUCCESSFUL (total time: 22 seconds)

You might also like