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 Programming Assignment
Homework Solution
$30.00
Java Programming
Variables
ToString Method
Equals Method
Overload
Computer Science
LinkedList in Java
Homework Solution
$30.00
Java
Programming
Computer Science
LinkedList
Methods
Variables
Statements
Players
Game Results
Client Code
List Head
Positions
Nodes
Multiplication Table in Java
Homework Solution
$40.00
Java
Programming
Codes
Algorithms
Computer Science
Statements
Variables
Loops
Rows
Columns
Input
Output
Integers
Strings
Multiplication
Tables
Operations
Conditions
Array Problems in Java: Summation, Average, Min/Max, Searching, Sorting
Homework Solution
$13.00
Java
Programming
Coding
Computer Science
Arrays
Summation
Average
Minimum Number
Maximum Number
Bubble Sort
Selection Sort
Sequential Search
Binary Search
Algorithms
Input
Output
Methods
Integers
Functions
Java Problems With Stack
Homework Solution
$40.00
Java
Programming
Coding
Computer Science
Stack
Generic Types
Push
Pop
Peek
Size
Linked List
Functions
Strings
Integers
Summation
Negative Values
Input
Output
Get help from a qualified tutor
Live Chats