The purpose of this assignment is to give you more experienc

The purpose of this assignment is to give you more experience in reading a short description of what we want a Java program to do and thinking your way through the program to write the program from scratch.

Write a Java program that welcomes the user and then prompts the user to enter a dollar amount for investment. Calculate a service charge of 3/10ths of a percent. Add the amount to the investment amount and display the three value.

The service charge amount should be declared as a constant, and the largest amount that can be invested is $99,999,999.99 (note: this is important for you to know when determining what the insertion sequence should be). Display the investment amount, service charge amount and total amount due rounded to exactly two decimal places and with a short message in front of each amount telling the user what is being displayed. Use printf and insertion sequences where necessary and place a short line of hyphens in between the service charge amount line and the total amount due line.

At the end, thank the user for using the program.

Here is example output in which the service charge is not arithmetically 3/10ths of a percent:


Welcome to NIU Investments!

Please enter the amount you would like to invest today: 34543.25


Total Investment (in dollars): 34543.25

Service Charge (in dollars): 22.33

-----------

Total Amount Due (in dollars): 34565.58

Thank you for your investment!

Solution

package org.students;

import java.util.Scanner;

public class NIUInvestments {

   //Declaring constant
   public static final double SCHARGE=0.0006464;
   public static void main(String[] args) {
      
       //Declaring variables
       double total_investment,service_charge,total_amount_due;
      
       //Scanner class object is used read the inputs entered by the user
       Scanner sc=new Scanner(System.in);
       System.out.println(\"Welcome to NIU Investments!\");
      
       //This loop continues to execute until the suer enters a valid number
       while(true)
       {
       //getting the total investment entered by the user.  
       System.out.print(\"Please enter the amount you would like to invest today:\");
       total_investment=sc.nextDouble();
      
       /*Checking the total investment is with the range
       * If not,Display the error message end prompt to enter again
       */
       if(total_investment<0 || total_investment>99999999.99)
       {
       System.out.println(\"::Invalid Number.Total investment must be greater than 0 and less than 99999999.99 ::\");
       continue;
       }
       else
           break;
       }  
       //Calculating the service charge
       service_charge=total_investment*SCHARGE;
      
       //calculating the total amount due
       total_amount_due=total_investment+service_charge;
      
       //Displaying the total investment
       System.out.printf(\"\ Total Investment (in dollars):\\t%.2f\ \",total_investment);
      
       //Displaying the service charge
       System.out.printf(\" Service Charge (in dollars):\\t%.2f\ \",service_charge);
       System.out.println(\"\\t\\t-----------\");
      
       //Displaying the total amount due
       System.out.printf(\"Total Amount Due (in dollars):%.2f\ \",total_amount_due);
       System.out.println(\"\ Thank you for your investment!\");
          

   }

}

____________________________________________

Output:

Welcome to NIU Investments!
Please enter the amount you would like to invest today:34543.25

Total Investment (in dollars):   34543.25
Service Charge (in dollars):   22.33
       -----------
Total Amount Due (in dollars):34565.58

Thank you for your investment!

________________________Thank You

The purpose of this assignment is to give you more experience in reading a short description of what we want a Java program to do and thinking your way through
The purpose of this assignment is to give you more experience in reading a short description of what we want a Java program to do and thinking your way through

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site