Marc Hauschildt
Web Technologies and Computer Software Development Instructor at Kirkwood Community College in Cedar Rapids, IA.
Week 1
Software Development Life Cycle, Steps 1-3
Fraction Class
Project Goal: To create a command-line application that performs basic arithmetic on fractions.
Project scope defines the boundaries of a project, such as what is included and excluded, thereby preventing scope creep and promoting efficient project execution.
Answer the question "What is the scope of the project?"
In Scope: The calculator must handle addition, subtraction, multiplication, and division. It must accept valid whole numbers, improper fractions, and mixed numbers (e.g., 3, 5/3, 1 2/3). All results must be simplified and displayed as both an improper fraction (e.g., 5/3) and a mixed number (e.g., 1 2/3).
Out of Scope: A graphical user interface (GUI) or handling square roots are not part of this initial project.
A feasibility analysis is a comprehensive evaluation of a proposed project to determine its viability. It assesses various factors like technical, financial/economic, operational, legal, and market aspects to determine if the project is likely to succeed and if it's worth pursuing.
Answer the question, "Is it feasible?"
Technical: Yes, it is possible, as Java has all the necessary tools to handle the arithmetic and user input.
Economic: The primary resources needed are a developer proficient in Java and a computer with a Java Development Kit (JDK). The cost is primarily the developer's time (approximately 8-10 hours). No special software or hardware is needed.
Operational: Once built, this project can be included as part of a suite of mathematical calculators. It will serve its purpose without disrupting any existing workflows.
Functional Requirements: (define what the program does)
The system must allow a user to input two fractions and an arithmetic operator (+, -, *, /).
The system must correctly parse various input formats: a/b (e.g., 2/3), a b/c (e.g., 1 1/2), and a (e.g., 4).
The system must perform the specified arithmetic operation. For example: 2/3+11/2 should equal 21/6.
The system must handle and report errors, such as division by zero or invalid input (e.g., "hello").
The final result must always be simplified to its lowest terms. For example, a raw result of 10/6 must be simplified to 5/3.
The final result must be displayed in two formats: as an improper fraction (e.g., 5/3) and as a mixed number (e.g., 1 2/3).
Non-Functional Requirements: (defines how it will be done)
The application must be written in the Java programming language.
It must run as a console (command-line) application.
Calculations must be accurate and computationally efficient.
We'll structure this application into two classes:
A Fraction class: This will be the core (the model) of our application. It will hold the data for a single fraction (numerator and denominator) and contain the logic for performing arithmetic operations, simplification, and formatting.
A Calculator (or Main) class: This will handle getting input from the console (the view) and orchestrate the operations (the controller) by creating Fraction objects and calling their methods.
Class diagrams show the classes of the system, their relationships, and the attributes and operations (methods).
Classes form the main building blocks of an object-oriented application.
Person |
---|
- String firstName |
+ getFirstName() : String + setFirstName(String firstName) : void + toString() : String |
ClassName |
---|
- attributes |
+ methods |
Person |
---|
- String firstName |
+ getFirstName() : String + setFirstName(String firstName) : void + toString() : String |
Person |
---|
- String firstName |
+ getFirstName() : String + setFirstName(String firstName) : void + toString() : String |
Fraction |
---|
- int numerator - int denominator |
+ Fraction() + Fraction(int numerator, int denominator) + getNumerator() :: int + setNumerator(int numerator) :: void + getDenominator() :: int + setDenominator(int denominator) :: void + toString() :: String + compareTo(Fraction other) :: int - gcd(int a, int b) :: int - lcm(int a, int b) :: int + simplify() :: void + toMixedNumber() :: String + add(Fraction other) :: Fraction + subtract(Fraction other) :: Fraction + multiply(Fraction other) :: Fraction + divide(Fraction other) :: Fraction |
classDiagram
class Fraction {
- int numerator
- int denominator
+ Fraction()
+ Fraction(int numerator, int denominator)
+ getNumerator(): int
+ setNumerator(int numerator): void
+ getDenominator(): int
+ setDenominator(int denominator): void
+ toString() : String
+ compareTo(Fraction other) : int
- simplify() : void
- gcd(int a, int b): int
+ toMixedNumberString() : String
+ add(Fraction other) : Fraction
+ subtract(Fraction other) : Fraction
+ multiply(Fraction other) : Fraction
+ divide(Fraction other) : Fraction
}
flowchart TD
A@{ shape: circle, label: "Start" } --> B@{ shape: lean-r, label: "Input Fraction 1 (n1/d1)<br>Input Fraction 2 (n2/d2)" };
B --> C@{ shape: diamond, label: "Are<br>d1 and d2<br>the same?" }
C -- Yes --> D
C -- No --> E@{ shape: rect, label: "Find the Least Common Multiple (LCM) of d1 and d2" };
E --> F@{ shape: rect, label: "Use the LCM to convert both fractions with the same denominator" };
F --> D@{ shape: rect, label: "Add numerators n1 and n2. Keep denominator the same." };
D --> G@{ shape: rect, label: "Display result as a simplified mixed number" };
G --> H@{ shape: circle, label: "End" };
flowchart TD
A@{ shape: circle, label: "Start" } --> B@{ shape: lean-r, label: "Input Fraction 1 (n1/d1)<br>Input Fraction 2 (n2/d2)" };
B --> C@{ shape: rect, label: "Set new numerator by cross multiplying<br>(n1 * d2 + d1 * n2)" };
C --> D@{ shape: rect, label: "Set new denominator<br>(d1 * d2)" };
D --> E@{ shape: rect, label: "Display result as a simplified mixed number" };
E --> F@{ shape: circle, label: "End" };
->
Convert 48/27 to 16/9, Convert 1/-2 to -1/2By Marc Hauschildt
Web Technologies and Computer Software Development Instructor at Kirkwood Community College in Cedar Rapids, IA.