In: Computer Science
1) Java code:
A user wants to save for a big purchase. Ask them for the amount they need to save, the current balance in their savings accounts, and the interest rate on the account. Calculate the balance of the account after the first, second, and third year, using the initial balance and annual interest rate. Using simple interest, the value of an account after one year is the balance multiplied by the interest rate plus the balance. Provide output telling the user how many years (1, 2, 3, or more than 3) they will need to wait until they have saved enough for their purchase.
2) Java code:
You and several friends go out for a fancy dinner and want to split the bill. Inputs will be the number of people dining, the total cost of the food, tax rate, and tip percent. The output should be the inputs, the calculated tax, calculated tip, total cost, and how much each person has to pay. Use decision structures to provide two additional messages:
Java code for Problem 1
============================================================================================
package sat;
import java.util.Scanner;
public class BalanceFind {
public static void main(String[] args) {
// TODO Auto-generated method
stub
double
saving,balance,interestrate;
double interest;
int year=0;
//scanner class object for taking
input from keyboard
Scanner sc = new
Scanner(System.in);
System.out.print("Enter amount you
want to save: ");
saving=sc.nextDouble();
System.out.print("Enter balance in
your account: ");
balance=sc.nextDouble();
System.out.print("Enter interest
rate on the account: ");
interestrate=sc.nextDouble();
while(balance<=saving)
{
balance=balance+(balance*interestrate/100);
year=year+1;
System.out.println("Balance after "+year+" year: "+balance);
}
System.out.println("You need
"+year+" to save "+saving);
}
}
============================================================================================
Output