Question

Rewrite the following program using the DecimalFormat class so that your output looks like that below....

Rewrite the following program using the DecimalFormat class so that your output looks like that below. Once again, the example is not calculated as 3/10ths of a percent.

Welcome to NIU Investments!

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


Total Investment: $34,543.25

Service Charge: $22.33

   -------------

Total Amount Due: $34,565.58

Thank you for your investment!

Program:

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("\nTotal Investment (in dollars):\t%.2f\n",total_investment);
      
       //Displaying the service charge
       System.out.printf(" Service Charge (in dollars):\t%.2f\n",service_charge);
       System.out.println("\t\t-----------");
      
       //Displaying the total amount due
       System.out.printf("Total Amount Due (in dollars):%.2f\n",total_amount_due);
       System.out.println("\nThank 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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here 3% percent means 3/100=0.03. where as 3/10th percent means 3/10X100 %=30%..But according to the problem the service charge 22.33 is not 3/10th% of 34543.25 Should I have to Modify.Where as 3/10th% of 34543.25 is 10362.975.

Could you please clarify .So that the output will be accurate.

_______________________

NIUInvestments.java

import java.text.DecimalFormat;
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;
       DecimalFormat df=new DecimalFormat("#.##");
       //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.println("Total Investment :$"+df.format(total_investment));
      
       //Displaying the service charge
       System.out.println(" Service Charge :$ "+df.format(service_charge));
       System.out.println("\t\t-----------");
      
       //Displaying the total amount due
       System.out.println("Total Amount Due:$"+df.format(total_amount_due));
       System.out.println("\nThank you for your investment!");
          

   }

}

______________________________

Output:

Welcome to NIU Investments!
Please enter the amount you would like to invest today:34543.25
Total Investment :$34543.25
Service Charge :$ 22.33
       -----------
Total Amount Due:$34565.58

Thank you for your investment!

__________________________________

Add a comment
Know the answer?
Add Answer to:
Rewrite the following program using the DecimalFormat class so that your output looks like that below....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Modify the program below so it also calculates and displays the amount of money Package A...

    Modify the program below so it also calculates and displays the amount of money Package A customers would save if they purchased Package B or C, and the amount of money Package B customers would save if they purchased Package C. If there would be no savings, no message should be printed. import java.util.*; public class Lab2 { public static void main (String[] args) {    //scanner Scanner input = new Scanner(System.in);    //declarations int hours; char pack; double totalCharges...

  • JAVA: amortization table: Hi, I have built this code and in one of my methods: printDetailsToConsole...

    JAVA: amortization table: Hi, I have built this code and in one of my methods: printDetailsToConsole I would like it to print the first 3 payments and the last 3 payments if n is larger than 6 payments. Please help! Thank you!! //start of program import java.util.Scanner; import java.io.FileOutputStream; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.lang.Math; //345678901234567890123456789012345678901234567890123456789012345678901234567890 /** * Write a description of class MortgageCalculator here. * * @author () * @version () */ public class LoanAmortization {    /* *...

  • How would you write the following program using switch statements instead of if-else statements (in java)...

    How would you write the following program using switch statements instead of if-else statements (in java) import java.util.*; public class ATM { public static void main(String[] args) { Scanner input = new Scanner (System.in); double deposit, withdrawal; double balance = 6985.00; //The initial balance int transaction; System.out.println ("Welcome! Enter the number of your transaction."); System.out.println ("Withdraw cash: 1"); System.out.println ("Make a Deposit: 2"); System.out.println ("Check your balance: 3"); System.out.println ("Exit: 4"); System.out.println ("***************"); System.out.print ("Enter Your Transaction Number "); transaction...

  • Program Requirements ·         The program prompts the user to enter a loan amount and an interest rate....

    Program Requirements ·         The program prompts the user to enter a loan amount and an interest rate. ·         The application calculates the interest amount and formats the loan amount, interest rate, and interest amount. Then, it displays the formatted results to the user. ·         The application prompts the user to continue. ·         The program stops prompting the user for values after taking 3 loan amounts. ·         The application calculates and displays the total loan and interest amount and ends the program Example Output Welcome to...

  • Please edit my following JAVA code so that there is no main function. I would like...

    Please edit my following JAVA code so that there is no main function. I would like one function in this class that completes what the current program is trying to do so that I can call this class in my main class which will be separate. import java.math.RoundingMode; import java.text.DecimalFormat; import java.util.Scanner; public class enterwklyincme { private static DecimalFormat df = new DecimalFormat("0.00"); public static float readFloat(Scanner reader) { float num; while (true) { try { num = Float.parseFloat(reader.nextLine()); return...

  • Why does my program generate [] when viewing all guests names? ----------------------------------------------- import java.util.*; public class...

    Why does my program generate [] when viewing all guests names? ----------------------------------------------- import java.util.*; public class Delete extends Info { String name; int Id; int del; public Delete() { } public void display() { Scanner key = new Scanner(System.in); System.out.println("Input Customer Name: "); name = key.nextLine(); System.out.println("Enter ID Number: "); Id = key.nextInt(); System.out.println("Would you like to Delete? Enter 1 for yes or 2 for no. "); del = key.nextInt(); if (del == 1) { int flag = 0; //learned...

  • Fix this program package chapter8_Test; import java.util.Scanner; public class Chapter8 { public static void main(String[] args)...

    Fix this program package chapter8_Test; import java.util.Scanner; public class Chapter8 { public static void main(String[] args) { int[] matrix = {{1,2},{3,4},{5,6},{7,8}}; int columnChoice; int columnTotal = 0; double columnAverage = 0; Scanner input = new Scanner(System.in); System.out.print("Which column would you like to average (1 or 2)? "); columnChoice = input.nextInt(); for(int row = 0;row < matrix.length;++row) { columnTotal += matrix[row][columnChoice]; } columnAverage = columnTotal / (float) matrix.length; System.out.printf("\nThe average of column %d is %.2f\n", columnAverage, columnAverage); } } This program...

  • public class Pet {    //Declaring instance variables    private String name;    private String species;...

    public class Pet {    //Declaring instance variables    private String name;    private String species;    private String parent;    private String birthday;    //Zero argumented constructor    public Pet() {    }    //Parameterized constructor    public Pet(String name, String species, String parent, String birthday) {        this.name = name;        this.species = species;        this.parent = parent;        this.birthday = birthday;    }    // getters and setters    public String getName() {        return name;   ...

  • This is a Java program Write a program that reads an unspecified number of integers, determines...

    This is a Java program Write a program that reads an unspecified number of integers, determines home many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number to 2 decimal places. System.out.println(countPositive); System.out.println(countNegative); System.out.println(total); System.out.printf("%.2f",total * 1.0 / count); Assume inputs are always integer [-912985158, 912985158] and ends with 0. Input 1 2 -1 3...

  • The class Engineer Test below is used to test two other class named Project & Engineer....

    The class Engineer Test below is used to test two other class named Project & Engineer. A project has three attributes: projNo (int), projName (string), revenue (double). Add a parameterized constructor, and setters & getters for all attributes. An engineer has four attributes: jobld (int), name (string), rate (double), and a list of projects. For each project, the engineer has a specific amount as profit (project revenue rate). Add a constructor that initializes the attributes: jobild, name and rate. Implement...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT