Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 10-07-09   #1 (permalink)
4.0 GHz
 
-bl4ck-'s Avatar
 
intel nvidia

Join Date: Dec 2007
Location: Dallas, Texas
Posts: 247

Rep: 4 -bl4ck- Unknown
Unique Rep: 4
Trader Rating: 0
Default Calling all Java/ Comp Sci Guru's

So I have no errors, but when I try to run after building this code, It does nothing? Any reason why? I am using netbeans to write my code, I know this is real basic but its my assignment. This is my code, +reps for help!


package jamesmills;

import javax.swing.JOptionPane;
import java.util.Scanner;


public class jamesmills
{


public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int Choice;
float Num1, Num2;

//numbers
JOptionPane.showInputDialog (null, "Enter your first Number");
Num1=input.nextFloat();
JOptionPane.showInputDialog (null, "Enter your second Number");
Num2=input.nextFloat();
//choice
JOptionPane.showInputDialog (null, "1.Addtion\n2.Subtraction\n.Multiplication\n.Divis ion\n5.Quit");
Choice=input.nextInt();

//decision
while (Choice!=5)
{
switch (Choice)
{
case 1: addNumbers(Num1,Num2);
break;
case 2: subNumbers(Num1,Num2);
break;
case 3: multiNumbers(Num1,Num2);
break;
case 4: divideNumbers(Num1,Num2);
break;
case 5: break;
}//end switch
}//end while


}//end void main

//methods for math
public static float addNumbers(float Num1, float Num2)
{
float Total;
Total=Num1+Num2;
return Total;
}

public static float subNumbers(float Num1, float Num2)
{
float Total;
Total=Num1-Num2;
return Total;
}

public static float multiNumbers(float Num1, float Num2)
{
float Total;
Total=Num1*Num2;
return Total;
}

public static float divideNumbers(float Num1, float Num2)
{
float Total;
Total=Num1/Num2;
return Total;
}

}//end class
__________________
92% of teens have moved on to rap. If you are part of the 8% who still listen to real music, copy and paste this

System: My shizzz
CPU
i7 920 C0
Motherboard
evga X58
Memory
6GB DDR3 1600
Graphics Card
XFX GTX 260
Hard Drive
2x WD 500GB
Power Supply
Antec Quattro 1000W
Case
Rocketfish
CPU cooling
CM V8
OS
7
Monitor
24" Sceptre
-bl4ck- is offline   Reply With Quote
Old 10-07-09   #2 (permalink)
Programmer
 
intel nvidia

Join Date: Jun 2009
Location: Italy
Posts: 231

Rep: 50 pippolo is acknowledged by some
Unique Rep: 46
Trader Rating: 0
Default

The Scanner reads from the standard input (and waits that you write something into the console), but the text entered into the JOptionPane isn't connected to the standard input.
The function
Code:
JOptionPane.showInputDialog (null, "Enter your first Number");
returns the entered text as a String. You have to write a thing like this:

Code:
String result = JOptionPane.showInputDialog (null, "Enter your first Number");
and after:

Code:
int number = Integer.parseInt(result);
or

Code:
Scanner scanner = new Scanner(result);
int number = scanner.nextInt();
__________________
System: My System
CPU
2xQuadCore Intel Xeon E5420
Motherboard
Tyan Tempest i5400XT
Memory
16GB 8xSamsung M395T5750 FBDIMM
Graphics Card
XFX 9800GTX
Hard Drive
16 Internal, 8 external. Mainly Seagate
Sound Card
Sound Blaster X-FI Platinum Fatal1ty Champion
Power Supply
Enermax Galaxy 1000W EGA1000EWL
Case
Chieftec (modified)
CPU cooling
Cooler Master 3U-Attiva S3N-7DWHS-L5-GP
GPU cooling
Standard
OS
Vista Ultimate x64
pippolo is offline   Reply With Quote
Old 10-07-09   #3 (permalink)
PC Gamer
 
Join Date: Oct 2008
Location: Arizona
Posts: 32

Rep: 3 Lumas Unknown
Unique Rep: 3
Hardware Reviews: 2
Trader Rating: 0
Default

And as a couple of syntax things:

Division has an extra space and is not numbered
Multiplication is not numbered

I believe it is also good practice when you declare your variables to set them equal to 0.
Lumas is offline   Reply With Quote
Old 10-07-09   #4 (permalink)
4.0 GHz
 
-bl4ck-'s Avatar
 
intel nvidia

Join Date: Dec 2007
Location: Dallas, Texas
Posts: 247

Rep: 4 -bl4ck- Unknown
Unique Rep: 4
Trader Rating: 0
Default

great got it working thanks
__________________
92% of teens have moved on to rap. If you are part of the 8% who still listen to real music, copy and paste this

System: My shizzz
CPU
i7 920 C0
Motherboard
evga X58
Memory
6GB DDR3 1600
Graphics Card
XFX GTX 260
Hard Drive
2x WD 500GB
Power Supply
Antec Quattro 1000W
Case
Rocketfish
CPU cooling
CM V8
OS
7
Monitor
24" Sceptre
-bl4ck- is offline   Reply With Quote
Old 10-08-09   #5 (permalink)
Non generic awesome title
 
Black Magix's Avatar
 
intel nvidia

Join Date: Mar 2008
Location: I'll let you decide.
Posts: 2,822
Blog Entries: 1

Rep: 256 Black Magix is a proven memberBlack Magix is a proven memberBlack Magix is a proven member
Unique Rep: 193
Folding Team Rank: 293
Team Name: Explosm
Hardware Reviews: 2
Trader Rating: 12
Default

I really wish we could preserve spacing on the forums....that was hard as hell to read >.<
__________________
Quote:
Originally Posted by Threefeet View Post
Yo dawg, we heard you like molding public opinion so we put terrorists into piracy so you can save the world while you make more money...

>SELECT * FROM tblUsers WHERE clue > 0
0 rows returned

System: Eris
CPU
Q9650
Motherboard
Gigabyte UD3P
Memory
8GB Corsair Dominator 1066
Graphics Card
EVGA GTX 295 Co-Op Edition
Hard Drive
2x 1TB 2x 750GB 3x 500GB
Sound Card
Asus Xonar DX
Power Supply
Antec 850w
Case
Silverstone Kublai - Silent Night Mod
CPU cooling
D-tek v2 CPU Block
GPU cooling
Stock
OS
Windows 7 x64 / Windows Vista Ultimate x64
Monitor
Acer 24' Widescreen & Viewsonic 20' Widescreen
Black Magix is online now I fold for Overclock.net Overclocked Account   Reply With Quote
Old 10-08-09   #6 (permalink)
4.0ghz
 
hometoast's Avatar
 
intel nvidia

Join Date: Sep 2007
Location: Pennsylvania
Posts: 2,150
Blog Entries: 3

Rep: 164 hometoast is acknowledged by manyhometoast is acknowledged by many
Unique Rep: 132
Hardware Reviews: 3
Trader Rating: 16
Default

Quote:
Originally Posted by Black Magix View Post
I really wish we could preserve spacing on the forums....that was hard as hell to read >.<
You CAN if you wrap it in [ CODE] blocks

Code:
lsdkjf
            lsdkjf

System: foot warmer
CPU
Q9550
Motherboard
EP45-UD3P
Memory
OCZ 2x2Gb ddr2-1066
Graphics Card
GTX260 700/1509/1000
Hard Drive
WD 320 AAKS
Power Supply
PP&C 610W Silencer
Case
CM Cosmos 1000
CPU cooling
Xig Dark Knight
OS
#7
Monitor
Samsung 204BW
hometoast is online now Overclocked Account   Reply With Quote
Old 10-09-09   #7 (permalink)
AMD Overclocker
 
amd nvidia

Join Date: Apr 2009
Posts: 438

Rep: 19 godsgift2dagame Unknown
Unique Rep: 17
Trader Rating: 0
Default

Hey dude, click "QUOTE" on my post and take everything from [quote] on down and edit your post. That was truly horrendous on the eyes.

Quote:
Originally Posted by -bl4ck- View Post
package jamesmills;

import javax.swing.JOptionPane;
import java.util.Scanner;


public class jamesmills
{


public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int Choice;
float Num1, Num2;

//numbers
JOptionPane.showInputDialog (null, "Enter your first Number");
Num1=input.nextFloat();
JOptionPane.showInputDialog (null, "Enter your second Number");
Num2=input.nextFloat();
//choice
JOptionPane.showInputDialog (null, "1.Addtion\n2.Subtraction\n.Multiplication\n.Divis ion\n5.Quit");
Choice=input.nextInt();

//decision
while (Choice!=5)
{
switch (Choice)
{
case 1: addNumbers(Num1,Num2);
break;
case 2: subNumbers(Num1,Num2);
break;
case 3: multiNumbers(Num1,Num2);
break;
case 4: divideNumbers(Num1,Num2);
break;
case 5: break;
}//end switch
}//end while


}//end void main

//methods for math
public static float addNumbers(float Num1, float Num2)
{
float Total;
Total=Num1+Num2;
return Total;
}

public static float subNumbers(float Num1, float Num2)
{
float Total;
Total=Num1-Num2;
return Total;
}

public static float multiNumbers(float Num1, float Num2)
{
float Total;
Total=Num1*Num2;
return Total;
}

public static float divideNumbers(float Num1, float Num2)
{
float Total;
Total=Num1/Num2;
return Total;
}

}//end class
__________________
System: $775
CPU
Phenom II 720
Motherboard
Gigabyte MA790X-UD4P
Memory
4GB OCZ Reaper DDR2 1150
Hard Drive
250GB Seagate Barracuda 7200.10 x 2
Power Supply
PC Power & Cooling 610W
Case
Antec 300
CPU cooling
XIGMATEK Dark Knight-S1283V
OS
Vista 64-bit
godsgift2dagame is online now   Reply With Quote
Old 10-09-09   #8 (permalink)
With great difficulty
 
rabidgnome229's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Pittsburgh
Posts: 5,210

Rep: 614 rabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famous
Unique Rep: 370
FAQs Submitted: 6
Trader Rating: 5
Default

I think this is what you meant
Code:
package jamesmills;

import javax.swing.JOptionPane;
import java.util.Scanner;


public class jamesmills
{


    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        int Choice;
        float Num1, Num2;

        //numbers
        JOptionPane.showInputDialog (null, "Enter your first Number");
        Num1=input.nextFloat();
        JOptionPane.showInputDialog (null, "Enter your second Number");
        Num2=input.nextFloat();
        //choice
        JOptionPane.showInputDialog (null, "1.Addtion\n2.Subtraction\n.Multiplication\n.Divis ion\n5.Quit");
        Choice=input.nextInt();

        //decision
        while (Choice!=5)
        {
            switch (Choice)
            {
                case 1: addNumbers(Num1,Num2);
                        break;
                case 2: subNumbers(Num1,Num2);
                        break;
                case 3: multiNumbers(Num1,Num2);
                        break;
                case 4: divideNumbers(Num1,Num2);
                        break;
                case 5: break;
            }//end switch
        }//end while


    }//end void main

    //methods for math
    public static float addNumbers(float Num1, float Num2)
    {
        float Total;
        Total=Num1+Num2;
        return Total;
    }

    public static float subNumbers(float Num1, float Num2)
    {
        float Total;
        Total=Num1-Num2;
        return Total;
    }

    public static float multiNumbers(float Num1, float Num2)
    {
        float Total;
        Total=Num1*Num2;
        return Total;
    }

    public static float divideNumbers(float Num1, float Num2)
    {
        float Total;
        Total=Num1/Num2;
        return Total;
    }

}//end class
__________________
System: It goes to eleven
CPU
E6300
Motherboard
DS3
Memory
2GB XMS2 DDR2-800
Graphics Card
EVGA 8600GTS
Hard Drive
1.294 TB
Sound Card
Audigy 2 ZS
Power Supply
Corsair 520HX
Case
Lian-Li v1000B Plus
CPU cooling
TTBT
GPU cooling
Thermalright V2
OS
Arch Linux/XP
Monitor
Samsung 226bw
rabidgnome229 is offline Overclocked Account   Reply With Quote
Reply


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



All times are GMT -5. The time now is 09:39 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.14756 seconds with 8 queries