Results 1 to 7 of 7
Thread: Stock Program, exclude
- 11-17-2012, 04:38 AM #1
Member
- Join Date
- Oct 2012
- Posts
- 10
- Rep Power
- 0
Stock Program, exclude
Hey all, I'm writing a program that will eventually be able to store information about stocks and individual customers that will be able to buy and sell the stock.
How does one create a menu in which you'd select an option or exit the application?
Here's my code... (may or may not be necessary to see, but what the hell.)
These next two are both classes i will be using...Java Code:public class broker { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Stock Stock1 = new Stock(); // this is a stock in the market (not with a customer) Stock1.setname("STK1"); Stock1.setprice(8); Stock1.setvolume(10000); // make other stocks as given System.out.println(Stock1.toString()); // output stock1 info Customer customer1 = new Customer("C1", 100000); // creating a customer with a name C1 and balance 100000 System.out.println(customer1.toString());// output all customer1 info // create other customers // now do the trading } }
Java Code:public class Stock { private String sname; private double sprice; private int svolume; public Stock()// constructor { sprice = 0; svolume = 0; } public void setprice(double p) { sprice = p; } public void setvolume(int v) { svolume = v; } public void setname(String s) { sname = s; } public String toString() { String out = ""; // add to out return out; } }
And.....
Java Code:public class Customer { private String name; private double balance; Stock s1, s2, s3, s4; // portfolio public Customer(String n, double b) { name = n; balance = b; s1 = new Stock(); s2 = new Stock(); s3 = new Stock(); s4 = new Stock(); s1.setname("STK1"); s2.setname("STK2"); s3.setname("STK3"); s4.setname("STK4"); } public String toString() { String output = ""; // add to output - get s1.toString() on this for stock info return output; } }
- 11-18-2012, 12:33 AM #2
Member
- Join Date
- Oct 2012
- Posts
- 10
- Rep Power
- 0
Re: Stock Program, exclude
The menu only needs three options the user can select, one will buy stock, one will sell, and one will terminate the application. I simply don't understand how to create the menu, though I can deal with coding the actions the menu options actually execute.
Thanks for any help
- 11-18-2012, 01:31 PM #3
Re: Stock Program, exclude
- 11-18-2012, 04:05 PM #4
- 11-18-2012, 10:11 PM #5
Re: Stock Program, exclude
Sorry, to me, menu is a GUI component, like JMenu/JMenuBar. Sorry if I was off-base there!How does one create a menu in which you'd select an option or exit the application?
- 11-18-2012, 10:49 PM #6
Member
- Join Date
- Nov 2012
- Posts
- 1
- Rep Power
- 0
Re: Stock Program, exclude
A menu can also be a console program which offers to choice some entries with a number example
1 New stock
2 List stocks
3 Delete stock
4 Exit
To be sure the op should tell us if he wants a console choice or a JMenu/JMenuBar!
- 11-18-2012, 11:26 PM #7
Member
- Join Date
- Oct 2012
- Posts
- 10
- Rep Power
- 0
Re: Stock Program, exclude
Hey again guys, thanks for the responses. I'm just using JOptionPane.showOptionDialog to show the choices and using an array for my choices. I simply am not sure how to associate the SuccessfulBuy/Sell methods only affect which stock they choose. Here's a revamped skeleton of my program.
Java Code:import javax.swing.JFrame; import javax.swing.JOptionPane; public class Customer { private String name; private double balance; double stockPrice; Stock s1, s2, s3, s4; // portfolio String[] anArray = { "STK1", "STK2", "STK3", "STK4" }; public Customer(String n, double b) { name = n; balance = b; s1 = new Stock(); s2 = new Stock(); s3 = new Stock(); s4 = new Stock(); s1.setname("STK1"); s2.setname("STK2"); s3.setname("STK3"); s4.setname("STK4"); } public double getBalance() { return balance; } public double SuccessfulBuy(String stockName, int stockBoughtAmt, double stockBoughtPrice) { int buyArray = JOptionPane.showOptionDialog(null, "Which Stock would you like to buy?", "Stock Broker", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, anArray, anArray[3]); if(buyArray == 0) //STK1 { } if(buyArray == 1) //STK2 { } if(buyArray == 2) //STK3 { } if(buyArray == 3) //STK4 { } return balance = balance - (stockBoughtAmt*stockBoughtPrice); } public double SuccessfulSell(String stockName, int stockSoldAmt, double stockSoldPrice) { int sellArray = JOptionPane.showOptionDialog(null, "Which Stock would you like to buy?", "Stock Broker", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, anArray, anArray[3]); if(sellArray == 0) //STK1 { } if(sellArray == 1) //STK2 { } if(sellArray == 2) //STK3 { } if(sellArray == 3) //STK4 { } return balance = balance + (stockSoldAmt*stockSoldPrice); } public String toString() { String output = "Valued customer " + name + " owns " + s1 + " "; // add to output - get s1.toString() on this for stock info return output; } }Java Code:public class Stock { private String sname; private double sprice; private int svolume; public Stock()// constructor { sprice = 0; svolume = 0; } public void setprice(double p) { sprice = p; } public void setvolume(int v) { svolume = v; } public void setname(String s) { sname = s; } public String toString() { String out = " " + sname + " is priced at $" + sprice + " per share and it contains " + svolume + " shares."; // add to out return out; } }
And the driver...
Java Code:import javax.swing.JFrame; import javax.swing.JOptionPane; public class broker { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Stock Stock1 = new Stock(); // this is a stock in the market (not with a customer) Stock1.setname("STK1"); Stock1.setprice(8); Stock1.setvolume(10000); Stock Stock2 = new Stock(); // this is a stock in the market (not with a customer) Stock2.setname("STK2"); Stock2.setprice(5); Stock2.setvolume(20000); Stock Stock3 = new Stock(); // this is a stock in the market (not with a customer) Stock3.setname("STK3"); Stock3.setprice(9); Stock3.setvolume(10000); Stock Stock4 = new Stock(); // this is a stock in the market (not with a customer) Stock4.setname("STK4"); Stock4.setprice(10); Stock4.setvolume(30000); System.out.println(Stock1.toString()); System.out.println(Stock2.toString()); System.out.println(Stock3.toString()); System.out.println(Stock4.toString()); // output stock info Customer customer1 = new Customer("C1", 100000.00); System.out.println(customer1.toString()); Customer customer2 = new Customer("C2", 25000.00); System.out.println(customer2.toString()); Customer customer3 = new Customer("C3", 50000.00); System.out.println(customer3.toString()); //Option window here... Object[] options = { "C1", "C2", "C3", "Exit" }; JFrame f = new JFrame(); f.setSize(250,250); f.setLocation(300, 200); f.setVisible(false); int x = JOptionPane.showOptionDialog(f, "Which customer are you?", "Stock Broker", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[3]); if(x == 0) //C1 { } if(x == 1) //C2 { } if(x == 2) //C3 { } if(x == 3) //exit application { } } }
Similar Threads
-
What to do... Simple Stock-Broker program
By Avey in forum New To JavaReplies: 3Last Post: 11-01-2012, 05:19 AM -
Exclude character
By ZeCute in forum New To JavaReplies: 2Last Post: 05-23-2011, 08:19 PM -
Need a Main for a Stock Managing program !!
By Sary in forum New To JavaReplies: 3Last Post: 05-30-2010, 07:57 PM -
Stock exchange program
By askinne2 in forum New To JavaReplies: 2Last Post: 05-02-2010, 11:25 PM -
Java program that transfers stock prices to MySQL database
By naipulb in forum New To JavaReplies: 2Last Post: 04-17-2008, 05:02 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks