// for scanner
import java.util.*;
// Stock class
public class Stock{
// stock name field
private String name;
// stock symbol field
private String symbol;
// stock current price
private float currentPrice;
// stock next price
private float nextPrice;
// price change between days
private float priceChange;
// price change in percent
private float priceChangePercentage;
// empty constructor
public Stock(){
this.name="Microsoft";
this.symbol="MS";
this.currentPrice=Float.valueOf("46.87");
this.nextPrice=Float.valueOf("46.87");
}
// cinstructot with frist 4 fields
public Stock(String name,String symbol,float currentPrice,float nextPrice){
this.name=name;
this.symbol=symbol;
this.currentPrice=currentPrice;
this.nextPrice=nextPrice;
}
// getter methods for all the fields
public String getName(){
return this.name;
}
public String getSymbol(){
return this.symbol;
}
public float getCurrentPrice(){
return this.currentPrice;
}
public float getNextPrice(){
return this.nextPrice;
}
public float getPriceChange(){
return this.priceChange;
}
public float getPriceChangePercentage(){
return this.priceChangePercentage;
}
// setter methods
public void setName(String name){
this.name=name;
}
public void setSymbol(String symbol){
this.symbol=symbol;
}
// if price passed is -ve set current price =0
public void setCurrentPrice(float currentPrice){
if(currentPrice<0){
this.currentPrice=0;
}else{
this.currentPrice=currentPrice;
}
}
// if price passed is -ve set next price =0
public void setNextPrice(float nextPrice){
if(nextPrice<0){
this.nextPrice=0;
}else{
this.nextPrice=nextPrice;
}
}
public void setPriceChange(float priceChange){
this.priceChange=priceChange;
}
public void setPriceChangePercentage(float priceChangePercentage){
this.priceChangePercentage=priceChangePercentage;
}
// simulatePrice function
// returns the new price of the stock
public float simulatePrice(){
// initialize random nummber generator
Random rand = new Random();
// get a random float number between 0-1
// divide by 10 so that it stays in range of 0-10%
float randomPercent=rand.nextFloat()/10;
// random number to increase of decrease current price
int positive=rand.nextInt(2);
if(positive!=0){
// increase next price by randomPercent calculated
setNextPrice(this.currentPrice+(this.currentPrice*randomPercent));
}
else{
// decrease next price by randomPercent calculated
setNextPrice(this.currentPrice-(this.currentPrice*randomPercent));
}
// set price change to the difference
setPriceChange(this.nextPrice-this.currentPrice);
// calculate and set price change percentage
setPriceChangePercentage((this.priceChange/this.currentPrice)*100);
// return the new price calculated
return this.nextPrice;
}
// main function
public static void main(String[] args){
// get stock name ,symbol and current price
System.out.println("\t--Stock Price Simulation--");
Scanner s=new Scanner(System.in);
System.out.println("Enter Stock Name");
String stockName=s.next();
System.out.println("Enter Stock Symbol");
String stockSymbol=s.next();
System.out.println("Enter Current Stock Price");
float currentStockPrice=s.nextFloat();
Stock stock;
// if user enters NONE ,or NA or 0.0 then
if(stockName.equals("NONE") || stockSymbol.equals("NA") || currentStockPrice==0.0){
stock=new Stock();
}
else{
stock=new Stock(stockName,stockSymbol,currentStockPrice,currentStockPrice);
}
// if Stock Name set to NONE or Stock Symbol set to NA or stock current price set to 0.0
// exit
if(stockName.equals("NONE") || stockSymbol.equals("NA") || currentStockPrice==0.0){
System.out.println("Stock Name set to NONE or Stock Symbol set to NA or stock current price set to 0.0");
System.out.println("Exiting");
}
else{
// loop for 30 count
System.out.println("\t--30 Days Simulation--");
for(int i=1;i<=30;i++){
// get the new price
float price=stock.simulatePrice();
// print all the fields of the stock
System.out.println("--Day-"+i+"--");
System.out.println("Stock Name:"+stock.getName());
System.out.println("Stock Symbol:"+stock.getSymbol());
System.out.println("Stock Current Price:"+stock.getCurrentPrice());
System.out.println("Stock Next Price:"+stock.getNextPrice());
System.out.println("Price Change:"+stock.getPriceChange());
System.out.println("Price Change Percentage:"+stock.getPriceChangePercentage()+"%");
// set stock current price to new price
stock.setCurrentPrice(price);
}
}
}
}
// for scanner
import java.util.*;
// Stock class
public class Stock{
// stock name field
private String name;
// stock symbol field
private String symbol;
// stock current price
private float currentPrice;
// stock next price
private float nextPrice;
// price change between days
private float priceChange;
// price change in percent
private float priceChangePercentage;
// empty constructor
public Stock(){
this.name="Microsoft";
this.symbol="MS";
this.currentPrice=Float.valueOf("46.87");
this.nextPrice=Float.valueOf("46.87");
}
// cinstructot with frist 4 fields
public Stock(String name,String symbol,float currentPrice,float nextPrice){
this.name=name;
this.symbol=symbol;
this.currentPrice=currentPrice;
this.nextPrice=nextPrice;
}
// getter methods for all the fields
public String getName(){
return this.name;
}
public String getSymbol(){
return this.symbol;
}
public float getCurrentPrice(){
return this.currentPrice;
}
public float getNextPrice(){
return this.nextPrice;
}
public float getPriceChange(){
return this.priceChange;
}
public float getPriceChangePercentage(){
return this.priceChangePercentage;
}
// setter methods
public void setName(String name){
this.name=name;
}
public void setSymbol(String symbol){
this.symbol=symbol;
}
// if price passed is -ve set current price =0
public void setCurrentPrice(float currentPrice){
if(currentPrice<0){
this.currentPrice=0;
}else{
this.currentPrice=currentPrice;
}
}
// if price passed is -ve set next price =0
public void setNextPrice(float nextPrice){
if(nextPrice<0){
this.nextPrice=0;
}else{
this.nextPrice=nextPrice;
}
}
public void setPriceChange(float priceChange){
this.priceChange=priceChange;
}
public void setPriceChangePercentage(float priceChangePercentage){
this.priceChangePercentage=priceChangePercentage;
}
// simulatePrice function
// returns the new price of the stock
public float simulatePrice(){
// initialize random nummber generator
Random rand = new Random();
// get a random float number between 0-1
// divide by 10 so that it stays in range of 0-10%
float randomPercent=rand.nextFloat()/10;
// random number to increase of decrease current price
int positive=rand.nextInt(2);
if(positive!=0){
// increase next price by randomPercent calculated
setNextPrice(this.currentPrice+(this.currentPrice*randomPercent));
}
else{
// decrease next price by randomPercent calculated
setNextPrice(this.currentPrice-(this.currentPrice*randomPercent));
}
// set price change to the difference
setPriceChange(this.nextPrice-this.currentPrice);
// calculate and set price change percentage
setPriceChangePercentage((this.priceChange/this.currentPrice)*100);
// return the new price calculated
return this.nextPrice;
}
// main function
public static void main(String[] args){
// get stock name ,symbol and current price
System.out.println("\t--Stock Price Simulation--");
Scanner s=new Scanner(System.in);
System.out.println("Enter Stock Name");
String stockName=s.next();
System.out.println("Enter Stock Symbol");
String stockSymbol=s.next();
System.out.println("Enter Current Stock Price");
float currentStockPrice=s.nextFloat();
Stock stock;
// if user enters NONE ,or NA or 0.0 then
if(stockName.equals("NONE") || stockSymbol.equals("NA") || currentStockPrice==0.0){
stock=new Stock();
}
else{
stock=new Stock(stockName,stockSymbol,currentStockPrice,currentStockPrice);
}
// if Stock Name set to NONE or Stock Symbol set to NA or stock current price set to 0.0
// exit
if(stockName.equals("NONE") || stockSymbol.equals("NA") || currentStockPrice==0.0){
System.out.println("Stock Name set to NONE or Stock Symbol set to NA or stock current price set to 0.0");
System.out.println("Exiting");
}
else{
// loop for 30 count
System.out.println("\t--30 Days Simulation--");
for(int i=1;i<=30;i++){
// get the new price
float price=stock.simulatePrice();
// print all the fields of the stock
System.out.println("--Day-"+i+"--");
System.out.println("Stock Name:"+stock.getName());
System.out.println("Stock Symbol:"+stock.getSymbol());
System.out.println("Stock Current Price:"+stock.getCurrentPrice());
System.out.println("Stock Next Price:"+stock.getNextPrice());
System.out.println("Price Change:"+stock.getPriceChange());
System.out.println("Price Change Percentage:"+stock.getPriceChangePercentage()+"%");
// set stock current price to new price
stock.setCurrentPrice(price);
}
}
}
}
WRITE JAVA PROGRAM Problem Statement You are required to write a stock price simulator, which simulates...
In java netbean8.1 or 8.2 please. The class name is Stock. It has 5 private attributes (name, symbol, numberOfShares, currentPrice and boughtPrice)and one static private attribute (numberOfStocks). All attributes must be initialized (name and symbol to “No name/ symbol yet” and numberOfShares, currentPrice and boughtPrice to 0. Create two constructors, one with no arguments and the other with all the attributes. (However, remember to increase the numberOfStocks in both constructors. Write the necessary mutators and accessors (getters and setters) for...
Write a C++ Program that simulates a basic calculator using functions which performs the operations of Addition, Subtraction, multiplication, and Division. ( make sure you cover the case to avoid division by a zero) Display a menu for list of operations that can be calculated and get the input from user about his choice of calculation. Based on user choice of operation, take the input of number/numbers from user. Assume all input values are of type double. Calculations must be...
Write a C++ Program that simulates a basic calculator using functions which performs the operations of Addition, Subtraction, multiplication, and Division. ( make sure you cover the case to avoid division by a zero) Display a menu for the list of operations that can be calculated and get the input from the user about his choice of calculation. Based on user choice of operation, take the input of number/numbers from user. Assume all input values are of type double. Calculations...
please use c programme Write a program which simulates a calculator using the following specifications. (50 points - 10pts for syntax, 10pts for commenting and 30pts for successful execution) • User input must have the following format - value1 operator value2 • Compute value1 operator value2 • Use switch statement • Operators must be ’+’ ,’-’, ’*’, ’/’ and ’%’ • Division by 0 in C leads to an error. Terminate the program before divison occurs in such cases. •...
Write a program in C++ that simulates a soft drink machine. The program will need several classes: DrinkItem, DrinkMachine and Receipt. For each of the classes you must create the constructors and member functions required below. You can, optionally, add additional private member functions that can be used for doing implementation work within the class. DrinkItem class The DrinkItem class will contains the following private data members: name: Drink name (type of drink – read in from a file). Type...
This is for Java Programming Please use comments Customer and Employee data (15 pts) Problem Description: Write a program that uses inheritance features of object-oriented programming, including method overriding and polymorphism. Console Welcome to the Person Tester application Create customer or employee? (c/e): c Enter first name: Frank Enter last name: Jones Enter email address: frank44@ hot mail. com Customer number: M10293 You entered: Name: Frank Jones Email: frank44@hot mail . com Customer number: M10293 Continue? (y/n): y Create customer...
Written in python using puTTy!! i'm having a lot of trouble with this, will upvote! also here is the address.csv file Name,Phone,Email,Year_of_Birth Elizi Moe,5208534566,[email protected],1978 Ma Ta,4345667345,[email protected],1988 Diana Cheng,5203456789,[email protected],1970 ACTIVITY I Implement in Python the Subscriber class modeled by the UML diagram provided below. Save in a file called MyClasses.py Subscriber name: string yearOfBirth: int phone: string email: string getName() getAge() getPhone() getEmail() Write a test program that does the following: Read the file addresses.csv. For each record, create an object...
In this assignment, you will implement Address and Residence classes. Create a new java project. Part A Implementation details of Address class: Add and implement a class named Address according to specifications in the UML class diagram. Data fields: street, city, province and zipCode. Constructors: A no-arg constructor that creates a default Address. A constructor that creates an address with the specified street, city, state, and zipCode Getters and setters for all the class fields. toString() to print out all...
. Use what you learned from our First Python Program to write a Python program that will carry out the following tasks. Ask user provide the following information: unit price (for example: 2.5) quantity (for example: 4) Use the following formula to calculate the revenue: revenue = unit price x quantity Print the result in the following format on the console: The revenue is $___. (for example: The revenue is $10.0.) . . Use the following formula to calculate the...
( Object array + input) Write a Java program to meet the following requirements: 1. Define a class called Student which contains: 1.1 data fields: a. An integer data field contains student id b. Two String data fields named firstname and lastname c. A String data field contains student’s email address 1.2 methods: a. A no-arg constructor that will create a default student object. b. A constructor that creates a student with the specified student id, firstname, lastname and email_address...