Previous Thread
Next Thread
Print Thread
Rate Thread
Joined: Nov 2002
Posts: 1,146
Likes: 1
Ice Offline OP
UGN News Staff
OP Offline
UGN News Staff
Joined: Nov 2002
Posts: 1,146
Likes: 1
Well, I just started learing Java couple days ago, this is the second program i made.. the first one is really crapy, just fooling around with some basic stuff.

So i decided to use a IDE and started making this program. Its for school and it you made it in the "Consol" but i started fooling around with it and made it a little better. If ur wondering why the seond program goes to the console, gets the Grade, then goes back to Messages, its because Java cant use the variable String in switch statements, and i read some tutorials on connverting the string to a hash (Just got confused). So i just used this way lol. If the Comments dont seem correct, dont Flame smirk i am new to this language. Heres my Code:

Code
import javax.swing.JOptionPane; // Import the Class for the JOptionPane
import java.lang.String; // Import the Class for the String variable

/*
Name: Ice
Date: September 21, 2004
Exercise: Assignment #2
*/

public class SecondAssignment {
    public static void main(String[] Args) {

           int theChoice; // Declares all the Variables Needed
           int userAge;
           char theGrade;
		
		//Prompt the user to Pick the Assignment they wanna see and store it in userChoice

           String userChoice = JOptionPane.showInputDialog(null, "Assignment #2" + "\nPlease Pick the Assignment you would like to see: "
          + "\n(1) - The Age Program" + "\n(2) - The Switch Program", "Assigment #2", JOptionPane.INFORMATION_MESSAGE);

           	//Convert the String to a Integer and store it in theChoice so a Switch statment can be used
		
		theChoice = Integer.parseInt(userChoice);
           
		switch (theChoice) {
           case 1: // First Case

		//Asks the user How old they are and stores it in firstChoice

               String firstChoice = JOptionPane.showInputDialog(null, "Please Enter How Old you Are:", "Assignment#2", JOptionPane.INFORMATION_MESSAGE);
               userAge = Integer.parseInt(firstChoice);

			// IF/ELSEIF statment to check that message to print out to the user
               		
                        if (userAge <= 1)
			JOptionPane.showMessageDialog(null, "Infant", "Assignment#2", JOptionPane.INFORMATION_MESSAGE);
		else if (userAge == 2)
			JOptionPane.showMessageDialog(null, "Toddlert", "Assignment#2", JOptionPane.INFORMATION_MESSAGE);
		else if (userAge >= 3 && userAge <= 5)
			JOptionPane.showMessageDialog(null, "Preschool", "Assignment#2", JOptionPane.INFORMATION_MESSAGE);
		else if (userAge >= 6 && userAge <= 10)
			JOptionPane.showMessageDialog(null, "Child", "Assignment#2", JOptionPane.INFORMATION_MESSAGE);
		else if (userAge >= 11 && userAge <= 13)
			JOptionPane.showMessageDialog(null, "Preteen", "Assignment#2", JOptionPane.INFORMATION_MESSAGE);
		else if (userAge >= 14 && userAge <= 18)
			JOptionPane.showMessageDialog(null, "Teenager", "Assignment#2", JOptionPane.INFORMATION_MESSAGE);
		else if (userAge >= 19 && userAge <= 26)
			JOptionPane.showMessageDialog(null, "Young Adult", "Assignment#2", JOptionPane.INFORMATION_MESSAGE);
		else if (userAge >= 27 && userAge <= 45)
			JOptionPane.showMessageDialog(null, "Adult", "Assignment#2", JOptionPane.INFORMATION_MESSAGE);
		else if (userAge >= 40 && userAge <= 60)
			JOptionPane.showMessageDialog(null, "Older Adult", "Assignment#2", JOptionPane.INFORMATION_MESSAGE);
		else if (userAge >= 66 && userAge <= 100)
			JOptionPane.showMessageDialog(null, "Senior", "Assignment#2", JOptionPane.INFORMATION_MESSAGE);
		else
			JOptionPane.showMessageDialog(null, "Wise Old Sage", "Assignment#2", JOptionPane.INFORMATION_MESSAGE);
                System.exit(0);
		break;

            case 2: // Second Case

		// Ask the user for there Grade and store it inside theGrade char Variable

            System.out.print("Please Enter your Grade: ");
            theGrade = in.getChar();

		//Does the Switch Statement to see witch Message to print from the user		

            switch (theGrade) {
                case 'A': JOptionPane.showMessageDialog(null, "Excellent", "Assignment#2", JOptionPane.INFORMATION_MESSAGE);
                break;
                case 'B': JOptionPane.showMessageDialog(null, "Good", "Assignment#2", JOptionPane.INFORMATION_MESSAGE);
                break;
                case 'C': JOptionPane.showMessageDialog(null, "Average", "Assignment#2", JOptionPane.INFORMATION_MESSAGE);
                break;
                case 'D': JOptionPane.showMessageDialog(null, "Poor", "Assignment#2", JOptionPane.INFORMATION_MESSAGE);
                break;
                case 'F': JOptionPane.showMessageDialog(null, "Unsatifactory", "Assignment#2", JOptionPane.INFORMATION_MESSAGE);
                break;
                default:
                    JOptionPane.showMessageDialog(null, "Invalid Grade Assignment", "Assignment#2", JOptionPane.WARNING_MESSAGE);
                    break; }
                System.exit(0); // End the Program with nothing being stored into memory (Realese all Variables)
         }
     }
} 
Tell me what u guys think, and what i can do to improve :]


Good artists copy, great artists
steal.

-Picasso
Joined: Dec 2002
Posts: 3,255
Likes: 3
UGN Elite
Offline
UGN Elite
Joined: Dec 2002
Posts: 3,255
Likes: 3
You need pergesu... Looks good to me, but I know bare bones. I mean bare as they get bones

Joined: Nov 2002
Posts: 1,146
Likes: 1
Ice Offline OP
UGN News Staff
OP Offline
UGN News Staff
Joined: Nov 2002
Posts: 1,146
Likes: 1
i think Java is a weak Language thou smirk
Its pretty sweet, but very weak at times.


Good artists copy, great artists
steal.

-Picasso
Joined: Dec 2002
Posts: 3,255
Likes: 3
UGN Elite
Offline
UGN Elite
Joined: Dec 2002
Posts: 3,255
Likes: 3
However JSP pays big bucks. What I have found,

PHP - No major company wants to support it or never heard of it.

Perl - Never was intended to be a web language and it far to slow and complicated compared to what is out there.

ASP - slightly outdated

ASP.net - Jobs abound, get certed and SQL Certed and make some bank

JSP - Jobs abound, Get good with JDBC connections, dynamic content and make bank.

C# - See ASP.net

There are more but they fall under PHP's situation.

Python -
Delphi -
on and on and on

Joined: Nov 2002
Posts: 1,146
Likes: 1
Ice Offline OP
UGN News Staff
OP Offline
UGN News Staff
Joined: Nov 2002
Posts: 1,146
Likes: 1
I think C++ is pretty good. Some good jobs out there if your good with C++.


Good artists copy, great artists
steal.

-Picasso
Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
'eh companies will learn of PHP; i'd definately learn it for now, it's a [censored] powerful and nice language smile


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
Joined: Nov 2002
Posts: 1,146
Likes: 1
Ice Offline OP
UGN News Staff
OP Offline
UGN News Staff
Joined: Nov 2002
Posts: 1,146
Likes: 1
Agreed :] PHP is pretty sweet especially when combined with MySQL

Anyways, I've been working with Java, we learning Constructors and Objects :]

Heres a simple program if ur Intrested.

The Class:

Code
class Circle {
    private double r;
 
    public Circle() {
        r = 1.0;
    }
    
    public Circle(double radius) {
        r = radius;
    }
    
    public double getr() {
        return r;
    }
    
    public void setr(double theNewRadius) {
        r = theNewRadius;
    }
   
    public double theArea() {
        return r *= 3.14;
    }
}
And the Program that uses the class:

Code
public class theProgram {
    public static void main(String[] args) {
        
        // Using the Defualt Constructer
        Circle FirstCircle = new Circle();
        System.out.println("(1)The Radius is: " + FirstCircle.getr());
        System.out.println("(1)The Area is: " + FirstCircle.theArea());
        
        // Using the Second Constructor (Assignment)
        Circle SecondCircle = new Circle(4.1);
        System.out.println("(2)Radius is: " + SecondCircle.getr());
        System.out.println("(2)The Area is: " + SecondCircle.theArea());
        
        // Using the setr to assign the raduis to the circle
        Circle ThirdCircle = new Circle();
        ThirdCircle.setr(8.0);
        System.out.println("(3)Radius is: " + ThirdCircle.getr());
        System.out.println("(3)The Area is:" + ThirdCircle.theArea());
    }
}
Simple, but hey, its a learning process.


Good artists copy, great artists
steal.

-Picasso
Joined: Jun 2003
Posts: 807
Likes: 2
G
UGN Super Poster
Offline
UGN Super Poster
G
Joined: Jun 2003
Posts: 807
Likes: 2
Agreed, PHP is a powerful, and awesome language. It's also pretty easy to learn.

Joined: Nov 2002
Posts: 1,146
Likes: 1
Ice Offline OP
UGN News Staff
OP Offline
UGN News Staff
Joined: Nov 2002
Posts: 1,146
Likes: 1
Quote:
Agreed, PHP is a powerful, and awesome language. It's also pretty easy to learn.
Only problem is that only small and medium sized buisness use PHP/MySQL. The big enterprise buisness dont bother using PHP/MySQL :[


Good artists copy, great artists
steal.

-Picasso
Joined: Feb 2005
Posts: 6
S
Junior Member
Offline
Junior Member
S
Joined: Feb 2005
Posts: 6
I tried compiling the first java code u post. But some error came out. "cannot resolve symbol variable in".

I see that u used in.getChar() so I think u need to import java.io.*; and declared in as BufferedReader...

Btw despite what I'm suggesting here, does u program work? cool


""Don't go looking for heroes to believe in... believe in yourselves." - Roadhandler
Joined: Mar 2002
Posts: 1,136
P
UGN Elite Poster
Offline
UGN Elite Poster
P
Joined: Mar 2002
Posts: 1,136
Change it to System.in.getChar()


Link Copied to Clipboard
Member Spotlight
Posts: 30
Joined: June 2002
Forum Statistics
Forums41
Topics33,840
Posts68,858
Average Daily Posts1
Members2,176
Most Online3,253
Jan 13th, 2020
Latest Postings
Where and how do you torrent?
by danni75 - 03/01/24 05:58 AM
Animation,
by JohanKaariainen - 08/15/19 01:18 AM
Blackbeard.....
by Gremelin - 10/03/18 07:02 PM
my old account still exists!
by Crime - 08/10/18 02:47 PM
Okay WTF?
by HenryMiring - 09/27/17 01:45 AM
The History Thread...
by Gremelin - 08/11/17 12:11 PM
My friend NEEDS your HELP!
by Lena01 - 07/21/17 12:06 AM
I'm having fun with this guy.
by gabithompson730 - 07/20/17 01:50 AM
I want to upgrade my phone
by gabithompson730 - 07/20/17 01:49 AM
Doom 3
by Cyrez - 09/11/14 08:58 PM
Amazon Gift Card Generator/KeyGen?te
by Gecko666 - 08/22/14 09:21 AM
AIM scene 99-03
by lavos - 09/02/13 08:06 AM
Planetside 2
by Crime - 03/04/13 07:10 AM
Beta Testers Wanted
by Crime - 03/04/13 06:55 AM
Hello Everyone
by Gremelin - 02/12/12 06:01 PM
Tracfone ESN Generator
by Zanvin Green - 01/18/12 01:31 PM
Python 3 issue
by Testing - 12/17/11 09:28 PM
tracfone airtime
by Drache86 - 07/30/11 03:37 AM
Backdoors and the Infinite
by ZeroCoolStar - 07/10/11 03:52 AM
HackThisZIne #12 Releaseed!
by Pipat2 - 04/28/11 09:20 PM
gang wars? l33t-wars?
by Gremelin - 04/28/11 05:56 AM
Consolidate Forums
by diggin2deep - 04/21/11 10:02 AM
LAN Hacking Noob
by Gremelin - 03/12/11 12:42 AM
Top Posters
UGN Security 41,392
Gremelin 7,203
§intå× 3,255
SilentRage 1,273
Ice 1,146
pergesu 1,136
Infinite 1,041
jonconley 955
Girlie 908
unreal 860
Top Likes Received
Ghost 2
Crime 1
Ice 1
Dartur 1
Cyrez 1
Powered by UBB.threads™ PHP Forum Software 7.7.5