Tilted Forum Project Discussion Community  

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


 
 
LinkBack Thread Tools
Old 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
threewingedfury is offline  
Old 02-03-2006, 09:45 AM   #2 (permalink)
"Officer, I was in fear for my life"
 
hrdwareguy's Avatar
 
Location: Oklahoma City
I would start by asking your instructor.
__________________
Gun Control is hitting what you aim at

Aim for the TFP, Donate Today
hrdwareguy is offline  
Old 02-03-2006, 11:11 AM   #3 (permalink)
Upright
 
the problem is, im taking the class online, and the instructor doesn't really answer questions
threewingedfury is offline  
Old 02-03-2006, 11:17 AM   #4 (permalink)
aka: freakylongname
 
Chamaeleontidae's Avatar
 
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.
Chamaeleontidae 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 06:30 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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360