Question

Problem 7. Stock Market For this program you are given a String that represents stock prices for a particular com- y over a p

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

/* The java program that prompts user to enter the price list of the stock price. Then find the lowest and highest price
* and its day on lowest and highest .Print the result of highest and lowest price of stock prices and its day * */

//StockMarket.java
import java.util.Scanner;
public class StockMarket
{
   public static void main(String[] args)
   {
       //declare variables of integer type
       int lowest;
       int lowestDay;
       int highest;
       int highestDay;
       //create a object of Scanner class
       Scanner console=new Scanner(System.in);
       System.out.printf("Please enter stock prices: ");
       String prices=console.nextLine();//raed prices as string
      
       //split prices by split method by comma as delimiter
       String priceList[]=prices.trim().split(",");
      
      
       //Assume starting value in priceList is lowest
       //and highest values of stock prices
       lowest=Integer.parseInt(priceList[0]);
       lowestDay=0;
       highest=Integer.parseInt(priceList[0]);
       highestDay=0;
      
       /*Now update the lowest and highest and its
       * days inside the for loop */
       for (int day = 1; day < priceList.length;day++)
       {
           int update_price=Integer.parseInt(priceList[day]);
           //update the lowest and lowestDay
           if(update_price<lowest)
           {
               lowest=update_price;
               lowestDay=day;
           }
           //update the highest and highest day
           if(update_price>highest)
           {
               highest=update_price;
               highestDay=day;
           }
       }
       //print the highest and lowest on day values
       System.out.println("Highest price: "+highest+" occurred on day # "+highestDay);
       System.out.println("Lowest price: "+lowest+" occurred on day # "+lowestDay);
  
   }

}

-----------------------------------------------------------------------------------------------------------------------------
Sample Output:

Sample run1:
Please enter stock prices: 1,22,30,38,44,49,73,52,66
Highest price: 73 occurred on day # 6
Lowest price: 1 occurred on day # 0


Sample run2:
Please enter stock prices: 41,37,40,54,51,63,54,47,23,33
Highest price: 63 occurred on day # 5
Lowest price: 23 occurred on day # 8

Add a comment
Know the answer?
Add Answer to:
Problem 7. Stock Market For this program you are given a String that represents stock prices...
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
  • USE JAVA Problem 1: Guess a Number You are writing a program for a number guessing...

    USE JAVA Problem 1: Guess a Number You are writing a program for a number guessing game. For playing "Guess a Number", the program will generate a number for player to guess from within a range specified by the player. The program will take as input the lowest number in the range and the highest number in the range from the player, and then a series of guesses of the form: <n,>n, = n, where n is the number guessed....

  • In the first task, you will write a Java program that accepts a string of the...

    In the first task, you will write a Java program that accepts a string of the format specified next and calculate the answer based on the user input. The input string should be of the format dddxxdddxx*, where d represents a digit and x represents any character and asterisk at the end represents that the string can have any number of characters at the end. 1. Prompt the user to enter a string with the specific format (dddxxdddxx*) 2. Read...

  • WRITE JAVA PROGRAM Problem Statement You are required to write a stock price simulator, which simulates...

    WRITE JAVA PROGRAM Problem Statement You are required to write a stock price simulator, which simulates a price change of a stock. When the program runs, it should do the following:  Create a Stock class which must include fields: name, symbol, currentPrice, nextPrice, priceChange, and priceChangePercentage.  The Stock class must have two constructor: a no-argument constructor and a constructor with four parameters that correspond to the four fields. o For the no-argument constructor, set the default value for...

  • ANY HELP PLEASE. PLEASE READ THE WHOLE INSTRUCTION THANK YOU Write a program GS.java that will...

    ANY HELP PLEASE. PLEASE READ THE WHOLE INSTRUCTION THANK YOU Write a program GS.java that will be responsible for reading in the names and grades for a group of students, then reporting some statistics about those grades. The statistics to be gathered are the number of scores entered, the highest score and the name(s) of the student(s) who earned that score, the lowest score and the name(s) of the student(s) who earned that score, and the average score for the...

  • Suppose you are given the following information about a particular industry: Market demand Market supply QD...

    Suppose you are given the following information about a particular industry: Market demand Market supply QD = 14400 - 100P QS = 1500P C(a)=673 + 20 MC(q) = 200 Firm total cost function Firm marginal cost function. Assume that all firms are identical and that the market is characterized by perfect competition. Find the equilibrium price, the equilibrium quantity, the output supplied by the firm, and the profit of each firm. The equilibrium price is $ 9. (Enter your response...

  • How do you write out this C++ program and zip the files? A local department store...

    How do you write out this C++ program and zip the files? A local department store is having a BoGoHo (Buy One, Get One Half Off) sale. The store manager wants a program that allows the salesclerk to enter the prices of two items. The program should calculate and display the total amount the customer owes. The half-off should always be taken on the item having the lowest price. For example, if the items cost $24.99 and $10, the half-off...

  • Write in C Spring 2016 Lab Assignment 11 ET2100 In computer programming in general a "string"...

    Write in C Spring 2016 Lab Assignment 11 ET2100 In computer programming in general a "string" is a sequence of characters. In the C language anything within double quotes is a "string constant" so you have been seeing strings all semester. But we can also have string variables. In the C language these are implemented as an array of char, e.g. char name (10]: In order to make these variables easier to work with, it has been universally agreed that...

  • Problem: You will write a program to compute some statistics based on monthly average temperatures for...

    Problem: You will write a program to compute some statistics based on monthly average temperatures for a given month in each of the years 1901 to 2016. The data for the average August temperatures in the US has been downloaded from the Climate Change Knowledge Portal, and placed in a file named “tempAugData.txt”, available on the class website. The file contains a sequence of 116 values. The temperatures are in order, so that the first one is for 1901, the...

  • PLEASE HELP!!!I need help with the following JAVA PROGRAMS. Please ready carefully. So this comes from...

    PLEASE HELP!!!I need help with the following JAVA PROGRAMS. Please ready carefully. So this comes from tony gaddis starting out with java book. I have included the screenshot of the problems for reference. I need HELP implementing these two problems TOGETHER. There should be TWO class files. One which has TWO methods (one to implement problem 8, and one to implement problem 9). The second class should consist of the MAIN program with the MAIN method which calls those methods....

  • Goals: Practicing functions and parameter types. Problem: You are to create a program that will aid...

    Goals: Practicing functions and parameter types. Problem: You are to create a program that will aid in a farmer in monitoring the amount of corn to feed livestock each week. There is a template named "Labs1-5template.cpp" posted on Canvas which you should download and complete. Follow the instructions given in the template and follow the assignment guidelines for the course. Do not use global variables and do not use the same variable name in multiple functions. Your finished code should...

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