Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8608063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:31:13+00:00 2026-06-12T03:31:13+00:00

first i would like to start saying that i am new to programing and

  • 0

first i would like to start saying that i am new to programing and i don t know much. with that said i would appreciate if anyone could help me with my program that it is supposed to read 2 fractions and an operator for example “2/3 + 4/5”. i have some of the code done but it still give me an error when i run it here is what i have so far:

public class Fraction {

    private static int numer;
    private static int denom;

     public Fraction(int num, int den)
        {
            numer = num;
            denom = den;
            simplify();
        }


    int findGcd(int a, int b)
        { 
        int temp;
            while(b != 0)
            {
                    temp = b;
                    b = a % b;
                    a = temp;
            }
        return a;
    }


    void simplify()
        {
            int gcd = findGcd(numer, denom);
            numer /= gcd;
            denom /= gcd;
        }

    public int getNumer(){
        return numer;
    }

    public int getDenom(){
        return denom;
    }



    Fraction add(Fraction x) {
        Fraction result;

        if (x.getDenom()== getDenom()) {
            result = new Fraction(x.getNumer() + getNumer(), denom);
        } else {
            denom = this.getDenom() * x.getDenom();
            numer = this.getNumer() * x.getDenom() + x.getNumer() * this.getDenom();
            return new Fraction(numer,denom);


        }
        return result;
    }

    public String toString(){
          return (Integer.toString(numer) + "/" +
                     Integer.toString(denom));
    }



    public static void main (String []args){
            Fraction a = new Fraction(1,3);
            Fraction b = new Fraction(4,5);
            System.out.println(a.toString());
            System.out.println(b.toString());
    }
}

thank you for your help i really appreciate it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:31:14+00:00Added an answer on June 12, 2026 at 3:31 am

    Why are you making your fields static? static fields belong to the class as opposed to each instantiation (not what you want here). Try removing the static keyword.

    On another note, you mentioned that you’d like to read input from the user. You might want to look into using a Scanner for this (in case you don’t already know about this handy class).

    Once you read the input, something like 2/3 + 4/5, you can split your string using a space as your delimiter. Now, you can parse a fraction from the first (2/3) and third (4/5) elements of the newly formed string array, and perform the operation that corresponds to the second element of the array (+).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First for all I would like to start by saying I am relatively new
First I would like to say that I am new to this site, never
Hi I would like to start by saying I'd greatly appreciate anyones help on
I'm new to jquery and would like to start datepicker with focus. My first
First I would like to start off with the info that I have just
I've been developing my first iPhone app part-time and would like to start using
I would like all my URLs in codeigniter to start with the first URI
I would first like to admit that I am an extremely novice developer, so
First off I would like to say that I think that my question may
First off I would like to say that this is my first post and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.