1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
puteri [66]
2 years ago
9

Create a class called StockTester that has the following fucntionality. a. Create a main method with an ArrayList named dataStoc

k that stores objects of type Stock. b. Add code that reads the content of StockInfo.csv and places it in dataStock. c. Create a new Stock object named newStock using the constructor in Question 1. Set the values to the following. Stock name: Gamma, Stock purchase date: 03/01/20, Number of Shares of Stock: 100, Stock Price: 50.5. Add newStock to dataStock. d. Print the information associated with newStock using printStock. e. Using the method requiredReturn, determine the rate of return required for your stock in Pitsco to have a value of $4,000 in 3 years. Print the result to the screen so that the user can clearly read the result.
Computers and Technology
1 answer:
myrzilka [38]2 years ago
3 0

Solution :

public class $\text{Stock}$ {

private $\text{String}$ stockName, $\text{purchaseDate}$;

private $\text{int}$ nShares;

private $\text{double}$ price;

 

public $\text{Stock}()$

{

this.stockName = "";

this.purchaseDate = "";

this.nShares = 0;

this.price = 0.0;

}

public Stock(String stockName, String purchaseDate, int nShares, double price) {

this.stockName = stockName;

this.purchaseDate = purchaseDate;

this.nShares = nShares;

this.price = price;

}

public String getStockName() {

return stockName;

}

public void setStockName(String stockName) {

this.stockName = stockName;

}

public String getPurchaseDate() {

return purchaseDate;

}

public void setPurchaseDate(String purchaseDate) {

this.purchaseDate = purchaseDate;

}

public int getnShares() {

return nShares;

}

public void setnShares(int nShares) {

this.nShares = nShares;

}

public double getPrice() {

return price;

}

public void setPrice(double price) {

this.price = price;

}

 

public String toString()

{

return("Stock name: " + this.stockName + "\nPurchase date: " + this.purchaseDate

+ "\nNumber of shares of stock: " + this.nShares + "\nPrice: $" + String.format("%,.2f", this.price));

}

 

public void printStock()

{

System.out.println("Stock name: " + this.stockName + "\nPurchase date: " + this.purchaseDate

+ "\nNumber of shares of stock: " + this.nShares + "\nPrice: $" + String.format("%,.2f", this.price)

+ "\n");

}

}

StockTester.java (Driver class)

import $\text{java.io.}$File;

import $\text{java.io.}$File$\text{NotFound}$Exception;

import $\text{java.util.}$ArrayList;

import $\text{java.util.}$Scanner;

$\text{public}$ class StockTester {

 

private static final String FILENAME = "StockInfo$.$csv";

 

public static $\text{void}$ main($\text{String}[]$ args)

{

ArrayList$$ dataStock = $\text{readData}$(FILENAME);

 

System.out.println("Initial stocks:");

for(Stock s : dataStock)

s.printStock();

 

System.out.println("Adding a new Stock object to the list..");

Stock newStock = new Stock("Gamma", "03/01/20", 100, 50.5);

dataStock.add(newStock);

 

System.out.println("\nStocks after adding the new Stock..");

for(Stock s : dataStock)

s.printStock();

 

Stock targetStock = dataStock.get(3);

double reqReturn = requiredReturn(targetStock, 4000, 3);

System.out.println("Required rate of return = " + String.format("%.2f", reqReturn) + "%");

}

 

private static ArrayList<Stock> readData(String filename)

{

ArrayList<Stock> stocks = new ArrayList<>();

Scanner fileReader;

try

{

fileReader = new Scanner(new File(filename));

while(fileReader.hasNextLine())

{

String[] data = fileReader.nextLine().trim().split(",");

String stockName = data[0];

String purchaseDate = data[1];

int nShares = Integer.parseInt(data[2]);

double price = Double.parseDouble(data[3]);

 

stocks.add(new $\text{Stock}$(stockName, $\text{purcahseDate}$, nShares, price));

}

fileReader.close();

}catch(FileNotFoundException fnfe){

System.out.println(filename + " cannot be found!");

System.exit(0);

}

return stocks;

}

 

private static double requiredReturn(Stock s, double targetPrice, int years)

{

double reqReturn;

 

double initialPrice = s.getPrice() * s.getnShares();

reqReturn = ((targetPrice - initialPrice) / initialPrice * years) * 100;

 

return reqReturn;

}

}

You might be interested in
Who is affected by electronuc theft of a song ?
Sonbull [250]
I would have to say the artist.
simply because the artist or publisher does not receive any income on their product. 
7 0
3 years ago
Read 2 more answers
What is the troubleshooting process?
sattari [20]
<span>It is a logical, systematic search for the source of a problem in order to solve it, and make the product or process operational again.Troubleshooting is needed to identify the symptoms. ...Troubleshooting is the process of isolating the specific cause or causes of the symptom.</span>
6 0
2 years ago
What is the difference between second generation and third generation​
Eduardwww [97]

These were later renamed to "Specialized Technology" and "Simscape Components" to help explain this difference.

Specialized Technology (Second Generation) is a Simulink based library and has been around for longer. It can still connect to Simscape, but in the same way you can connect Simulink models to Simscape -- that is, you need converters and sometimes to break algebraic loops, etc. It also has more dedicated electrical power systems capabilities. If your model will be only power systems, and especially if it's a larger model, I'd recommend this one.

Simscape Components (Third Generation) is built using the Simscape language and therefore connects directly with other Simscape blocks. If you plan to use other Simscape domains like mechanical, hydraulic, etc. I'd recommend this one.

4 0
2 years ago
Which command displays the status of the ipsec installation?
Alexandra [31]
Character command shows the status.
8 0
2 years ago
Mike needs to write the primary objectives of a project in a project plan. In which section should he write them?
Advocard [28]

Mike needs to write the primary objectives of a project in a project plan. He should write this under the SCOPE section of the project plan.

Explanation:

  • Project scope is the part of project planning that involves determining and documenting a list of specific project goals, deliverables, features, functions, tasks, deadlines, and ultimately costs.
  • It is what needs to be achieved and the work that must be done to deliver a project.
  • The Scope of Work (SOW) is the area in an agreement where the work to be performed is described.
  • The SOW should contain any milestones, reports, deliverables, and end products that are expected to be provided by the performing party. The SOW should also contain a time line for all deliverables.
  • The scope is simply all the work that needs to be done in order to achieve a projects objectives.
  • A project scope, or project scope statement, is a tool used to describe the major deliverables of a project including the key milestones, high level requirements, assumptions, and constraints.

7 0
3 years ago
Other questions:
  • 11. The golden rule of safe driving is: A. Always drive at the posted speed limit B. Never drive while physically or mentally im
    6·1 answer
  • You can install several printers on your machine, but at least one must be the _______ printer.
    6·1 answer
  • You work as the IT administrator for a small corporate network. To accommodate specific network communication needs for an upcom
    9·1 answer
  • Write a program Gas.java that computes and displays the price a person will pay for gas at the gas station. The program takes th
    12·1 answer
  • Write 5 things that can be done to avoid computer vision syndrome
    8·2 answers
  • To move an object to the bottom of the stack, click the Send Backwards arrow and then click Send to Back in the Arrange group on
    7·1 answer
  • (25 POINTS)Which statement best reflects the importance of following safety guidelines?
    8·2 answers
  • E commerce is the demand of modern society both for time and money
    14·2 answers
  • Hello guys please help me <br>list and identify the components of computer ​
    15·1 answer
  • What is referential integrity
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!