02-02-2006, 10:13 PM | #1 (permalink) |
Upright
|
[java] starting out a program - new at this
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 |
02-03-2006, 11:17 AM | #4 (permalink) |
aka: freakylongname
Location: South of the Great While North
|
I tend to think in terms of objects and action, and I tend to be visual in my thinking...
I usually start by drawing on paper what I want the finished result will look like on screen, and how you interact with it... What does each object type need to do... What data needs to be available to everything... for the function keys, what will they get for input, and what do they need to modify...
__________________
"Reality is just a crutch for people who can't cope with drugs." Robin Williams. |
Tags |
java, program, starting |
|
|