Question: ExpDecayApp import java.util.*; import java.text.*; public class ExpDecayApp { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub

ExpDecayApp import java.util.*; import java.text.*; public class ExpDecayApp { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub //declare Scanner class and interest, principal vars Scanner input = new Scanner(System.in); double decayConstant, initialQuantity; final DecimalFormat NUMBER_FORMAT = new DecimalFormat("##0.######"); //instantiate a default object of the InvestCalc class ExpDecay value1 = new ExpDecay(); System.out.println("Default ExpDecay Object"); System.out.println(value1.toString()+ " "); //query for decay constant and initial quantity System.out.print("Enter a decay constant: "); decayConstant = input.nextDouble(); System.out.print("Enter the initial quantity: "); initialQuantity = input.nextDouble(); //change object and output value1.setLambda(decayConstant); value1.setN0(initialQuantity); System.out.println("Updated ExpDecay Object"); System.out.println(value1.toString()+ " "); //test the futureValue and displayTable methods // UNCOMMENT THE NEXT TWO STATEMENTS WHEN YOU ARE READY TO TEST // System.out.println("Amount at time=1: " + NUMBER_FORMAT.format(value1.futureQuantity(1)) + " "); // value1.displayTable(); //query for another decay constant and initial quantity System.out.print("Enter a decay constant: "); decayConstant = input.nextDouble(); System.out.print("Enter the initial quantity: "); initialQuantity = input.nextDouble(); //instantiate an object of the InvestCalc class ExpDecay value2 = new ExpDecay(decayConstant, initialQuantity); System.out.println("Non-Default ExpDecay Object"); System.out.println(value2.toString()+ " "); // UNCOMMENT THE NEXT STATEMENT WHEN YOU ARE READY TO TEST // value2.displayTable(); } }
ExpDecay
import java.text.DecimalFormat;
public class ExpDecay{ private double lambda, n0; private static final int SHORT_TERM = 5; private static final int MIDDLE_TERM = 25; private static final int LONG_TERM = 50;
private static final DecimalFormat NUMBER_FORMAT = new DecimalFormat("##0.######"); /** * Default constructor */ public ExpDecay(){ lambda = 0.0; n0 = 0.0; }
/** * Non-default constructor * @param lambda * @param n0 */ public ExpDecay(double lambda, double n0){ this.lambda = lambda; this.n0 = n0; }
/** * Accessor method for decay constate, lambda * @return lambda */ public double getLambda(){ return lambda; }
/** * Accessor method for initial quantity * @return n0 */ public double getN0(){ return n0; }
/** * Mutator method for decay constate, lambda * @param lambda */ public void setLambda(double lambda){ this.lambda = lambda; }
/** * Mutator method for initial quantity * @param n0 */ public void setN0(double n0){ this.n0 = n0; }
/** * Returns the values of the instance variables */ public String toString(){ return ("Initial Quantity: "+ NUMBER_FORMAT.format(n0) + " Lambda: "+ NUMBER_FORMAT.format(lambda)); }
/** * Uses the formula N(t) = N(0)e^(-Lt) * @param time * @return future_quantity */ public double futureQuantity(int t){ double fq = n0 * Math.pow(Math.E, (-1) * lambda * t); return (fq); }
/** * Calculate and display the future quantity at time t=5,25,50 */ public void displayTable(){ System.out.println("TIME\tLAMBDA\tN0\tFUTURE QUANTITY"); System.out.println(SHORT_TERM + "\t" + NUMBER_FORMAT.format(lambda) + "\t" + NUMBER_FORMAT.format(n0) + "\t" + NUMBER_FORMAT.format(futureQuantity(SHORT_TERM)));
System.out.println(MIDDLE_TERM + "\t" + NUMBER_FORMAT.format(lambda) + "\t" + NUMBER_FORMAT.format(n0) + "\t" + NUMBER_FORMAT.format(futureQuantity(MIDDLE_TERM))); System.out.println(LONG_TERM + "\t" + NUMBER_FORMAT.format(lambda) + "\t" + NUMBER_FORMAT.format(n0) + "\t" + NUMBER_FORMAT.format(futureQuantity(LONG_TERM))); System.out.println(); } }
1) [2pt] In some applications of exponential decay, the value for lambda (the decay constant) is affected by the magnitude of N(0), the (initial) quantity at time t-0. Let's start with your ExpDecay class from the previous HW, and add functionality so that if the inital quantity N(0) is 10,000 or more, increase the lambda by 10% when calculating the futureQuantity. Do not change the lambda in ExpDecay objects if the inital quantity N(0) is 10,000 or more, just change the futureQuantity method calculation to increase lambda in the calculation by 10%. Add code to the application (client) class ExpDecayApp.java (attached) to test your new futureQuantity for the test cases given below. 1. Write pseudocode for the revised method. 2. Step through your pseudocode to be sure that it works. 3. Implement your pseudocode in java. Be sure your program is appropriately documented. For input, assume the user inputs the correct type of data, either from the keyboard or using runtime arguments. 4. Compile and run your program to see if it runs (no run-time errors). 5. Complete the following test plan. 6. Test your program with the test plan below. If you discover mistakes in your program, correct them and execute the test plan again. Test Case in ital quantity N (0)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
