[go: up one dir, main page]

0% found this document useful (0 votes)
10 views2 pages

q1 Soln

Uploaded by

coolgrinder235
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

q1 Soln

Uploaded by

coolgrinder235
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

interface Stock_Market_Instrument {

double calculateTotalValue();
}

abstract class Stock_IPO implements Stock_Market_Instrument {


private int quantity;
private double pricePerShare;

public Stock_IPO(int quantity, double pricePerShare) {


this.quantity = quantity;
this.pricePerShare = pricePerShare;
}

public double calculateTotalValue() {


return quantity * pricePerShare;
}

public int getQuantity() {


return quantity;
}

public double getPricePerShare() {


return pricePerShare;
}

public void setQuantity(int quantity) {


this.quantity = quantity;
}

public void setPricePerShare(double pricePerShare) {


this.pricePerShare = pricePerShare;
}

public abstract void displayStockInformation();


}

class Stock extends Stock_IPO {

public String name;


public String[] highestInvestors;

public Stock(String name, int quantity, double pricePerShare) {


super(quantity, pricePerShare);
this.name = name;
this.highestInvestors = new String[3];
}

public Stock(Stock s){


super(s.getQuantity(), s.getPricePerShare());
this.name = s.name;
this.highestInvestors = new String[3];
for(int i = 0; i < s.highestInvestors.length; i++){
this.highestInvestors[i] = s.highestInvestors[i];
}
}

public void displayStockInformation() {


System.out.println("Stock: " + name + ", Total value: $" +
String.format("%.2f", calculateTotalValue()));
for(int i = 0; i < highestInvestors.length; i++){
System.out.println("Highest Investor: " + highestInvestors[i]);
}
System.out.println();
}

public void changeName(String newName){


this.name = newName;
}

public void setHighestInvestors(String[] highestInvestors){


this.highestInvestors = highestInvestors;
}

public class StockMarketSimulation {


public static void main(String[] args) {
Stock appleStock = new Stock("Apple", 100, 150.0);
Stock microsoftStock = new Stock("Microsoft", 200, 120.0);
Stock googleStock = new Stock("Google", 150, 180.0);
Stock metaStock = new Stock(appleStock);

String[] i1 = {"Warren Buffet", "Shiv Nadar"};


String[] i2 = {"Anne","Joe"};
String[] i3 = {"John", "Mark"};
String[] i4 = {"Ambani", "Rakesh"};

appleStock.setHighestInvestors(i1);
microsoftStock.setHighestInvestors(i2);
googleStock.setHighestInvestors(i3);
metaStock.setHighestInvestors(i4);

metaStock.setQuantity(125);
metaStock.setPricePerShare(300.0);

appleStock.displayStockInformation();
microsoftStock.displayStockInformation();
googleStock.displayStockInformation();
metaStock.displayStockInformation();
}
}

You might also like