Question

In: Computer Science

1) Java code: A user wants to save for a big purchase. Ask them for the...

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:

  • A comment on the tip percentage the user entered.
  • Whether the bill can be evenly split (if everyone pays the displayed amount, will this exactly match the amount you owe)

Solutions

Expert Solution

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


Related Solutions

Code in Java Change the instructionLabel to ask the user to enter a numeric value into...
Code in Java Change the instructionLabel to ask the user to enter a numeric value into the textField and click the button to convert the entered value from kilometers to miles (1.609344 km = 1 mile). When the actionButton on the form is clicked, ActionWindow should take the value entered in the textField, convert it from kilometers to miles, and display the result in the resultField. import java.awt.Container; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class...
in java code Modify your program as follows: Ask the user for the number of hours...
in java code Modify your program as follows: Ask the user for the number of hours worked in a week and the number of dependents as input, and then print out the same information as in the initial payroll assignment. Perform input validation to make sure the numbers entered by the user are reasonable (non-negative, not unusually large, etc). Let the calculations repeat for several employees until the user wishes to quit the program. Remember: Use variables or named constants...
IN JAVA: Write a simple program that takes 5 inputs from the user and save them...
IN JAVA: Write a simple program that takes 5 inputs from the user and save them into a Text File. The inputs are Student Name, Student Address and student Date of Birth. Also write a simple program that reads and display the input from the first program text file.
Create a Java method that does the following: 1) Ask the user for a dividend and...
Create a Java method that does the following: 1) Ask the user for a dividend and a divisor both of "int" type. 2) Computes the remainder of the division. The quotient (answer) must be of the "int" type. Do NOT use the method " % " provided in Java in your code. Remember that it gives wrong answers when some of the inputs are negative. Please see the videos for the explanation.
Create a Java method that does the following: 1) Ask the user for a dividend and...
Create a Java method that does the following: 1) Ask the user for a dividend and a divisor both of "int" type. 2) Computes the remainder of the division. The quotient (answer) must be of the "int" type. Do NOT use the method " % " provided in Java in your code. Remember that it gives wrong answers when some of the inputs are negative. Here is the code that I have so far I can't seem to get it...
Write Java code that prompts the user for a string and tells them if the grouping characters in that string are balanced.
Write Java code that prompts the user for a string and tells them if the grouping characters in that string are balanced. Grouping characters are ( and ), [ and ], and { and }. I got the basic idea for this problem from HackerRank. It’s also a very common interview question.*******************8Example output**************Enter the expression:{[()]} {[()]}is balancedEnter the expression: {()()} {()()}is balancedEnter the expression: {([[])} {([[])}is not balancedEnter the expression: {([)]} {([)]}is not balanced
1. Write Python code to - (a) ask user to enter a list of animals, one...
1. Write Python code to - (a) ask user to enter a list of animals, one item at a time, until “done” to terminate input (b) randomly display a selected item from the list, starting with “I like ______”. When run, the output should look something like this: Enter an item; 'done' when finished: cats Enter an item; 'done' when finished: dogs Enter an item; 'done' when finished: guinea pigs Enter an item; 'done' when finished: done You are done...
Write a program that will ask the user to enter the amount of a purchase. The...
Write a program that will ask the user to enter the amount of a purchase. The program should then compute the state and county sales tax. Assume the state sales tax is 5 percent and the county sales tax is 2.5 percent. The program should display the amount of the purchase, the state sales tax, the county sales tax, the total sales tax, and the total of the sale (which is the sum of the amount of purchase plus the...
This is in java, thank you! Problem2: In this problem you ask the user for a...
This is in java, thank you! Problem2: In this problem you ask the user for a month and day. You will then calculate the season based on the month and day. Create a class named Problem2 Create two integer instance variables, month and day. Create a constructor to initialize the both variables. The constructor should accept two arguments as parameters, m and d. Initialize the instance variables with these two values. Create a method called calcSeason. It should not have...
write a program i java that ask the user to enter salary, user ID and username...
write a program i java that ask the user to enter salary, user ID and username and out put them
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT