![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2009
Posts: 13
Rep Power: 0
![]() |
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) so my question is do i do the console.nextInt() in the main class or the class math |
|
|
|
|
|
#2 |
|
Expert Programmer
|
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);
}
}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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |