Zelaron Gaming Forum  
Stats Arcade Portal Forum FAQ Community Calendar Today's Posts Search
Go Back   Zelaron Gaming Forum > The Zelaron Nexus > The Lounge

 
 
Thread Tools Display Modes

 
My java class is killing me!!!!
Reply
Posted 2004-03-28, 06:21 PM
Anyone here knows java!!!!!!!....... I need help bad.. I am getting a C probally worst... at that class.
Old
Profile PM WWW Search
Ganga is neither ape nor machine; has so far settled for the in-betweenGanga is neither ape nor machine; has so far settled for the in-between
 
 
Ganga
 



 
Reply
Posted 2004-03-28, 06:26 PM in reply to Ganga's post "My java class is killing me!!!!"
My condolences, Java's a pretty confusing language to learn, at least from what I've looked at. At least you're learning (or trying to learn) something you can use. My computer class is fricking boring and what we're learning probably won't serve me any use in the future. Also my grade isn't so good in it for this quarter...
Old
Profile PM WWW Search
Neko is neither ape nor machine; has so far settled for the in-betweenNeko is neither ape nor machine; has so far settled for the in-between
 
 
Neko
 



 
Reply
Posted 2004-03-28, 06:39 PM in reply to Neko's post starting "My condolences, Java's a pretty..."
Actually Java's pretty easy. I'm not a Java guru or anything, but I could try to help you out if need be. What are you having trouble with Ganga?
Old
Profile PM WWW Search
Demosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to be
 
Demosthenes
 



 
Reply
Posted 2004-03-29, 06:59 PM in reply to Demosthenes's post starting "Actually Java's pretty easy. I'm not a..."
it's not hard, but we just started to learn, and we are having this crazy ass homework, we have to write a program for a caculator is our current project... after I spend 10 hour in TA office I think I got it, when my new project come up...which will be right after this one due- tomorow, I ask you question.
Old
Profile PM WWW Search
Ganga is neither ape nor machine; has so far settled for the in-betweenGanga is neither ape nor machine; has so far settled for the in-between
 
 
Ganga
 



 
Reply
Posted 2004-03-29, 07:04 PM in reply to Ganga's post starting "it's not hard, but we just started to..."
No problem. Feel free to ask me whatever you feel like. Another thing, check out www.planetsourcecode.com. Whatever your homework is, I'm sure they'll have something similar to it there, so you can use that as reference if the need arises.
Old
Profile PM WWW Search
Demosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to be
 
Demosthenes
 



 
Reply
Posted 2004-03-30, 01:06 AM in reply to Demosthenes's post starting "No problem. Feel free to ask me..."
Wow, java can't be THAT hard to write a calc, ever used any other programming langs?
Old
Profile PM WWW Search
`Insolence` is neither ape nor machine; has so far settled for the in-between`Insolence` is neither ape nor machine; has so far settled for the in-between
 
 
`Insolence`
 



 
Reply
Posted 2004-03-30, 08:21 AM in reply to `Insolence`'s post starting "Wow, java can't be THAT hard to write a..."
no it's suppose to be first programming class.
Old
Profile PM WWW Search
Ganga is neither ape nor machine; has so far settled for the in-betweenGanga is neither ape nor machine; has so far settled for the in-between
 
 
Ganga
 



 
Reply
Posted 2004-03-30, 08:28 AM in reply to Ganga's post starting "no it's suppose to be first programming..."
public class Calculator implements CalculatorMVC {
private CalculatorFrame frame;
private String display; //Contents which will be display
private boolean wasLastkeyOperator=true; //show was last key a operator
private int firstOperand; //first operation
private char preOp; //Previews operator

static public void main(String[] args) {
Calculator calc = new Calculator();
CalculatorFrame frame = new CalculatorFrame("Calc");
frame.setCalculatorMVC(calc);
}

public Calculator() {
display = "0"; //int display content
preOp = '='; //int previes operator
}

public String getDisplayString() {

return display; // return content
}

public void keyClicked(char key){
if (key == 'C'){
display = "0";
firstOperand = 0;
wasLastkeyOperator = false;
}

// If it's a operator stop, else continue
//Performs the indicated mathematical operation according to whether a sequence of

if (isNumber(key)) {
if (wasLastkeyOperator){
display = ""+key;
wasLastkeyOperator = false;
}else {
display +=key;
}
}else
if (wasLastkeyOperator){
preOp = key;
}
//Calculation
else {
if (preOp=='+'){
firstOperand =firstOperand + Integer.parseInt (display);
display = Integer.toString (firstOperand);
}
if (preOp =='-') {
firstOperand =firstOperand - Integer.parseInt (display);
display = Integer.toString(firstOperand);
}
if (preOp == '*') {
firstOperand =firstOperand * Integer.parseInt (display);
display = Integer.toString(firstOperand);
}
if (preOp == '/') {
if (Integer.parseInt(display)==0){
display = "Divide by zero";
}
else{
firstOperand =firstOperand / Integer.parseInt (display);
display = Integer.toString (firstOperand);
}
}
if (preOp == '=') {
firstOperand = Integer.parseInt(display);
}
preOp =key;
wasLastkeyOperator = true;
}
}
//see if the key is a number or a operator
public boolean isNumber(char key){
if (key >= '0' && key <='9'){
return true;
}
else {
return false;
}
}
}






That's my code for the simple calculator, but my problem is everytime I click clear (C) the after calculation always wrong, it will ingnore my first number I input then it will be 0+ my second number or 0- second number or 0 * or 0 /,
like 9+9 =9, 9-9 =-9, 9*9=0, 9/9=0 where all the first number input is 0.
so I am thinking there something wrong with my codes around here:

if (key == 'C'){
display = "0";
firstOperand = 0;
wasLastkeyOperator = false;
}








edit: Nvm I just need to add a else after it. got it, thx anyway MJ.

Last edited by Ganga; 2004-03-30 at 08:50 AM.
Old
Profile PM WWW Search
Ganga is neither ape nor machine; has so far settled for the in-betweenGanga is neither ape nor machine; has so far settled for the in-between
 
 
Ganga
 
 

Bookmarks

« Previous Thread | Next Thread »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules [Forum 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
Forum Jump


All times are GMT -6. The time now is 05:17 AM.
'Synthesis 2' vBulletin 3.x styles and 'x79' derivative
by WetWired the Unbound and Chruser
Copyright ©2002-2008 zelaron.com
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
This site is best seen with your eyes open.