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 392143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:07:48+00:00 2026-05-12T16:07:48+00:00

If i was to make a new program and wanted to have a fraction

  • 0

If i was to make a new program and wanted to have a fraction class and what my book calls a driver class wich is a main class and i have code like this

// Driver class

import java.util.Scanner;

public class DriverClass{

    public static void main(String[] args){

        Scanner stdIn = new Scanner(System.in);
        Fraction c, d;

        System.out.println(" Enter a numerator then a denominator:");
        c = new Fraction( stdIn.nextInt(), stdIn.nextInt());
        c.print();

       System.out.println(" Enter a numerator then a denominator:");
        d = new Fraction( stdIn.nextInt(), stdIn.nextInt());
        d.print();
    }
}
...

in my fraction class i have a method called public fraction. How will that set both numbers from fraction c in the driver class wich is coming in from the scanner util and also would this, would the c values be replaced by the values that are coming in from fraction d? I am taking a Java class and this is part the part of my home work I dont understand. I am trying to get these valued passed to the fraction class because in the end i have to add these two fractions together and also multiply them.

// begining of class

public class Fraction{

    private int numerator;
    private int denominator;

    // well this is what my problem is, how do I call for c 
    // twice in the Fraction class
    public int Fraction(int num, int denom){

this.numerator = num;

this.denominator = denom;
}
    // is this the right way to recieve the fraction 
    // from the driver class for both c and d?

}

can any one help me with this one

  • 1 1 Answer
  • 2 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-05-12T16:07:49+00:00Added an answer on May 12, 2026 at 4:07 pm

    Your Fraction method is a method which is defined to return an int, but you’re calling it as though it were a constructor.

    Constructors don’t return anything, so don’t declare any return type. ( they don’t even have a void type so the compiler knows they are constructors rather than methods, and need to be called with new. It’s a minor bug that Java lets you declare methods with the same name as the class, IIRC one of the puzzles in Java Puzzlers does that ).

    Remove the “int” return type from the definition:

    public class Fraction{
    
        private int numerator;
        private int denominator;
    
        public  Fraction(int num, int denom) {
            //...
    

    How will that set both numbers from fraction c in the driver class wich is coming in from the scanner util and also would this, would the c values be replaced by the values that are coming in from fraction d?

    You’re making two calls to new Fraction(..,..). Each time you use new, it creates a new object of the requested class and then calls the constructor on that object with the values you give it. So c and d will hold references to difference instances of Fraction. As the numerator and denominator fields of Fraction are not marked as static, then each instance of Fraction will have its own copy of those fields, so the values passed to the constructor of the object whose reference will stored in the variable c are stored in the first new object, and those of d in the second new object. As they are different objects, the values won’t replace each other.

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

Sidebar

Related Questions

I am new in java. I try to make a program and I have
I have a program doing something like the following: class SomeObject{} { void function(int
I am trying to make a simple program that could open a new activity
I'm new to iPhone programming, and I'm trying to make a simple program without
I have make a new dropdown navi in css . Chrome, firefox, safari is
I'm trying to make a new CLLocation subclass. This is the skeleton: #import <UIKit/UIKit.h>
I'm trying to make a new wx.Choice-like control (actually a replacement for wx.Choice) which
I don't want to make a new instance of Form1 in the class, and
I have a program that makes some hefty calls to the database and then
I wanted to make a class GradeBook, then create an object for each student,

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.