 # Part 1 The Government of India recently demonetized the existing c...

## Question

Show transcribed text

## Transcribed Text

Part 1 The Government of India recently demonetized the existing currency notes of 1000 and 500 denominations and issued new currency notes instead in 2000 and 500 denominations. People holding the old currency notes needed to exchange them for the new currency notes at bank branches. For this homework, we will assume that the bank will use the least number of notes principle, i.e., it will first calculate the 2000 denomination notes first, and the remaining amount, if any, as 500 denomination notes. Program the Bank calculation using the following guidelines. a. Create a package named cs520.hw1.part1 b. Create a class named Demonetize under the above package with the main method. c. The code in the main method should do the following: i. Prompt the user for a string input value for the number of old 1000 notes and store it in a variable named input1. ii. Convert the string to an integer and store it in the variable named thousands. You can assume that the user enters a valid integer number (>= 0) iii. Prompt the user for a string input value for the number of old 500 notes and store it in a variable named input2. iv. Convert the string to an integer and store it in the variable named fiveHundreds. You can assume that the user enters a valid integer number (>= 0) v. Calculate the total amount to be converted to the new notes using the above two inputs and store the value into an integer variable. vi. Print the the above value to the console. vii. Declare the integer variables named newTwoThousands, and newFiveHundreds. viii. Declare another integer variable named remainingAmount. ix. Compute the newTwoThousands and the remainingAmount. Print the information to the console. x. Compute the newFiveHundreds. Print the information to the console. xi. Using a message dialog, show the summary of the above values to the user. See the sample input and output below. Sample Input: Sample Console Output: Sample Dialog Output: Part2 𝒏𝒏𝟏𝟏 The Euler constant, e, is computed by the following series: For example, if n = 2, Ifn=5,1 1 1 1 1 𝑒𝑒=1+ + + + + =2.716666667 1! 2! 3! 4! 5! 𝒆𝒆=𝟏𝟏+ 𝒊𝒊)𝟏𝟏 𝒊𝒊! 11 𝑒𝑒=1+ 1!+ 2! =2.5 If n = 12, 𝑒𝑒=1+1+1+1+1+1+1+1+1+1+1 1! 2! 3! 4! 5! 6! 7! 8! 9! 10! 11! 12! Program the computation of the Euler constant using a loop for a given value of n using the following instructions: a. Create a package named cs520.hw1.part2 b. Create a class named EulerConstant under the above package with the main method. c. Write the static method, compute, that takes the number n as its argument. The code for this method should use a loop to calculate the result using the formula shown in the above equation. The method returns the computed result. Reuse the factorial computed in the previous iteration for the next iteration, i.e., do not explicitly compute each factorial in each iteration of the loop. In each iteration, print the intermediate results as shown in the sample output. +1+1 = 2.718281828 d. The code in the main method should do the following: i. Invoke the method, compute, for n = 2, and store the result into the variable, result1. ii. Print the result to the console. iii. Invoke the method, compute, for n = 5, and store the result into the variable, result2. iv. Print the result to the console. v. Invoke the method, compute, for n = 12, and store the result into the variable, result3. vi. Print the result to the console. vii. Print the difference between result2 and result1, and result3 and result2. The double values are printed to 9 decimal places using the printf’s %.9f format. Sample Console Output: Computing with n = 2 Factorial of 1 is 1 Factorial of 2 is 2 e =2.500000000 Computing with n = 5 Factorial of 1 is 1 Factorial of 2 is 2 Factorial of 3 is 6 Factorial of 4 is 24 Factorial of 5 is 120 e =2.716666667 Computing with n = 12 Factorial of 1 is 1 Factorial of 2 is 2 Factorial of 3 is 6 Factorial of 4 is 24 Factorial of 5 is 120 Factorial of 6 is 720 Factorial of 7 is 5040 Factorial of 8 is 40320 Factorial of 9 is 362880 Factorial of 10 is 3628800 Factorial of 11 is 39916800 Factorial of 12 is 479001600 e =2.718281828 Diff of result2 and resultl = 0.216666667 Diff of result3 and result2 = 0.00161 e = 2.000000000 e = 2.500000000 e = 2.000000000 e = 2.500000000 e = 2.666666667 e = 2.708333333 e = 2.716666667 e = 2.000000000 e = 2.500000000 e = 2.666666667 e = 2.708333333 e = 2.716666667 e = 2.718055556 e = 2.718253968 e = 2.71827870 e = 2.718281526 e = 2.718281801 e = 2.718281826 e = 2.718281828

## Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

package cs520.hw1.part1;

// Import JPane package
import javax.swing.JOptionPane;

// Beginning of De-Monetize Class
public class Demonetize
{
// Beginning of Main Class
public static void main(String[] args)
{
// Show a dialog box and convert entered value to the first integer
String input1 = JOptionPane.showInputDialog("Enter # of Old 1000's:");
int thousands = Integer.parseInt(input1);

// Show a dialog box and convert entered value to the integer
String input2 = JOptionPane.showInputDialog("Enter # of Old 500's:");
int fiveHundreds = Integer.parseInt(input2);

// Calculate the total old note amount
int totReqConvAmt = (thousands*1000) + (fiveHundreds*500);

// Prints out the number of old 1000 and 500 notes and total amount
System.out.println("Old 1000 notes = " + thousands + ", Old 500 notes = " + fiveHundreds);
System.out.println("Requested Conversion Amount = " + totReqConvAmt);

// Calculate the new 2000 notes and remaining amount
int newTwoThousands = totReqConvAmt / 2000;
int remainingAmount = totReqConvAmt % 2000;

// Print out the new 2000 notes and remaining amount
System.out.println("New 2000 notes = " + newTwoThousands + ", Remaining Amount = " + remainingAmount);...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

\$13.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

### Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.