Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Write a driver and fraction class that performs addition, multiplication, prints the fraction, and prints as a double.
YourNameProg7.java
Provide a driver class, YourNameProg7, that demonstrates this Fraction class. The driver class should contain this main method:
public static void main(String[] args)
{
Scanner stdIn = new Scanner(System.in);
Fraction c, d, x; // Fraction objects
System.out.println("Enter numerator; then denominator.");
c = new Fraction(stdIn.nextInt(), stdIn.nextInt());
c.print();
System.out.println("Enter numerator; then denominator.");
d = new Fraction(stdIn.nextInt(), stdIn.nextInt());
d.print();
x = new Fraction(); // create a fraction for number 0
System.out.println("Sum:");
x.add(c).add(d);
x.print();
x.printAsDouble();
x = new Fraction(1, 1); // create a fraction for number 1
System.out.println("Product:");
x.multiply(c).multiply(d);
x.print();
x.printAsDouble();
System.out.println("Enter numerator; then denominator.");
x = new Fraction(stdIn.nextInt(), stdIn.nextInt());
x.printAsDouble();
} // end main
Note that this demonstration driver does not call the accessor methods. That's OK. Accessor methods are often implemented regardless of whether there's an immediate need for them. That's because they are very useful methods in general and providing them means that future code can use them when the need arises.
16
Fraction.java
Write a Fraction class called Fraction.java that implements these methods:
· add - This method receives a Fraction parameter and adds the parameter fraction to the calling object fraction.
· multiply - This method receives a Fraction parameter and multiplies the parameter fraction by the calling object fraction.
· print - This method prints the fraction using fraction notation (1/4, 21/14, etc.)
· printAsDouble - This method prints the fraction as a double (0.25, 1.5, etc.)
Separate accessor methods for each instance variable in the Fraction class. 
Sample Output
Enter numerator; then denominator.
5
8
5/8
Enter numerator; then denominator.
4
10
4/10
Sum:
82/80
1.025
Product:
20/80
0.25
Enter numerator; then denominator.
6
0
infinity 

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M9652006

Have any Question?


Related Questions in Computer Engineering

Serial port assignmentdesign write and debug an mc8051

Serial Port Assignment Design, write, and debug an MC8051 assembly program which does the following: Configure the serial port to mode 1 with enabled reception and 9600 BAUD rate for the DS89S420 microcontroller. Also co ...

Suppose a graph is represented by a list of lists a of

Suppose a graph is represented by a list of lists A of zeroes and ones. If there is an edge from node i to j, then A[i][j] = 1, otherwise A[i][j] = 0. Write a Python function to find a path between any two nodes. Write c ...

Penetration testing is a technique used to identify

Penetration testing is a technique used to identify security weaknesses in your network. Discuss a type of penetration testing and the different methods utilized to recognize vulnerabilities in your network.

Suppose there is a relation ra b c with a b-tree index with

Suppose there is a relation R(A, B, C) with a B+-tree index with search keys (A, B). 1. What is the worst-case cost of finding records satisfying 10 2. What is the worst-case cost of finding records satisfying 10 3. Unde ...

Anz is offering a product that pays out 3000 quarterly from

ANZ is offering a product that pays out $3,000 quarterly from the end of Mar 2021 to the end of Dec 2030 with annual interest rate 6% compounded quarterly. (e.g. payment is made at the end of every March, June, September ...

Question 1a major department store chain is interested in

QUESTION 1 A major department store chain is interested in estimating the average amount its credit card customers spent on their first visit to the chain's new store in the mall. Fifteen credit card accounts were random ...

Without doing any math or drawing a graph which is bigger

Without doing any math, or drawing a graph, which is bigger, compensating variation or equivalent variation for a tax? Consider an individual with Cobb-Douglas preferences over some good and all other goods. In what sens ...

Do you need computers or information and communication

Do you need computers or information and communication technologies to store, organize, and manage data in organizations? Explain how the present day organizations in a developed country like the USA store and manage the ...

Question after 1 year of launch ride sharing increased a

Question: After 1 year of launch, ride sharing increased a lot resulting in a lot of insertion requests to the database. Consider there is no room to further increase the size of server and changing database is not an op ...

Write a program that takes as input an xy center value and

Write a program that takes as input an x,y center value and radii for two circles, draws them in a turtle (Python) window, and prints whether they intersect or not. You should show intersecting circles, and show non-inte ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As