Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 7th, 2009, 3:54 PM   #1
skylerof209
Newbie
 
Join Date: Jan 2009
Posts: 13
Rep Power: 0 skylerof209 is on a distinguished road
confused about multiple classes help simple question.

well ok im doing a fraction thing for java
my four variables are a,b,c,d(so a/b +c/d or sumthn like that)
i have my main class and fraction and my other math
so anyways my teacher gave me this ( a method on the class addition.)
public int addfraction(int a , int b, int c, int d)
now that the integers are declared a person has to input the four integers.
so my question is do i do the console.nextInt() in the main class or the class math
skylerof209 is offline   Reply With Quote
Old Apr 7th, 2009, 11:48 PM   #2
thechristelegacy
Expert Programmer
 
thechristelegacy's Avatar
 
Join Date: Jul 2004
Location: Somerset, Pa
Posts: 720
Rep Power: 7 thechristelegacy is on a distinguished road
Send a message via AIM to thechristelegacy Send a message via MSN to thechristelegacy
Re: confused about multiple classes help simple question.

Well it depends, you can do either way really.

If you have a class set up for your fraction code, you could get the input in the main function and then pass it into your fraction object when you create it.

Something like
public class myProg {
    public static void main (String[] args) {
        float a, b, c, d;
        a = console.nextInt();
        b = console.nextInt();
        c = console.nextInt();
        d = console.nextInt();
        
        Fraction frac = new Fraction(a,b,c,d);

     }
   }
And then in your class something like
public class Fraction{
    public Fraction(float a, float b, float c, float d){
        addFraction(a,b,c,d);
    }
}

Or you can put it write into the class. In the end you get the same result.

Last edited by thechristelegacy; Apr 7th, 2009 at 11:49 PM. Reason: Typo
thechristelegacy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

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

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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple if statement question :( Arnack C++ 12 May 4th, 2008 9:31 PM
Basic Question: Using Multiple Functions? skatJ C 6 Nov 19th, 2006 1:39 PM
Classes question MR.T Python 3 Oct 28th, 2006 9:34 PM
Pointers to std::strings Question (and classes in general) Soulstorm C++ 3 Aug 1st, 2006 5:15 AM
very simple question. make button change number in edit box nickm Delphi 2 Apr 29th, 2006 10:47 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:59 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC