Question

Question 1: The Java programming part.   
Write a java program that has a class “Fraction” that has does the following: The user should be able to input two fractions (command line is fine), the program should ensure that the denominator is not 0 in any case, and the user should be able to add, subtract, multiply or divide those two fractions together. You can assume these are signed integers and that the number ranges will be small (not exceeding 32 bit architecture limits) – so don’t worry about big integers or that sort of thing. You do not need to implement a ‘reduce’ function. Users should be able to Print the fraction as well, which should produce both the fraction in a numerator/denominator format as well as a floating point result (3 decimal places is fine).
Java does not support operator overloading (so don’t try).
A Fraction should have an integer numerator and integer denominator, at given time you could have up to 3 fraction objects.
The program should run in loop and allow the user to exit with some special character input (e.g. x or X to exit), but otherwise keep getting fractions to do basic math on, then print the result.
In a MS Word (or similar) document please provide examples of how you tested the program (input and output, remember though: the program does not need to reduce).

Question 2: UML.
Using the UML tool of your choice (I recommend UMLet) make a custom UML element that in the following style: It should have your name, a horizontal line, your student number, and the name of the degree program you are currently enrolled in, all centre justified. You should then export it in some way that you can import it into a word (or similar) document.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.util.Scanner;


public class Fraction {

public int numerator, denominator;

public Fraction(int num, int den)
{
numerator = num;
denominator = den;
}

public void add(Fraction fraction)
{
if(fraction.denominator == denominator)
numerator = numerator + fraction.numerator;
else
{
numerator = numerator * fraction.denominator + fraction.numerator * denominator;
denominator = denominator * fraction.denominator;
}
}

public void subtract(Fraction fraction)
{
if(fraction.denominator == denominator)
numerator = numerator - fraction.numerator;
else
{
numerator = numerator * fraction.denominator - fraction.numerator * denominator;
denominator = denominator * fraction.denominator;
}
}...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

Java Program: Strings, Integers, Statements
Homework Solution
$20.00
Java
Programming
Coding
Computer Science
Integers
Statements
Strings
Special Characters
Error Messages
Lines
Input
Output
Variables
Operators
Java Programming Assignment
Homework Solution
$40.00
Java Programming
Computer Science
Arrays
Dynamic Allocation
ArrayList
Constructor
Java Programming Questions
Homework Solution
$50.00
Java
Programming
Computer Science
Algorithms
Classes
Shapes
Iterations
Information
Sample Runs
Console Application
Mutator Methods
Colors
User Input
Inheritance
Java Program For Vending Machine
Homework Solution
$40.00
Java
Programming
Computer Science
Vending Machine
Drinks
Password
Screen
Inventory
Menu
Errors
Money
Get help from a qualified tutor
Live Chats