Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a program with the following features: • Takes sequential input from a us

ID: 3732825 • Letter: C

Question

Create a program with the following features: • Takes sequential input from a user chosen input file. • Outputs the input to the monitor and user chosen output file sequentially for each asset under a header (see sample output). • Calculates the total investment, maximum possible annual return, and maximum possible annual loss for the entire input file. • Uses the requested formula to check whether the input file (portfolio) is a sound investment or not. • Outputs calculated values as well as soundness of the investment portfolio to both the terminal and the output file as show in sample output below. • All information sent to the standard output device, must also be written to a file in the same format as shown in sample output below. • The output/input files are to be chosen by the user, proper error handling and loop structures must be implemented to avoid overwriting and other problems. . Declare the variables Ex: PRT string that does not cowiain blanks a floating poin valwe Current price (USD) evested amount (USD)ain Maximum Return(%) Manmum Loss% Total invested (USD) Ex: 10.00 Ex:2000.00 Ex: 120% Ex: 50% x:8453.00 vala a floating point ale a Moating point vahe a floating poine ale Es 130% Ex 60% Ex:1.50 Ex. I Max Return Overall ()oating point val .loating Alint val a ñoating point vale a Boolean value tring that does not contain blanks Ex inFile dtring that does not contain blanks Ex Outfile.txt Max Less Overall 0%) e leput file name Output file name leput file nput file stream variable Ex. inFi Output file output file stream variable Ex. Outfe 2. While choice is true esecute the following steps 3 Prompt the user for the input Eile name to include the Est extension a Open the input file by converting the input file name to a e string first and the appending it to the inpet file variable b) If the file does not open exit the program 4 Prompt the user for the output file name to include the Ixt extension a) Should they choose the same name as the input file, repetitively ask for a diflerent name as this would cause an everwrite Open the output file by converting the output file name to a c sring first and thern appending it to the output file variable. b) Output the header as shown in the sample outpst of both the monitor and output filk 6 Begin reading the input file sequentially line by line: a) Symbol > current price >lovested amount> max return (%) > max loss (%) Calculate Max return (USD) by continally adding on to iR as a new asset is read in: Max Return Max Retur+(max return percemasset)/100Invested amount asset) Note: max returm percent and invested amount represent the asset that is currently in the Ex. Max Return- Max Retum(PRT)+Max Retun ( Qcv)... Max Return(USD>-

Explanation / Answer

import java.io.*;
import javax.swing.*;
import java.util.*;


public class Investment
{
      
   public static void main(String[] args) throws IOException
   {
       String l, symbol;
       int ch = 1;
       File inp;
       File out;
       float maxReturnOverAll = 0, maxLossOverAll = 0, totalInvestment = 0;
      
           Scanner ss = new Scanner(System.in);
           String input = "";
       while(ch == 1)
   {
       System.out.println("Enter input filename");
           input = ss.nextLine();
      
       inp = new File(input);
       System.out.println("Enter output filename");
       input = ss.nextLine();
       out = new File(input);

       if(!inp.exists())
       {
           System.exit(0);
       }
       Scanner sc = new Scanner(inp);
       PrintWriter ab = new PrintWriter(out);
       ab.print("symbol ");
       ab.print("currentPrice ");
       ab.print("investedAmount ");  
       ab.print("maxReturn ");
       ab.print("maxLoss ");
       ab.print("maxReturnOverAll ");  
       ab.print("maxLossOverAll ");
       ab.println("totalInvestment");
       while(sc.hasNext())
       {
       l = sc.nextLine();
           String[] a = l.split(" ");
      
           symbol = a[0];
           float currentPrice = Float.parseFloat(a[1]);
           float investmentAmount = Float.parseFloat(a[2]);
           float maxReturn = Float.parseFloat(a[3]);
           float maxLoss = Float.parseFloat(a[4]);
           System.out.print(symbol + " ");
       System.out.print(currentPrice + " ");
       System.out.print(investmentAmount + " ");
       System.out.print(maxReturn + " ");
       System.out.println(maxLoss);

       maxReturnOverAll = maxReturnOverAll + (maxReturn/100 * investmentAmount);
       maxLossOverAll = maxLossOverAll + (maxLoss / 100 * investmentAmount);
       totalInvestment = totalInvestment + investmentAmount;

       ab.print(symbol + " ");
       ab.print(currentPrice + " ");
       ab.print(investmentAmount + " ");  
       ab.print(maxReturn + " ");
       ab.print(maxLoss + " ");
       ab.print(maxReturnOverAll + " ");  
       ab.print(maxLossOverAll + " ");
       ab.println(totalInvestment);  
       }

       float maxReturnOverAllL = maxReturnOverAll / totalInvestment;
       float maxLossOverAllL = maxLossOverAll / totalInvestment;
       System.out.print("max return Over all is " + maxReturnOverAll + " ");
       System.out.print("max loss Over all is " + maxLossOverAll + " ");
       System.out.print("Total investment is " + totalInvestment + " ");      
       System.out.print(maxReturnOverAllL + " ");
       System.out.println(maxLossOverAllL);

       System.out.println("Do you want to continue(1/0)");
       ch = ss.nextInt();
       ab.close();
   }
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote