473,486 Members | 2,181 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

I Have A Class And Method Problems....

30 New Member
/*MY CONSOLE DOES NOT EXECUTE EVERY TIME I RUN MY PROGRAM
WHAT HAPPEN? WHERE DID I GO WRONG? BUT THE PROCESS IS COMPLETED...I AM NEW IN JAVA PROGRAM AND THIS IS OUR NEW LESSON IN CLASS*/
Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import java.util.*;
  3. import java.lang.*;
  4. public class FRACTIONagain {
  5.  
  6.     static Scanner console = new Scanner(System.in); 
  7.     public static void main(String[]args) {
  8.  
  9.     FRACTIONclass oldFraction = new FRACTIONclass();
  10.  
  11.  
  12.  
  13.     int num1 = 0,denom1 = 0;
  14.     int num2=0,denom2=0;
  15.     String operator=" ",slash=" ";
  16.  
  17.     System.out.println("Enter two fractions followed by a space");
  18.     num1 = console.nextInt();
  19.     slash = console.next();
  20.     denom1 = console.nextInt();
  21.     num2 = console.nextInt();
  22.     slash = console.next();
  23.     denom2 = console.nextInt();
  24.     System.out.println(); 
  25.  
  26.     oldFraction.getNum(num1, denom1, operator, num2, denom2);
  27.  
  28.     }
  29.     }
//THIS IS MY MAIN
----------------------------------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. public class FRACTIONclass {
  2.  
  3.     public FRACTIONclass() 
  4.     {
  5.      getNum(0,0," ",0,0);        
  6.     }
  7.     public void getNum(int num1,int denom1,String operator,int num2, int denom2)
  8.     {
  9.         if(operator == "+") 
  10.         addNum(num1,denom1,num2,denom2);
  11.  
  12.         if(operator == "-") 
  13.         subNum(num1,denom1,num2,denom2);
  14.  
  15.         if(operator == "*") 
  16.         mulNum(num1,denom1,num2,denom2);
  17.  
  18.         if(operator == "/") 
  19.         divNum(num1,denom1,num2,denom2);
  20.  
  21.         else
  22.         System.exit(0);
  23.     }
  24.  
  25.      public static void addNum(int w,int x, int y, int z)
  26.     {
  27.         int numerator= 0,denominator= 0;
  28.         numerator = (w*z)+(x*y);
  29.         denominator = x*z;
  30.         System.out.println("Answer: "+numerator+"/"+" "+denominator);
  31.  
  32.     }
  33.     public static void subNum(int w,int x, int y, int z)
  34.     {
  35.     int numerator= 0,denominator= 0;
  36.     numerator = (w*z)-(x*y);
  37.     denominator = x*z;
  38.  
  39.     System.out.println("Answer: "+numerator+"/"+""+denominator);    
  40.     }
  41.  
  42.     public static void mulNum(int w,int x, int y, int z)
  43.     {
  44.     int numerator= 0,denominator= 0;
  45.     numerator = w*y;
  46.     denominator = x*z;    
  47.     System.out.println("Answer: "+numerator+"/"+""+denominator);
  48.     }
  49.  
  50.     public static void divNum(int w,int x, int y, int z)
  51.     {
  52.      int numerator= 0,denominator= 0;
  53.      numerator = w*z;
  54.      denominator = x*y;
  55.      System.out.println("Answer: "+numerator+"/"+""+denominator);
  56.  
  57.     }
  58.  
  59. }
//THIS IS MY CLASS
Sep 9 '08 #1
3 1245
Nepomuk
3,112 Recognized Expert Specialist
Hi jimgym1989! Welcome to bytes.com!

It's great to have you here!

When you post, please always keep to the Posting Guidelines and when you post code, please post it in [code] ... [/code] tags. (I've added them for you this time, please use them yourself in future.)

In this post, you have used capital letters in everything you wrote apart from the code. This is against our rules, as the use of capitals is generally considered to be shouting and therefore rather rude. So please, even if you're angry at your code or your computer or whatever, do not use capitals in that way.

About your question, how do you "run your program"? Are you using an IDE (e.g. Eclipse, Netbeans, ...) or did you write your code in an editor (e.g. Notepad)? Your code is probably correct (as you say it does what it should), but the way you call it may not be.

Otherwise, I'll just wish you the best and hope you enjoy being part of bytes.com!

Greetings,
Nepomuk (Moderator)
Sep 9 '08 #2
jimgym1989
30 New Member
Hi jimgym1989! Welcome to bytes.com!

It's great to have you here!

When you post, please always keep to the Posting Guidelines and when you post code, please post it in [code] ... [/code] tags. (I've added them for you this time, please use them yourself in future.)

In this post, you have used capital letters in everything you wrote apart from the code. This is against our rules, as the use of capitals is generally considered to be shouting and therefore rather rude. So please, even if you're angry at your code or your computer or whatever, do not use capitals in that way.

About your question, how do you "run your program"? Are you using an IDE (e.g. Eclipse, Netbeans, ...) or did you write your code in an editor (e.g. Notepad)? Your code is probably correct (as you say it does what it should), but the way you call it may not be.

Otherwise, I'll just wish you the best and hope you enjoy being part of bytes.com!

Greetings,
Nepomuk (Moderator)
Hi Nepomuk!! thank you for your immediate response..im very sorry..i haven't read the post guidelines...anyways it wasn't my intention to be mad on something, i just make it capital so that you'll be able to see my questions properly..hehehe..im using JCreator..I just copy paste my code on this textfield..how do i properly call the method or a class..

by the way I'm a Happy Person
Sep 9 '08 #3
Nepomuk
3,112 Recognized Expert Specialist
Hi Nepomuk!! thank you for your immediate response..im very sorry..i haven't read the post guidelines...
No problem, as long as you've read them now. ^^
anyways it wasn't my intention to be mad on something, i just make it capital so that you'll be able to see my questions properly..hehehe..
Well, that's what the [CODE]...[/code] tags are for.
im using JCreator..I just copy paste my code on this textfield..how do i properly call the method or a class..
JCreator should have some kind of "run" button and some kind of console. If you run a very simple class like this:
Expand|Select|Wrap|Line Numbers
  1. public class HelloWorld {
  2.    public static void main(String[] args) {
  3.       System.out.println("Hello World");
  4.       System.in.read(); // This is just to make sure, that the console window doesn't close immediately
  5.    }
  6. }
then the output "Hello World" must be printed somewhere. That place is a replacement for the command window. You can however start your class from a "proper" console too - open one (in Windows: Start -> Run -> "cmd" -> Enter -> cd /d "path/to/my/project") and then start your program with java -cp yourClasspath youClass
by the way I'm a Happy Person
Glad to hear that. Happy people are especially welcome here! :-D

Greetings,
Nepomuk
Sep 9 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1698
by: Gregory Bond | last post by:
I'm building a class hierarchy that needs to keep as a class variable a reference to a (non-member) function, so that different subclasses can use different generator functions. But it seems...
21
4027
by: Jon Slaughter | last post by:
I have a class that is basicaly duplicated throughout several files with only members names changing according to the class name yet with virtually the exact same coding going on. e.g. class...
21
1957
by: Mark Broadbent | last post by:
Consider the following statements //------- Item i = Basket.Items; //indexer is used to return instance of class Item Basket.Items.Remove(); //method on class item is fired item i = new...
28
4291
by: kfrost | last post by:
I know this is probably simple but I have a C# form and the class for the form is called sbaSynch. I have a textbox name txtServerName. I'm creating a class to manipulate XML functions so I...
7
2095
by: WXS | last post by:
Vote for this idea if you like it here: http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=5fee280d-085e-4fe2-af35-254fbbe96ee9...
8
1968
by: Jackson | last post by:
I want a class that will determine its base class by the argument passed in. What I am about to write _does_not_work_, but it shows what I am trying to do. class ABC(some_super): def...
9
5481
by: silversurfer2025 | last post by:
Hello everyone, I am currently having problems with a C++ abstract class. I have a class FrameWork.h which defines some methods (of which some are abstract, i.e. virtual void method() = 0). In...
4
1706
by: ddtl | last post by:
Hello everybody. Consider the following code: class A(object): def met(self): print 'A.met' class B(A): def met(self):
21
55569
by: phpCodeHead | last post by:
Code which should allow my constructor to accept arguments: <?php class Person { function __construct($name) { $this->name = $name; } function getName()
20
4001
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7132
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7180
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5439
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4564
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
266
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.