1 / 2100%
/*-------------------------------------------------------------
// AUTHOR: Zachary Zeka
// FILENAME: Assignment03.java
// SPECIFICATION: This program will determine whether to buy, sell, or hold
shares in a stock market.
// FOR: CSE 110 - Assignment 3
// TIME SPENT: 4 hours
//-----------------------------------------------------------*/
//Import the scanner
import java.util.Scanner;
public class Assignment03
{
public static void main(String[] args)
{
//Initialize the scanner
Scanner scan = new Scanner(System.in);
//Declare the required variables
int currentShares = 0; //This is the number of shares of this
stock currently held in the account
int purchasePrice = 0; //(per share) paid for current stock in the
account
int marketPrice = 0; //(per share) of this stock. This is the
current market price for buying or selling this stock
int availableFunds = 0; //the amount the client is willing to spend
on a transaction
int transactionFee = 10; //There is a $10 transaction fee for the
transaction whether we buy or sell
//Prompt for the required inputs
System.out.println("Current Shares:");
currentShares = scan.nextInt();
System.out.println("Purchase Price:");
purchasePrice = scan.nextInt();
System.out.println("Market Price:");
marketPrice = scan.nextInt();
System.out.println("Available Funds:");
availableFunds = scan.nextInt();
//Declare the perShareBuyValue and perShareSellValue int's to
determine whether you should buy or sell
int perShareBuyValue = purchasePrice - marketPrice;
int perShareSellValue = marketPrice - purchasePrice;
//Declare the numberOfSharesToBuy int which shows the possible
number of shares we could buy
int numberOfSharesToBuy = ((availableFunds - transactionFee) /
marketPrice);
//Declare the totalBuyCost
//int totalBuyCost = transactionFee + marketPrice *
numberOfSharesToBuy;
if (perShareBuyValue >= 0)
{
int totalBuyValue = perShareBuyValue * numberOfSharesToBuy;
if (totalBuyValue > 10)
{
System.out.println("Buy "+numberOfSharesToBuy+"
shares");
}
else
{
System.out.println("Hold Shares");
}
}
else
{
if (perShareSellValue >= 0)
{
int totalSellValue = perShareSellValue * currentShares;
if (totalSellValue > 10)
System.out.println("Sell "+currentShares+" Shares");
else
{
System.out.println("Hold Shares");
}
}
else
{
System.out.println("Hold Shares");
}
}
//Close the scanner
scan.close();
}
}
Powered by TCPDF (www.tcpdf.org)
Students also viewed