Question

Anyone help with me with this assignment, you are calculating ROI and AnnualizedROI. Receive the user's...

Anyone help with me with this assignment, you are calculating ROI and AnnualizedROI.

  • Receive the user's first and last name (in two different lines) and print the below line to the console:
[First character of first name][First character of last name]
  • Receive the initialStockPrice, finalStockPrice, shares (this should be integer), dividends, commissions, and holding period (an integer number of days) from the user and store them in relevant variables.
    • Use the exact same order in receiving the input.
    • Receive all of the inputs of this bullet point in one line.
  • Use the ROI formula (under the "A Simple ROI Example" section), calculate ROI and print the below line to the console:
The ROI of your investment is: [calculated ROI in the 00.00 format]%
  • Use the Annualized ROI formula (under the "Special ROI Considerations" section) and calculate the annualized ROI and print the below line:
    • In converting days to years, consider only 30-day months (assume that one year is 360 days).
The annualized ROI of your investment is: [calculated annualized ROI in the 00.00 format]%
  • Note:
    • ROI and annualized ROI are rounded up to two decimal digits. So, if ROI is 10%, your program should print 10.00%, and if ROI is 9.929% your program should print 10.93%
    • The same rounded value of ROI should be used in annualized ROI calculation. For example if ROI is 9.528, 9.53% or 0.953 should be used when calculating annualized ROI.

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);

/* Type your code here. */
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);

        String firstName,lastName;
        System.out.println("Enter your first Name: ");
        firstName= scnr.nextLine();
        System.out.println("Enter your Last Name: ");
        lastName= scnr.nextLine();

        double  initialStockPrice, finalStockPrice, dividends, commissions;
        int shares, holdingPeriod;
        System.out.print("Enter initial Stock Price: $");
        initialStockPrice= scnr.nextDouble();
        System.out.print("Enter Final Stock Price: $");
        finalStockPrice= scnr.nextDouble();
        System.out.print("Enter number of shares holding: ");
        shares = scnr.nextInt();
        System.out.print("Enter dividend: $");
        dividends= scnr.nextDouble();
        System.out.print("Enter commissions: $");
        commissions= scnr.nextDouble();
        System.out.print("Enter Holding Period: ");
        holdingPeriod= scnr.nextInt();
        System.out.println(firstName.charAt(0)+" "+lastName.charAt(0));
        //Calculate ROI
        double ROI = ((((finalStockPrice-initialStockPrice)*shares)+dividends-(commissions))*100)/(initialStockPrice*shares);
        System.out.print("The ROI of your investment is: "+String.format("%.2f",(double)Math.round(ROI))+"%");
        //Calculating Annualized ROI
        int n= holdingPeriod/360;
        double AROI = Math.pow((1+ROI),(1/n))*100;
        System.out.print("
The annualized ROI of your investment is: "+String.format("%.2f",(double)Math.round(AROI))+"%");

    }
}

//output

C: \Program Files Javaljdk-10.0.2\bin\java.exe-javaagent Enter your first Name: Enter your Last Name: Hack Enter initial Stock Price: $1200 Enter Final Stock Price: $1300 Enter number of shares holding: 1000 Enter dividend: $500 Enter commissions: $120 Enter Holding Period: 1000 T H The ROI of your investment is: 8.00% The annualized ROI of your investment is: 100.00% Process finished with exit code 0

//Thanks....................

Add a comment
Know the answer?
Add Answer to:
Anyone help with me with this assignment, you are calculating ROI and AnnualizedROI. Receive the user's...
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
  • Can someone help me out with this? You are given a program that receives four lines...

    Can someone help me out with this? You are given a program that receives four lines in the below format, and stores them in str1, str2, str3, and num1. This is not a very long sentence. is long 4 Expand this program to: Write an if-elseif-else statement to print this line only if num1 is higher than 0: "Num1 is higher than 0!" print this line only if num1 is 0: "Num1 equals to 0!" And otherwise, print: ""Num1 is...

  • Finish FormatJavaProgram.java that prompts the user for a file name and assumes that the file contains...

    Finish FormatJavaProgram.java that prompts the user for a file name and assumes that the file contains a Java program. Your program should read the file (e.g., InputFile.java) and output its contents properly indented to ProgramName_Formatted.java (e.g., InputFile_Formatted.java). (Note: It will be up to the user to change the name appropriately for compilation later.) When you see a left-brace character ({) in the file, increase your indentation level by NUM_SPACES spaces. When you see a right-brace character (}), decrease your indentation...

  • C++ programming question, please help! Thank you so much in advance!!! In this exercise, you will...

    C++ programming question, please help! Thank you so much in advance!!! In this exercise, you will work with 2 classes to be used in a RPG videogame. The first class is the class Character. The Character class has two string type properties: name and race. The Character class also has the following methods: a constructor Character(string Name, string Race), that will set the values for the name and the race variables set/get functions for the two attributes a function print(),...

  • Within DrJava, create a class called StudentQuizScores and do the following using a do-while loop. 1....

    Within DrJava, create a class called StudentQuizScores and do the following using a do-while loop. 1. You program will read in a student’s first name. The same will be done for the student’s last name. Your program will use respective methods (described below) to accomplish this. 2. Your program will then read in three quiz scores, respectively. This should be done by using the same method three times. This method is described below. 3. Your program will then calculate the...

  • Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class...

    Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class should contain the following data fields and methods (note that all data and methods are for objects unless specified as being for the entire class) Data fields: A String object named firstName A String object named middleName A String object name lastName Methods: A Module2 constructor method that accepts no parameters and initializes the data fields from 1) to empty Strings (e.g., firstName =...

  • You will need to think about problem solving. There are several multi-step activities. Design, compile and...

    You will need to think about problem solving. There are several multi-step activities. Design, compile and run a single Java program, StringEx.java, to accomplish all of the following tasks. Add one part at a time and test before trying the next one. The program can just include a main method, or it is neater to split things into separate methods (all static void, with names like showLength, sentenceType, lastFirst1, lastFirst), and have main call all the ones you have written...

  • Please help me. package a1; public class Methods {    /*    * Instructions for students:...

    Please help me. package a1; public class Methods {    /*    * Instructions for students: Use the main method only to make calls to the    * other methods and to print some testing results. The correct operation of    * your methods should not depend in any way on the code in main.    *    * Do not do any printing within the method bodies, except the main method.    *    * Leave your testing code...

  • For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java...

    For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java program that will input a file of sentences and output a report showing the tokens and shingles (defined below) for each sentence. Templates are provided below for implementing the program as two separate files: a test driver class containing the main() method, and a sentence utilities class that computes the tokens and shingles, and reports their values. The test driver template already implements accepting...

  • I have most of the code for this assignment but need some help getting the rest....

    I have most of the code for this assignment but need some help getting the rest. Go to bottom to see what I have. Please help me figure out the foreach loops and the put() statement. In this assignment, you will be using a new data structure, HashMaps, to repeat Assignment 8.3. Main Method (5 points) Declare and initialize an HashMap with values of type of type Employee, and keys of type integer. In a while loop, keep initializing objects...

  • Please help and please satisfy the directions. The directions are under program 3. port JavaScore. public...

    Please help and please satisfy the directions. The directions are under program 3. port JavaScore. public class Example 4 [ public static int getint String strum - JOptionPane.showinput Dialog("Enter an integer"); return integer.parseInt(strum): public static void main(String args Scanner input = new Scanner (System.in): System.out.println("Enter 2 integers"); intx input.nextInt(); inty input.nextInt(): 1/ these are simple is if b ) System.out.println("The first number is positive): if (0 y0) System.out.println("Both numbers are positive"); ( 11 y) System.out.println("At least one number is positive");...

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