In python:
Write a class to create a stock class. That stock class should initialize the following information: symbol, shares, initial price, and current_price. An object should be printed as follows:
Stock Symbol: ….
Shares: …
Initial Price:...
Current Price: ….
There should be methods to buy stock (adds to the shares count) and sell stock (deducts shares). You should ensure that you cannot have negative shares. When you sell a stock you will need to update the current price to what it is sold at in addition you will need to print the amount gained or lost.
# do comment if any problem arises
# Code
class stock:
# constuctor to initialize symbol, shares, initial_price, and current_price
def __init__(self, symbol, shares, initial_price, current_price):
self.symbol = symbol
self.shares = shares
self.initial_price = initial_price
self.current_price = current_price
def __str__(self):
return f'\nStock Symbol: {self.symbol}\nShares: {self.shares}\nInitial Price: {self.initial_price}\nCurrent Price: {self.current_price}'
# buy stock
def buy(self, count):
self.shares += count
# sell stock
def sell(self, count, price):
if self.shares-count > 0:
self.shares -= count
# update current price
self.current_price -= price
# check for gain or loss
if self.current_price/self.shares > self.initial_price/self.shares:
print(
f'Amount gained: {self.current_price/self.shares-self.initial_price/self.shares}')
else:
print(
f'Amount gained: {self.initial_price/self.shares-self.current_price/self.shares}')
else:
print("\nNot enough shares")
# testing above class
testing = stock("GK", 10, 200, 200)
# print stock
print(testing)
Screenshot:

Output:

In python: Write a class to create a stock class. That stock class should initialize the...
PYTHON Create a Student class and initialize it with name and roll number. Make methods to : 1. Display - It should display all informations of the student. 2. setAge - It should assign age to student 3. setMarks - It should assign marks to the student.
PLEASE DO BOTH OF THESE IN PYTHON 1) Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 1.0 in the default constructor. A non-argument constructor method to create a default rectangle. Another constructor method to create a rectangle with user-specified height and width. Python...
Create a Python file (book.py) that has a class named Book. Book class has four attributes, title (string), author(string), isbn(string), and year(int). Title - the name of the book. Author - the name of the persons who wrote the book. ISBN - is a unique 13 digit commercial book identifier. Year - the year the title was printed. Your class should have the following methods: (1) __init__(self, title, author, isbn, year): This method called when an object (book) is created...
Create a Python file (book.py) that has a class named Book. Book class has four attributes, title (string), author(string), isbn(string), and year(int). Title - the name of the book. Author - the name of the persons who wrote the book. ISBN - is a unique 13 digit commercial book identifier. Year - the year the title was printed. Your class should have the following methods: (1) __init__(self, title, author, isbn, year): This method called when an object (book) is created...
need code for this in java
Design a set of classes that work together to simulate the Stock Transaction System. You should design the following classes: 1. the StockMarket class. This class simulates the stock market such as Nasdaq, NYSD, or other stock market. The class's responsibility are as follows: -To know the stock market abbreviation, full name, location, an arraylist of stocks for this market 2. the Company class: this class simulates a company that has stock released on...
Design a set of classes that work together to simulate the Stock Transaction System. You should design the following classes: 1. the StockMarket class. This class simulates the stock market such as Nasdaq, NYSD, or other stock market. The class's responsibility are as follows: -To know the stock market abbreviation, full name, location, an arraylist of stocks for this market 2. the Company class: this class simulates a company that has stock released on a stock market. The class's...
write this program in python plz Many investment management companies are switching from manual stock trading done by humans to automatic stock trading by computers. You've been tasked to write a simple automatic stock trader function that determines whether to buy, sell, or do nothing (hold) for a particular account. It should follow the old saying "Buy low, sell high!" This function takes 4 input parameters in this order: current_shares - current number of shares of this stock in the...
Look at the Account class below and write a main method in a different class to briefly experiment with some instances of the Account class.Using the Accountclass as a base class, write two derived classes called SavingsAccountand CurrentAccount.ASavingsAccountobject, in addition to the attributes of an Account object, should have an interest variable and a method which adds interest to the account. ACurrentAccount object, in addition to the instance variables of an Account object, should have an overdraft limit variable. Ensure...
The program needs to be in python :
First, create a BankAccount class. Your class should support the following methods: class BankAccount (object): """Bank Account protected by a pin number.""" def (self, pin) : init "n"Initial account balance is 0 and pin is 'pin'."" self.balance - 0 self.pin pin def deposit (self, pin, amount): """Increment account balance by amount and return new balance.""" def withdraw (self, pin, amount): """Decrement account balance by amount and return amount withdrawn.""" def get balance...
Create the Python code for a program adhering to the following specifications. Write an Employee class that keeps data attributes for the following pieces of information: - Employee Name (a string) - Employee Number (a string) Make sure to create all the accessor, mutator, and __str__ methods for the object. Next, write a class named ProductionWorker that is a subclass of the Employee class. The ProductionWorker class should keep data attributes for the following information: - Shift number (an integer,...