Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class TesterClass { public static void main ( String [ ] args ) { Fraction f 1 = new Fraction ( ) ; Fraction

public class TesterClass
{
public static void main(String[] args)
{
Fraction f1= new Fraction();
Fraction f2= new Fraction(1,2);
System.out.println(f1);
System.out.println(f2.numerator / f2.denominator);
}
}
/** Class Fraction */
class Fraction
{
// instance variables
private int numerator;
private int denominator;
// constructor: set instance variables to default values
public Fraction()
{
int d =1;
numerator = d;
denominator = d;
}
// constructor: set instance variables to init parameters
public Fraction(int initNumerator, int initDenominator)
{
numerator = initNumerator;
denominator = initDenominator;
}
public String toString()
{
// if the denominator is 1, then just return the numerator
if (denominator == d)
{
int newNumerator =1;
}
return newNumerator +"/"+ denominator;
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual Basic6 Database Programming

Authors: John W. Fronckowiak, David J. Helda

1st Edition

0764532545, 978-0764532542

More Books

Students also viewed these Databases questions

Question

Explain the components of the current ratio.

Answered: 1 week ago

Question

Write short notes on Marketing mix.

Answered: 1 week ago

Question

Analyse the process of new product of development.

Answered: 1 week ago

Question

Define Trade Mark.

Answered: 1 week ago

Question

=+you think is being taxed when more money is printed? Why?

Answered: 1 week ago