Results 1 to 3 of 3
  1. #1
    hiralarious is offline Member
    Join Date
    Sep 2011
    Posts
    2
    Rep Power
    0

    Question Identifying Objects/Variables

    Oh hello!(:
    Okay so I feel pretty bad about making my first post on this site about one pleading for help... but alas, I need help.
    On the bright side, it's basically pretty simple questions.

    I actually don't know how to phrase this so forgive me! I really am just that new at this stuff :[

    Uhm okay, so what I need to do is identify objects, local variables, instance variables, class variables(I don't think I have any of these though), methods, and constants in this code thing. Which I wrote! Yippee!
    So basically, I have the textbook definitions and whatnot but it's really not helping.
    I'm not sure if what I'm really calling an object or a variable is really that, you know?

    So anyway, here's my code:
    Java Code:
    import javax.swing.*;
    
    
    public class HwkAssignment2Appl extends JFrame
    {
    
    
    	/**
    	 * @param args
    	 */
    	
    	//create object of JPanel
    	JPanel mainPanel = new JPanel();
    	
    	//create 12 label objects for prompts that let user input three numbers. These three numbers are then added together and then multiplied together to get the tax that would be payed for these objects. The total price of purchase with tax is also displayed. The programmer name is also shown.
    	JLabel firstNumberPromptLabel = new JLabel("First Number:");
    	JLabel firstNumberLabel = new JLabel("          ");
    	JLabel secondNumberPromptLabel = new JLabel("Second Number:");
    	JLabel secondNumberLabel = new JLabel("          ");
    	JLabel thirdNumberPromptLabel = new JLabel("Third Number:");
    	JLabel thirdNumberLabel = new JLabel("         ");
    	JLabel resultPromptLabel = new JLabel("Result Number:");
    	JLabel resultLabel = new JLabel("          ");
    	JLabel nameLabel = new JLabel("Programmer Name: Hira");
    	JLabel taxNumberLabel = new JLabel("Tax paid on items at 9.25% tax rate:");
    	JLabel taxLabel = new JLabel("            ");
    	JLabel additionPromptLabel = new JLabel("Subtotal:");
    	JLabel additionLabel = new JLabel("        ");
    	
    	//set the tax rate to .0925
    	final float TAX_RATE = .0925f;
    
    						
    	
    	public static void main(String[] args)
    	{
    		// create an object of the class and set the close of the X button
    		HwkAssignment2Appl myApp = new HwkAssignment2Appl();
    		myApp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		
    
    	}
    	
    	
    	public HwkAssignment2Appl()
    	{
    		//add label objects to the panel
    		mainPanel.add(firstNumberPromptLabel);
    		mainPanel.add(firstNumberLabel);
    		mainPanel.add(secondNumberPromptLabel);
    		mainPanel.add(secondNumberLabel);
    		mainPanel.add(thirdNumberPromptLabel);
    		mainPanel.add(thirdNumberLabel);
    		mainPanel.add(resultPromptLabel);
    		mainPanel.add(resultLabel);
    		mainPanel.add(nameLabel);
    		mainPanel.add(taxNumberLabel);
    		mainPanel.add(taxLabel);
    		mainPanel.add(additionPromptLabel);
    		mainPanel.add(additionLabel);
    		
    		//Create 3 String objects to store in the user entry
    		String num1String, num2String, num3String;
    			
    	
    		//create 4 floats the user entries and result
    		float num1Float, num2Float, num3Float, resultFloat;
    		
    		//create 2 floats for the sum of three numbers inputed by user(additionFloat) and one for the sum of additionFloat and tax(taxFloat) 
    		float additionFloat, taxFloat;
    		
    		//JOption dialog returns the user entry
    		num1String = JOptionPane.showInputDialog(null, "Please enter the number");
    		num2String = JOptionPane.showInputDialog(null, "Please enter the number");
    		num3String = JOptionPane.showInputDialog(null, "Please enter the number");
    		
    		
    		//Convert from String object to float
    		num1Float = Float.parseFloat(num1String);
    		num2Float = Float.parseFloat(num2String);
    		num3Float = Float.parseFloat(num3String);
    		
    		//add the numbers
    		additionFloat = num1Float + num2Float + num3Float;
    
    		//multiply additionFloat by TAX_RATE in order to get the tax of items
    		taxFloat = additionFloat * TAX_RATE;
    		
    		//add taxFloat and additionFloat to get the result
    		resultFloat = additionFloat + taxFloat;		
    				
    		//display the variables in the label objects
    		firstNumberLabel.setText(num1String);
    		secondNumberLabel.setText(num2String);
    		thirdNumberLabel.setText(num3String);
    		resultLabel.setText("" + resultFloat);
    		nameLabel.setText("Programmer: Hira");
    		taxLabel.setText("" + taxFloat);
    		additionLabel.setText("" + additionFloat);
    
    		//add the panel object to the JFrame object
    		add(mainPanel);
    		
    		//set the size and visibility of the JFrame
    		setSize(300,300);
    		setVisible(true);
    		
    		
    		
    	}
    
    }

    Please help! ):
    I would love you to pieces if you did.
    (Please don't think about that statement for more than two seconds. You might realize that it doesn't make sense.. which I sadly do not a vast majority of the time).

    Gracias in advance though. Just for even looking at this (wonderful, hilarious, exciting) thread.

    Excuse me for a moment while I use this adorable emotican. Heheh.


    AIGHT.
    SO YEAH.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Identifying Objects/Variables

    Quote Originally Posted by hiralarious View Post
    ...so what I need to do is identify objects, local variables, instance variables, class variables(I don't think I have any of these though), methods, and constants in this code thing. ...

    So basically, I have the textbook definitions and whatnot but it's really not helping.
    I'm not sure if what I'm really calling an object or a variable is really that, you know?
    Since this is your project, you absolutely need to show us your attempt to solve this yourself first. If you don't do this, you'd be cheating yourself.

  3. #3
    hiralarious is offline Member
    Join Date
    Sep 2011
    Posts
    2
    Rep Power
    0

    Default Re: Identifying Objects/Variables

    Mmks, so this is what I have so far then:
    https://docs.google.com/document/d/1.../edit?hl=en_US


    edit:
    oh, almost forgot to ask -
    would all the addition stuff and whatnot count as a method or no? I was leaning towards no though, but yeah.

Similar Threads

  1. Identifying sender on keypress event
    By tomtraxler in forum NetBeans
    Replies: 1
    Last Post: 01-08-2011, 05:49 PM
  2. Help me ! identifying the mistake
    By o0oNorao0o in forum New To Java
    Replies: 6
    Last Post: 11-06-2010, 11:03 PM
  3. Most of my trouble is identifying a pattern
    By ElkNinja in forum New To Java
    Replies: 4
    Last Post: 10-10-2010, 07:17 AM
  4. help with identifying components of a gui
    By jaytee in forum New To Java
    Replies: 1
    Last Post: 03-08-2010, 03:28 AM
  5. Replies: 1
    Last Post: 01-03-2010, 10:48 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
  •