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
The ____number system is base 10​
evablogger [386]

Answer:

The correct answer to this question is given below in the explanation section.

Explanation:

This is a fill-in-blank question.

The answer is:

The decimal number system is base 10.

In our everyday life, we use a number system that is a Base-10 system. As we know that the base-10 is known as the decimal system and this number has 10 digital starting from 0 to 9 such as:

0,1,2,3,4,5,6,7,8,9

We use this number system in our daily accounting and in daily life and it is a base-10 number system. This number system uses 10 as its base number so it is called a base-10 system. It is also called the decimal number system.

7 0
3 years ago
What would you need to install if you have an app that is incompatible with your current operating system?
Angelina_Jolie [31]

Answer:

D. A virtual machine

Explanation:

7 0
3 years ago
If a window is split into two panes and you want to return to a single window, choose what on the View tab?
adell [148]
Select that square and it should do the trick

8 0
3 years ago
Which of the following statements are true of network packets? Check all of the boxes that apply. They contain control informati
oksian1 [2.3K]

They contain control information.

They contain user data.

They are sent over a network.




They can travel indefinitely over the Internet is wrong as every packet contains the source and destination in the header. If the destination is not available you'll get an error message for example "The HTTP 404 Not Found Error" or another error depending on the application. The packet is then discarded.  

4 0
3 years ago
Which feature of a blog allows an author to interact and get feedback from his or her readers?
Gemiola [76]

Answer:

comment section g

Explanation:

7 0
3 years ago
Other questions:
  • Please Help!<br><br>in return brainliest and special thanks
    5·1 answer
  • Create a logic array qualifyingIndex with true for any location where the runner is male with a running time less than 8.2. Row
    15·1 answer
  • The one place where c++ allows aggregate operations on arrays is the input and output of c-strings.
    8·1 answer
  • A(n) _____ program, used to participate in a newsgroup, is often provided with some e-mail software.
    14·1 answer
  • IF ACCURATE = BRAINLY (if u answer rubbish randomness= reported AND if you got questions dont ask in answer slot= reported)
    13·1 answer
  • Explain In your own words what a motherboard is and it’s functions?
    10·2 answers
  • Translation of a file into a coded format that occupies less space than the original file is called
    15·1 answer
  • When Kim was working in her Microsoft® Excel® spreadsheet, she accidentally placed her book on the spacebar and erased the conte
    13·1 answer
  • Which is the most portable memory media? Mention its features in detail.
    10·1 answer
  • What does input allow a computer to do
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!