Tilted Forum Project Discussion Community  

Go Back   Tilted Forum Project Discussion Community > Interests > Tilted Technology


 
 
LinkBack Thread Tools
Old 02-02-2006, 10:05 PM   #1 (permalink)
Upright
 
Starting a java program

I'm just beginning to learn java, and I'm trying to make a simple RPN calculator - Once I declare a few of my instance variables, I get lost of where to start my methods.

These are the guidelines:


You are designing a simple four function, integer based, RPN calculator. The calculator layout is shown below.
Display: 153
7 8 9 +
4 5 6 -
1 2 3 *
0 C /
For this calculator to function it must have methods and instance variables. The instance variables are the pieces of the calculator (buttons and display) as well as the things the calculator knows. You may use JButton as the type of variable to represent a button. You may use JTextArea as the type of variable to represent the display. The calculator must have the items it knows as well. These will be the integers needed for the math. You will have a total of 18 instance variabled in the calculator.
The second half of the design is the method design. For each button that can be pressed you will have one method. The press of the button will trigger the method to run. What happens when each button is pressed can be grouped into two sets:
• Numeric buttons
• Function buttons
A numeric button updates the current value on the display. This means when you press it that two things must occur:
1. Current value being stored must be updated via math
2. The display must be refreshed to show the current value
A function button updates the total value in memory and the current value in memory. It causes the total to be displayed on the display. This means when you press a function three things must occur:
1. The total value must be updated to incorporate the current value. This means if you press add the current value is added to the total. If you press subtract the current value is subtracted from the total value.
2. The current value must be reset to zero
3. The display must be refreshed to show the total value
________________________________________
A Sample
The following operations show a sample of the calculator in action:
Button Pressed Resulting Display Value of current Value of total
1 1 1 0
2 12 12 0
0 120 120 0
+ 120 0 120
1 1 1 120
2 12 12 120
- 108 0 108
C 0 0 0
________________________________________
Assignment

Make a text file which includes pseudo code including the definition of the instance varaibles including the variable type (JButton, JTextArea, or int) and the variable name (must be a valid Java variable name). You must also have all 15 methods. The methods must have valid method names, and must include the math required to update the total and/or current values correctly. You must also state (in english) the update of the display and which value you are showing in the display (total or current) in each method.

My code so far:

/**
* Exercise # 1
* Description: This program will be the basis of designing an RPN calculator, and learning to use methods and instance variables.
* This will not be a fully working program, but is the start of one.
* @author Tiffany
* @version 1.0
*/
public class Calc {
/**
* Instance variable for button number 0
*/
private int num0;

/**
* Instance variable for button number 1
*/
private int num1;

/**
* Instance variable for button number 2
*/
private int num2;

/**
* Instance variable for button number 3
*/
private int num3;

/**
* Instance variable for button number 4
*/
private int num4;

/**
* Instance variable for button number 5
*/
private int num5;

/**
* Instance variable for button number 6
*/
private int num6;

/**
* Instance variable for button number 7
*/
private int num7;

/**
* Instance variable for button number 8
*/
private int num8;

/**
* Instance variable for button number 9
*/
private int num9;

/**
* Constructor to initialize instance variables
*/
public Calc () {
num0=;
num1=;
num2=;
num3=;
num4=;
num5=;
num6=;
num7=;
num8=;
num9=;
}

/**
*


I know this is no where near complete, I just need a little help on it - I'm just learning how to use methods and instance variables, so its a little hard to do this - and this isn't supposed to be a working program, just where I can show that I know how to declare method and instance variables
threewingedfury is offline  
Old 02-02-2006, 10:12 PM   #2 (permalink)
Upright
 
woops sorry i didnt know there was a programming forum.. ill post there instead
threewingedfury is offline  
 

Tags
java, program, starting


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 03:13 AM.

Tilted Forum Project

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62