Project 1 Objects, Methods, and Classes Create a project that will allow the use
ID: 3669688 • Letter: P
Question
Project 1
Objects, Methods, and Classes
Create a project that will allow the user to select one of the Wall Street companies (Dow Jones, NASDAQ, and S&P 500). After the user selects his choice, you allow him to enter number of the shares he would like to buy or to sell. Later on you will print out to him the total number of shares and the total price or cost.
You have to ask the user if he needs to enter another trade or not. If so, then you will repeat the same process until the user doesn’t want to continue. In another way, your project will be dynamic.
Directions:
Create a Package called StockMarket.
Create one called wallStreet, and the other one called Trade that will include the main statement.
Create the following variables for each one of the three companies:
For Dow Jones:
currentDow.
closePriceDow.
openPriceDow.
lowPriceDow.
For NASDAQ:
currentNas.
closePriceNas.
openPriceNas.
lowPriceNas.
For Dow SP:
currentSp.
closePriceSp.
openPriceSp.
lowPriceSp.
* All the values for the variables will be assigned the Trade class. This means that you need to create four Objects (dowObject, NasObject, and apObjbect) to access the wallStreet class. Then, the Trade * class will print out the total number of shares and the total price.
* Create a Method in wallStreet class called “marketplace”, which will call a Method “enterTrade”.
* The method enterTrade will allow the user to select the name of the company (dow, nas, or sp), and the number of shares.
* For each trade of the three companies (dow, nas, and sp) check the (currentPrice is greater than openPrice and closePrice is less than lowPrice) for the trade to be process.
* Submit the print out of the source code and the output result in the class. There is no project submitted by email, where the grade will be reduced by 10-points.
* Use NetBeans for you Java code.
* Start your source code with header information about your project. Missing the header information will reduce your grade by 5-points.
* If there is no result or the output not matches the requirements, then there is no grade.
* Use the samples and the examples in the blackboard as a guide.
* Due date will be on Feb. 19. Late work will be reduced by 10-points. There are no exceptions for any reasons.
Explanation / Answer
double next = 0,
sum = 0;
}
public double openpricedow;
public double closepricedow;
public double currentpricedow;
public double lowpricedow;
public double openpricenas;
public double closepricenas;
public double currentpricenas;
public double lowpricenas;
public double openpricesp;
public double closepricesp;
public double currentpricesp;
public double lowpricesp;
String company, dow, nas, sp;
int NumberofShares = 0;
public void Trade()
{
System.out.println("Welcome to the Stock Market");
System.out.println("Please enter your stock company");
}
public double findPrice(){
findPrice();
company = keyboard.next();
Switch (company){
case "dow":
System.out.println("Please enter your number of shares");
//Scanner keyboard = new Scanner (System.in);//
openpricedow = 11.50;
closepricedow = 18;
lowpricedow = 14.50;
currentpricedow = 12.50;
boolean areMore = true;
while (areMore = true) {
next = keyboard.nextInt();
if (next < 0) {
areMore = false;
} else {
sum = Numberofshares + next;
}
}
System.out.println(" You have bought " + sum + " shares at $ " + currentpricedow + " and your total is $ " + (sum * currentpricedow));
// if (Shares > 1000) {
// double returnedShares = (Shares * currentpricedow);
// System.out.println("You have bought " + Shares + " shares at $" + currentpricesp + " and your total is $" + returnedShares);
if (Shares < 1000) {
System.out.println("Your number of shares are insufficient");
}
break;
case "sp":
System.out.println("Please enter your number of shares");
//Scanner keyboard = new Scanner (System.in);//
//Shares = keyboard.nextInt();
openpricesp = 13.50;
closepricesp = 16;
lowpricesp = 15.50;
currentpricesp = 8;
Shares = 0;
next = keyboard.nextDouble();
while (next > 0) {
sum = +sum + next;
Shares++;
next = keyboard.nextDouble();
}
if (next < 0) {
System.out.println(" You have bought " + sum + " shares at $ " + currentpricesp + " and your total is $ " + (sum * currentpricesp));
} // if (Shares > 1000) {
// double returnedShares = (Shares * currentpricesp);
// System.out.println("You have bought " + Shares + " shares at $" + currentpricesp + " and your total is $" + returnedShares);
else if (Shares < 1000) {
System.out.println("Your number of shares are insufficient");
}
break;
case "nas":
System.out.println("Please enter your number of shares");
//Scanner keyboard = new Scanner (System.in);//
Shares = keyboard.nextInt();
openpricenas = 12.50;
closepricenas = 14;
lowpricenas = 17.50;
currentpricenas = 9.80;
if (closepricenas < lowpricenas) {
System.out.println("Your cannot buy shares at this moment");
} else {
Shares = 0;
next = keyboard.nextDouble();
while (next > 0) {
sum = sum + next;
Shares++;
next = keyboard.nextDouble();
}
if (next < 0) {
System.out.println(" You have bought " + sum + " shares at $ " + currentpricenas + " and your total is $ " + (sum * currentpricenas));
break;
}
}
}
// if (Shares > 1000) {
// double returnedShares = (Shares * currentpricenas);
// System.out.println("You have bought " + Shares + " shares at $" + currentpricenas + " and your total is $" + returnedShares);}
else if (Shares < 1000)
System.out.println("Your number of shares are insufficient");
return findPrice;}
}
public class Price {
public static void main (String [] args)
{Trade dow = new Trade(); //<=====buy is the object. stock is the class.
dow.openpricedow = 11.50;
dow.closepricedow = 18;
dow.currentpricedow = 14.50;
dow.lowpricedow = 12.50;
dow.Trade();
double result = dow.findPrice();
System.out.println("The higher Stock is " + result);
}
{Trade nas = new Trade(); //<=====buy is the object. stock is the class.
nas.openpricenas = 11.50;
nas.closepricenas = 18;
nas.currentpricenas = 14.50;
nas.lowpricenas = 12.50;
nas.Trade();
double result = nas.findPrice();
System.out.println("The higher Stock is " + result);
}
{Trade sp = new Trade(); //<=====buy is the object. stock is the class.
sp.openpricesp = 13.50;
sp.closepricesp = 16;
sp.currentpricesp = 15.50;
sp.lowpricesp = 8;
sp.Trade();
double result = sp.findPrice();
System.out.println("The higher Stock is " + result);
// }
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.