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
What is a quick way to determine if a site might contain reliable information?
xz_007 [3.2K]
<span>The best and most correct answer among the choices provided by the question is the fourth choice.

A way of determining that a site is realiable is examining comments about the <span>webpage.</span></span><span>
I hope my answer has come to your help. God bless and have a nice day ahead!</span>
5 0
3 years ago
Read 2 more answers
In computer science, what does the word security mean?
zepelin [54]

Answer:

B

Explanation:

Computer security, cybersecurity or information technology security (IT security) is the protection of computer systems and networks from information disclosure, theft of or damage to their hardware, software, or electronic data, as well as from the disruption or misdirection of the services they provide.[1]

4 0
3 years ago
What is the decimal format of the binary IP address 11001110.00111010.10101010.01000011?
Neporo4naja [7]

Answer:

206.58.170.67 is the decimal format of the given binary IP address.

Explanation:

we can convert the binary number into decimal by the following procedure.

11001110 = 1x2⁷+1x2⁶+0x2⁵+0x2⁴+1x2³+1x2²+1x2¹+0x2⁰

            = 128 + 64 + 0 + 0 + 8 + 4 + 2 + 0

            =   206

00111010 = 0x2⁷+0x2⁶+1x2⁵+ 1x2⁴+1x2³+0x2²+1x2¹+0x2⁰

               = 0 + 0 + 32 + 16 + 8 + 0 + 2 + 0

               = 58

10101010 = 1x2⁷+0x2⁶+1x2⁵+ 0x2⁴+1x2³+0x2²+1x2¹+0x2⁰

              = 128 + 0 + 32 + 0 + 8 + 0 + 2 + 0

              = 170

01000011 =  0x2⁷+ 1x2⁶+ 0x2⁵+ 0x2⁴+ 0x2³+0x2²+1x2¹+1x2⁰

                = 0 + 64 + 0 + 0 + 0 + 0 + 2 + 1

                =  67

so, the IP address is becomes 206.58.170.67

7 0
3 years ago
Define computer memory and write its type <br>​
Helga [31]

Answer:

Computer memory is a generic term for all of the different types of data storage technology that a computer may use, including RAM, ROM, and flash memory. ... Another way that computer memory can vary is that some types are non-volatile, which means they can store data on a long term basis even when there is no power

4 0
3 years ago
Read 2 more answers
What will be displayed after the following statements execute? int funny = 7, serious = 15; funny = serious % 2; if (funny != 1)
Reika [66]

Answer:

1 1

Explanation:

First we have funny = 7 and serious = 15 .Then after that remainder when serious is divided by 2 is stored in funny that is 1.if condition will be false because funny is equal to 1.else if condition will also be false because it is not 2.So else will be executed and funny =1 and serious =1.

Output=1 1

8 0
3 years ago
Read 2 more answers
Other questions:
  • How do you delete text from a slide
    14·2 answers
  • Which of the following locations is the option to show hidden files or folders location
    7·2 answers
  • A perfect binary tree is a complete binary tree with all levels fully filled. Add a method in the BST class to return true if th
    13·1 answer
  • Date criteria are automatically enclosed in ____ when entered in a query design.
    11·1 answer
  • What is an electronic tool that stores large amounts of data in one place in a systematic, logical way? A Database B Platform C
    5·1 answer
  • write a program that asks the user to enter a positive integer, then prints a list of all positive integers that divide that num
    6·1 answer
  • In preparing his persuasive presentation, Reza should most likely focus on clearly presenting his
    6·2 answers
  • Name two materials that we can burn in order to get energy from biomass
    9·1 answer
  • Mississippi law codes state that bullying and cyberbullying are against the law. A court can decide to incur ___________________
    10·1 answer
  • When entering information for a new contact in the address book, Outlook will automatically create a _____. A. Invitation B. Res
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!