Results 1 to 7 of 7
  1. #1
    Avey is offline Member
    Join Date
    Oct 2012
    Posts
    10
    Rep Power
    0

    Post 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.)


    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
    	}
    
    }
    These next two are both classes i will be using...

    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;
    	}
    }

  2. #2
    Avey is offline Member
    Join Date
    Oct 2012
    Posts
    10
    Rep Power
    0

    Default 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

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,240
    Rep Power
    19

    Default Re: Stock Program, exclude

    Um, the question is about a console application, not a GUI.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Stock Program, exclude

    How does one create a menu in which you'd select an option or exit the application?
    Sorry, to me, menu is a GUI component, like JMenu/JMenuBar. Sorry if I was off-base there!

  6. #6
    bananajoe is offline Member
    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Default 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!

  7. #7
    Avey is offline Member
    Join Date
    Oct 2012
    Posts
    10
    Rep Power
    0

    Default 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

  1. What to do... Simple Stock-Broker program
    By Avey in forum New To Java
    Replies: 3
    Last Post: 11-01-2012, 05:19 AM
  2. Exclude character
    By ZeCute in forum New To Java
    Replies: 2
    Last Post: 05-23-2011, 08:19 PM
  3. Need a Main for a Stock Managing program !!
    By Sary in forum New To Java
    Replies: 3
    Last Post: 05-30-2010, 07:57 PM
  4. Stock exchange program
    By askinne2 in forum New To Java
    Replies: 2
    Last Post: 05-02-2010, 11:25 PM
  5. Replies: 2
    Last Post: 04-17-2008, 05:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •