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...
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.
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...
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
In python Write the code to ask a user to enter a number in the range...
In python Write the code to ask a user to enter a number in the range of 1-100. Have the code checked to make sure that it is in this range. If it is not, let the user re-enter the number. The user should be able to re-enter numbers until the number is within the correct range.
Write a C++ code to perform the following steps: 1. Ask the user to enter two...
Write a C++ code to perform the following steps: 1. Ask the user to enter two whole numbers number1 and number2 ( Number 1 should be less than Number 2) 2. calculate and print the sum of all even numbers between Number1 and Number2 3. Find and print all even numbers between Number1 and Number2 4. Find and print all odd numbers between Number1 and Number2 5. Calculate and print the numbers and their squares between 2 and 20 (inclusive)...
Write a java program that perform the following: 1. Ask a user ti enter 10 student...
Write a java program that perform the following: 1. Ask a user ti enter 10 student test score on a test (100 point test and save the score in an array 2. Iterate through the array to find the average and highest of these score, print them out 3 Count how many student score below average and print them out 4 . Instructor decide to curve the student score using square root curving method( take the square root of the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT