Java School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a Java Expert!

Join 300,503 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,880 people online right now. Registration is fast and FREE... Join Now!




A little help here, How could i edit this to have Methods

 

A little help here, How could i edit this to have Methods

NoobProgramer

30 Jun, 2009 - 10:24 PM
Post #1

D.I.C Head
**

Joined: 15 Jun, 2009
Posts: 68



Thanked: 1 times
My Contributions
CODE

import java.io.*;                

class Calculator
{
     public static void main ( String [] args ) throws IOException    
     {
          BufferedReader stdin =  new BufferedReader(new InputStreamReader( System.in ));

            System.out.print( " Enter Number 1:  " );
            String input   =   stdin.readLine();            
            int a    =   Integer.parseInt( input );

            System.out.print( "Enter Number 2:  " );
            input   =   stdin.readLine();                    
            int b    =   Integer.parseInt( input );

            System.out.print( "Enter your choice: \n1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\nYour Choice: ");

            
            input        =  stdin.readLine();        
            int choice  =  Integer.parseInt( input );

            switch( choice )                        
        {
        case 1:                              
        System.out.println( a +" + "+ b + " = " + (a+b) );
        break;
        
        case 2:                              
        System.out.println( a + " - " + b +" = " + (a-b) );
        break;

        case 3:                                
        System.out.println( a + " * " + b +" = " + (a*b) );
        break;

        case 4:                                
        System.out.println( a + " / " + b +" = " + (float)(a/b) );    
                 break;
                
                
                

        default:                                
        System.out.println( "Enter a valid choice..." );

            }
      }                                                    
}


damn , my professor is so demanding he wants me to put a method /constructor
kindly help me to edit this to have constructor and methods

User is offlineProfile CardPM
+Quote Post


no2pencil

RE: A Little Help Here, How Could I Edit This To Have Methods

30 Jun, 2009 - 10:29 PM
Post #2

i R L33t Skiddie, k?
Group Icon

Joined: 10 May, 2007
Posts: 13,234



Thanked: 289 times
Dream Kudos: 2875
Expert In: Goofing Off

My Contributions
QUOTE(NoobProgramer @ 1 Jul, 2009 - 12:24 AM) *

my professor is so demanding he wants me to put a method /constructor

So what's the difference between your professor asking you to do it, & you asking someone us to do it?
User is offlineProfile CardPM
+Quote Post

Jaanavee

RE: A Little Help Here, How Could I Edit This To Have Methods

30 Jun, 2009 - 10:33 PM
Post #3

New D.I.C Head
*

Joined: 24 Jun, 2009
Posts: 14

its quite simple
1. first create another class say class AAA
2. in that create consructor as AAA() and write all ur coding i that constructor.
3.and lastly create instace of class AAA in main method of ur class Calculator
User is offlineProfile CardPM
+Quote Post

NoobProgramer

RE: A Little Help Here, How Could I Edit This To Have Methods

1 Jul, 2009 - 09:23 PM
Post #4

D.I.C Head
**

Joined: 15 Jun, 2009
Posts: 68



Thanked: 1 times
My Contributions
QUOTE(Jaanavee @ 30 Jun, 2009 - 10:33 PM) *

its quite simple
1. first create another class say class AAA
2. in that create consructor as AAA() and write all ur coding i that constructor.
3.and lastly create instace of class AAA in main method of ur class Calculator



Thanks for that jaanavee , ur more helpful that the first one who posted here.. satisfied.gif
User is offlineProfile CardPM
+Quote Post

Fuzzyness

RE: A Little Help Here, How Could I Edit This To Have Methods

1 Jul, 2009 - 09:48 PM
Post #5

Comp Sci Student
Group Icon

Joined: 6 Mar, 2009
Posts: 1,149



Thanked: 173 times
Dream Kudos: 150
My Contributions
Wow the disrespect runs high in the threads today.

no2Pencil is a highly known moderator in this website. He has helped me a number of times as many other people and contributed to tutorials of many. The difference this time is that you are asking us to do your homework. Constructors and methods are the basics of Java and learning the class layouts and how they function. You could simply google it and get a lot of results for it, not to mention the tutorial section for Java in this website is a good one, but why should we ask you to work for your code? That crazy! Instead you would do as your instructor did to you, ask us to fix it.

no2Pencil had a point, a well one, not to mention the fact you didnt say please. If you want future help in the Java Section at all I would suggest disrespecting the mods would come to a halt, I have no intention on helping those who are disrespectful.

Have a Good Day Sir. smile.gif
User is offlineProfile CardPM
+Quote Post

NeoTifa

RE: A Little Help Here, How Could I Edit This To Have Methods

2 Jul, 2009 - 05:07 AM
Post #6

Yay caek! ZOMG!!!
Group Icon

Joined: 24 Sep, 2008
Posts: 6,292



Thanked: 79 times
Dream Kudos: 150
My Contributions
[I'm sick of the flame wars. -Neo]

On a different note, you said method/constructor? Which one? A constructor means a whole different class, and a method could just be an addition to the main class you already have.

This post has been edited by NeoTifa: 2 Jul, 2009 - 06:22 AM
User is offlineProfile CardPM
+Quote Post

computerfox

RE: A Little Help Here, How Could I Edit This To Have Methods

2 Jul, 2009 - 05:15 AM
Post #7

straight vegetarian kid
*****

Joined: 29 Jan, 2009
Posts: 3,772



Thanked: 48 times
Dream Kudos: 1700
My Contributions
QUOTE(NeoTifa @ 2 Jul, 2009 - 05:07 AM) *

Actually I find No2Pencil to be a very nonhelpful ass, but he's just like that to me lol. He is being nicer though, so I will say that. He is a reletively respected member of this community, and should be respected by n00bs. (I'm a different story though tongue.gif) In all, you definitely should use manners when requesting help. Some most of us are really busy, and make it a point to take time out of our busy schedules to come here and help. Why do you think I get so frustrated when nincumpoops like fox post crap that doesn't help or is basically spam?

On a different note, you said method/constructor? Which one? A constructor means a whole different class, and a method could just be an addition to the main class you already have.


1-i actually like no2. i find his personality hilarious.
2-you criticize no2 and i for "not being helpful" but what the fuck do you do? you say you'll do some tutorials, but you never get them done. i know it's that time of the month, but get over it and stop bitching.
3-as for the original post:

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.
User is offlineProfile CardPM
+Quote Post

NeoTifa

RE: A Little Help Here, How Could I Edit This To Have Methods

2 Jul, 2009 - 05:26 AM
Post #8

Yay caek! ZOMG!!!
Group Icon

Joined: 24 Sep, 2008
Posts: 6,292



Thanked: 79 times
Dream Kudos: 150
My Contributions
[deleted. pull your head out of your ass computerfox- Neo]

This post has been edited by NeoTifa: 2 Jul, 2009 - 06:23 AM
User is offlineProfile CardPM
+Quote Post

computerfox

RE: A Little Help Here, How Could I Edit This To Have Methods

2 Jul, 2009 - 05:44 AM
Post #9

straight vegetarian kid
*****

Joined: 29 Jan, 2009
Posts: 3,772



Thanked: 48 times
Dream Kudos: 1700
My Contributions
are you threatening me? whatever i don't have patience for someone that keeps bitching regardless.

anyways, as neotifa has stated, which one is it? do you want just methods or a whole entire new class? and what would you want to make into methods?

This post has been edited by computerfox: 2 Jul, 2009 - 05:55 AM
User is offlineProfile CardPM
+Quote Post

pbl

RE: A Little Help Here, How Could I Edit This To Have Methods

2 Jul, 2009 - 02:48 PM
Post #10

Java Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 9,537



Thanked: 1126 times
Dream Kudos: 450
My Contributions
Do not post your question on the topic title, it gets truncated
Topic title is to give a "hint" on what the question would be
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 05:03AM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month