diff --git a/Lectures/OLD_SpecViaUMLWithJava/SpecViaUML.pdf b/Lectures/OLD_SpecViaUMLWithJava/SpecViaUML.pdf new file mode 100644 index 0000000000000000000000000000000000000000..12e4432309b5d737a6e58509bb5de1359b5880e8 Binary files /dev/null and b/Lectures/OLD_SpecViaUMLWithJava/SpecViaUML.pdf differ diff --git a/Lectures/OLD_SpecViaUMLWithJava/SpecViaUML.tex b/Lectures/OLD_SpecViaUMLWithJava/SpecViaUML.tex new file mode 100755 index 0000000000000000000000000000000000000000..84416f2e4af03a74f0b065977361e8147bc7b6fe --- /dev/null +++ b/Lectures/OLD_SpecViaUMLWithJava/SpecViaUML.tex @@ -0,0 +1,480 @@ +%\documentclass[t,12pt,numbers,fleqn,handout]{beamer} +\documentclass[t,12pt,numbers,fleqn]{beamer} + +\usepackage{pgfpages} +\usepackage{hyperref} +\hypersetup{colorlinks=true, + linkcolor=blue, + citecolor=blue, + filecolor=blue, + urlcolor=blue, + unicode=false} +\urlstyle{same} + +\usepackage{booktabs} +\usepackage{multirow} +\usepackage{listings} + +\useoutertheme{split} %so the footline can be seen, without needing pgfpages + +% \pgfpagesuselayout{resize to}[letterpaper,border +% shrink=5mm,landscape] %if this is uncommented, the hyperref links do not work + +\mode<presentation>{} + +\input{../def-beamer} +\Draftfalse + +\newcommand{\topicTitle}{26 Specification Via UML (Ch.\ 5 and others)} +\ifDraft +\newcommand{\topic}{\topicTitle~DRAFT} +\else +\newcommand{\topic}{\topicTitle} +\fi + +\input{../titlepage} + +\begin{document} + +\input{../footline} + +\lstset{language=java,breaklines=true,showspaces=false,showstringspaces=false,breakatwhitespace=true} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{\topic} + +\begin{itemize} +\item Administrative details +\item Best specification technique? +\item Designing spec of modules +\item Interfaces in UML +\bi +\item Measurable interface +\item Multiple inheritance example +\ei +\item Generic classes in UML +\item Use cases with UML +\item Sequence diagrams in UML +\end{itemize} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Administrative Details} + +\ifDraft +TBD +\else +{ +\begin{itemize} + +\item \structure{Who has skimmed the homework problem?} +\item Some delay likely in grading A2 +\item A3 deadlines +\begin{itemize} +\item Part 1 - Specification: due 11:59 pm \structure{Mar 11} +\item Part 2 - Code: due 11:59 pm Mar 20 +\end{itemize} + +\item A4 +\bi +\item Your own design and specification +\item Due April 3 at 11:59 pm +\ei + +\item Sources of slides +\bi +\item DataSet example based on Cay Horstmann, Big Java, John Wiley \& Sons, 2002 +\item Other UML examples from Stevens, Using UML, 2006 +\item Ghezzi et al 2003 +\ei +\end{itemize} +} +\fi + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Best?} + +\bi +\item \structure{What is the best software development tool?} +\item \structure{What is the most important software design principle?} +\item \structure{What is the best specification technique?} +\ei + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Best Continued} + +\bi +\item \structure{What is the best programming language?} +\item \structure{What is the best engineering/scientific discipline?} +\item \structure{What is the best movie? video game?} +\item \structure{What is the best genre of music?} +\item \structure{What is the best food?} +\ei + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Deciding the Best Strategy For a Given Problem} + +\bi +\item What is the approach at your company? +\item Likely maintenance, so many decisions have likely been made. +\item What tools/techniques/programming language etc.\ do you know? +\item What can you afford in terms of cost/time? +\item What tool is appropriate for the task at hand? +\item What are the requirements? +\bi +\item Verifiability? +\item Maintainability? +\item Reusability? +\item etc. +\ei +\item etc. +\ei + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{UML Diagram of Measurable Interface} + +\includegraphics[scale=0.65]{../Figures/UMLDataSetMeasurableInterface.pdf} + +\begin{itemize} +\item Realization arrow should have an outline triangle +\item UML diagram can also show interface method names +\item Realization arrow is like weak generalization (inheritance) +\end{itemize} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[allowframebreaks] +\frametitle{DataSet Without Interface} + +\lstset{language=java,breaklines=true,showspaces=false,showstringspaces=false,breakatwhitespace=true} +\noindent \lstinputlisting{./src/DataSet.java} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[allowframebreaks] +\frametitle{PointT} +\lstset{language=java,breaklines=true,showspaces=false,showstringspaces=false,breakatwhitespace=true} +\noindent \lstinputlisting{./src/PointT.java} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[allowframebreaks] +\frametitle{DataSet for Points} +\lstset{language=java,breaklines=true,showspaces=false,showstringspaces=false,breakatwhitespace=true} +\noindent \lstinputlisting{./src/DataSetPoint.java} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[allowframebreaks] +\frametitle{Bank Account Class} +\lstset{language=java,breaklines=true,showspaces=false,showstringspaces=false,breakatwhitespace=true} +\noindent \lstinputlisting{./src/BankAccount.java} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[allowframebreaks] +\frametitle{DataSet for Bank Accounts} +\lstset{language=java,breaklines=true,showspaces=false,showstringspaces=false,breakatwhitespace=true} +\noindent \lstinputlisting{./src/DataSetBankAccount.java} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[allowframebreaks] +\frametitle{Measurable Interface} +\lstset{language=java,breaklines=true,showspaces=false,showstringspaces=false,breakatwhitespace=true} +\noindent \lstinputlisting{./src/Measurable.java} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[allowframebreaks] +\frametitle{Data Set with Measurable Interface} +\lstset{language=java,breaklines=true,showspaces=false,showstringspaces=false,breakatwhitespace=true} +\noindent \lstinputlisting{./src/DataSetInterface.java} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[allowframebreaks] +\frametitle{PointT with Measurable Interface} +\lstset{language=java,breaklines=true,showspaces=false,showstringspaces=false,breakatwhitespace=true} +\noindent \lstinputlisting{./src/PointTInterface.java} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[allowframebreaks] +\frametitle{Bank Account with Measurable Interface} +\lstset{language=java,breaklines=true,showspaces=false,showstringspaces=false,breakatwhitespace=true} +\noindent \lstinputlisting{./src/BankAccountInterface.java} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[allowframebreaks] +\frametitle{Using DataSet} +\lstset{language=java,breaklines=true,showspaces=false,showstringspaces=false,breakatwhitespace=true} +\noindent \lstinputlisting{./src/DataSetTest.java} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Interface Strategy} +\begin{itemize} +\item There are limitations to the Measurable interface +\begin{itemize} +\item You can only add a Measurable interface to classes that you control +\item You can measure an object in only one way +\end{itemize} +\item Move responsibility for measuring outside of objects themselves +\item Have another object carry out the comparison +\item Introduce a Measurer interface +\end{itemize} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{UML Diagram of Measurer Interface} + +\includegraphics[scale=0.55]{../Figures/UMLDataSetMeasurerInterface.pdf} + +\bi +\item Rectangle is part of Class java.awt +\item You cannot change it +\ei + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[allowframebreaks] +\frametitle{Measurer Interface} + +\lstset{language=java,breaklines=true,showspaces=false,showstringspaces=false,breakatwhitespace=true} +\noindent \lstinputlisting{./src/Measurer.java} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[allowframebreaks] +\frametitle{Data Set with New Strategy} + +\lstset{language=java,breaklines=true,showspaces=false,showstringspaces=false,breakatwhitespace=true} + +\noindent \lstinputlisting{./src/DataSetStrategy.java} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[allowframebreaks] +\frametitle{Rectangle Measurer} + +\lstset{language=java,breaklines=true,showspaces=false,showstringspaces=false,breakatwhitespace=true} + +\noindent \lstinputlisting{./src/RectangleMeasurer.java} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[allowframebreaks] +\frametitle{Using Rectangle Measurer} + +\lstset{language=java,breaklines=true,showspaces=false,showstringspaces=false,breakatwhitespace=true} + +\noindent \lstinputlisting{./src/DataSetStrategyTest.java} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[fragile] +\frametitle{ {\tt Comparable} Versus {\tt Comparator}} + +\begin{itemize} +\item Comparable similar UML diagram to Measurable +\item Comparator similar UML diagram to Measurer +\end{itemize} + +\begin{lstlisting} +public interface Comparable<T> +{ + int compareTo(T obj); +} +\end{lstlisting} + +\begin{lstlisting} +public interface Comparator<T> +{ + public int compare(T obj1, T obj2); +} +\end{lstlisting} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Interface Versus Abstract} +\begin{itemize} +\item \structure{What is the difference between an interface and an abstract class?} +\end{itemize} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +%\frametitle{Differences Between Interface and Abstract} +\begin{itemize} +\item Interface +\bi +\item Methods are implicitly abstract and public +\item Methods can have default implementation ( JDK 8) +\item Cannot have constructors +\item Variables are final +\item Can only extend interfaces +\item Classes can extend multiple instances +\item Appropriate for unrelated classes +\ei +\item Abstract class +\bi +\item At least one method is declared as abstract +\item Some methods can implement a default behaviour +\item Cannot instantiate them, but can have constructors +\item Variables are not necessarily final +\item Can extend other class +\item Can implement multiple interfaces +\item Classes can extend only one abstract class +\item Sharing code between closely related classes +\ei +\end{itemize} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{UML Diagram for Generic Classes} + +\includegraphics[scale=0.55]{../Figures/UML_class_diagram_template.png} + +\href{https://coderanch.com/t/626984/a/5041/UML_class_diagram_template.png}{UML + Class Diagram Template} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +%\frametitle{Use Cases} + +\includegraphics[scale=0.65]{../Figures/useCaseDiagram.jpg} + +\href{http://www.agilemodeling.com/artifacts/useCaseDiagram.htm}{UML + 2 Use Case Diagrams: An Agile Introduction} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Use Cases} + +\bi +\item Often used for capturing requirements +\item From user's (actor's) viewpoint +\bi +\item Person +\item Other system +\item Hardware +\item etc. (anything external +\ei +\item Each circle is a use case +\item Lines represent possible interactions +\item An actor represents a role, individuals can take on different roles +\ei + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[plain] +%\frametitle{Use Cases} + +\includegraphics[scale=0.45]{../Figures/buying_3.jpg} + +\href{http://people.cs.ksu.edu/~reshma/buying_3.JPG}{Sequence Diagram For + On-Line Shopping} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Sequence Diagram Question} + +\bi +\item \structure{Is a sequence diagram an operational or a descriptive + specification?} +\item \structure{If objects exchange a message, should there be an association + between their classes?} +\ei + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Sequence Diagrams} + +\bi +\item Represents a specific use case scenario +\item How objects interact by exchanging messages +\item Time progresses in the vertical direction +\item The vertically oriented boxes show the object's lifeline +\ei + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\end{document} + diff --git a/Lectures/OLD_SpecViaUMLWithJava/src/BankAccount.java b/Lectures/OLD_SpecViaUMLWithJava/src/BankAccount.java new file mode 100644 index 0000000000000000000000000000000000000000..9c9b10e6e696bd925d7ae028114f65e8e5ab708f --- /dev/null +++ b/Lectures/OLD_SpecViaUMLWithJava/src/BankAccount.java @@ -0,0 +1,13 @@ +public class BankAccount +{ + private double balance; + + public BankAccount() + { balance = 0;} + public void deposit(double amount) + { balance = balance + amount;} + public void withdraw(double amount) + { balance = balance - amount;} + public double getBalance() + { return balance;} +} \ No newline at end of file diff --git a/Lectures/OLD_SpecViaUMLWithJava/src/BankAccountInterface.java b/Lectures/OLD_SpecViaUMLWithJava/src/BankAccountInterface.java new file mode 100644 index 0000000000000000000000000000000000000000..4567091b968c6e34d9a3975fa114b6f0d51a7a64 --- /dev/null +++ b/Lectures/OLD_SpecViaUMLWithJava/src/BankAccountInterface.java @@ -0,0 +1,12 @@ +public class BankAccountInterface implements Measurable +{ private double balance; + public BankAccountInterface() + { balance = 0; + } + //.. + public double getBalance() + { return balance; + } + public double getMeasure() + { return balance;} +} \ No newline at end of file diff --git a/Lectures/OLD_SpecViaUMLWithJava/src/DataSet.java b/Lectures/OLD_SpecViaUMLWithJava/src/DataSet.java new file mode 100644 index 0000000000000000000000000000000000000000..2aea56d528a0da5b76dc4e5f088bdd71b85174a9 --- /dev/null +++ b/Lectures/OLD_SpecViaUMLWithJava/src/DataSet.java @@ -0,0 +1,27 @@ +public class DataSet +{ + private double sum; + private double maximum; + private int count; + + public DataSet() + { + sum = 0; + count = 0; + maximum = 0; + } + public void add(double x) + { + sum = sum + x; + if (count == 0 || maximum < x) maximum = x; + count++; + } + public double getAverage() + { + if (count == 0) return 0; + else return sum/count; + } + public double getMaximum() + { return maximum; + } +} \ No newline at end of file diff --git a/Lectures/OLD_SpecViaUMLWithJava/src/DataSetBankAccount.java b/Lectures/OLD_SpecViaUMLWithJava/src/DataSetBankAccount.java new file mode 100644 index 0000000000000000000000000000000000000000..2b5e7ed377b59c260282bd6dd0e5a987d47bc297 --- /dev/null +++ b/Lectures/OLD_SpecViaUMLWithJava/src/DataSetBankAccount.java @@ -0,0 +1,26 @@ +public class DataSetBankAccount +{ + private double sum; + private BankAccount maximum; + private int count; + + public DataSetBankAccount() + { + sum = 0; + count = 0; + maximum = null; + } + public void add(BankAccount x) + { + sum = sum + x.getBalance(); + if (count == 0 || maximum.getBalance() < x.getBalance()) maximum = x; + count++; + } + public double getAverage() + { if (count == 0) return 0; + else return sum/count; + } + public BankAccount getMaximum() + { return maximum; + } +} \ No newline at end of file diff --git a/Lectures/OLD_SpecViaUMLWithJava/src/DataSetInterface.java b/Lectures/OLD_SpecViaUMLWithJava/src/DataSetInterface.java new file mode 100644 index 0000000000000000000000000000000000000000..7f0a3895fd34f93d326ebbb557d9a90bf610e419 --- /dev/null +++ b/Lectures/OLD_SpecViaUMLWithJava/src/DataSetInterface.java @@ -0,0 +1,26 @@ +public class DataSetInterface +{ + private double sum; + private Measurable* maximum; + private int count; + + public DataSetInterface() + { + sum = 0; + count = 0; + maximum = null; + } + public void add(Measurable x) + { + sum = sum + x.getMeasure(); + if (count == 0 || maximum.getMeasure() < x.getMeasure()) maximum = x; + count++; + } + public double getAverage() + { if (count == 0) return 0; + else return sum/count; + } + public Measurable getMaximum() + { return maximum; + } +} diff --git a/Lectures/OLD_SpecViaUMLWithJava/src/DataSetPoint.java b/Lectures/OLD_SpecViaUMLWithJava/src/DataSetPoint.java new file mode 100644 index 0000000000000000000000000000000000000000..fdfb98bd7975340f1c568f15d31ef50196d85dd4 --- /dev/null +++ b/Lectures/OLD_SpecViaUMLWithJava/src/DataSetPoint.java @@ -0,0 +1,25 @@ +public class DataSetPoint +{ + private double sum; + private PointT maximum; + private int count; + public DataSetPoint() + { sum = 0; + count = 0; + maximum = null; + } + public void add(PointT x) + { + sum = sum + x.distToOrigin(); + if (count == 0 || maximum.distToOrigin() < x.distToOrigin()) maximum = x; + count++; + } + public double getAverage() + { if (count == 0) return 0; + else return sum/count; + } + public PointT getMaximum() + { + return maximum; + } +} \ No newline at end of file diff --git a/Lectures/OLD_SpecViaUMLWithJava/src/DataSetStrategy.java b/Lectures/OLD_SpecViaUMLWithJava/src/DataSetStrategy.java new file mode 100644 index 0000000000000000000000000000000000000000..bbddd8196b1c9f5fba398c15fde86c4adc142b2e --- /dev/null +++ b/Lectures/OLD_SpecViaUMLWithJava/src/DataSetStrategy.java @@ -0,0 +1,25 @@ +public class DataSetStrategy +{ private double sum; + private Object maximum; + private int count; + private Measurer measurer; + public DataSetStrategy(Measurer aMeasurer) + { sum = 0; + count = 0; + maximum = null; + measurer = aMeasurer; + } + public void add(Object x) + { + sum = sum + measurer.measure(x); + if (count == 0 || measurer.measure(maximum) < measurer.measure(x)) maximum = x; + count++; + } + public double getAverage() + { if (count == 0) return 0; + else return sum/count; + } + public Object getMaximum() + { return maximum; + } +} \ No newline at end of file diff --git a/Lectures/OLD_SpecViaUMLWithJava/src/DataSetStrategyTest.java b/Lectures/OLD_SpecViaUMLWithJava/src/DataSetStrategyTest.java new file mode 100644 index 0000000000000000000000000000000000000000..2febfa5d261086af5288a4e67f776ddf32c57a36 --- /dev/null +++ b/Lectures/OLD_SpecViaUMLWithJava/src/DataSetStrategyTest.java @@ -0,0 +1,23 @@ +import java.awt.Rectangle; +public class DataSetStrategyTest +{ + public static void main(String[] args) + { + class RectangleMeasurer implements Measurer + { + public double measure(Object anObject) + { + Rectangle aRectangle = (Rectangle) anObject; + double area = aRectangle.getWidth() * aRectangle.getHeight(); + return area; + } + } + Measurer m = new RectangleMeasurer(); + DataSetStrategy data = new DataSetStrategy(m); + data.add(new Rectangle(5, 10, 20, 30)); + data.add(new Rectangle(10, 20, 30, 40)); + System.out.println("Average area = " + data.getAverage()); + Rectangle max = (Rectangle) data.getMaximum(); + System.out.println("Maximum area = " + m.measure(max)); + } +} \ No newline at end of file diff --git a/Lectures/OLD_SpecViaUMLWithJava/src/DataSetTest.java b/Lectures/OLD_SpecViaUMLWithJava/src/DataSetTest.java new file mode 100644 index 0000000000000000000000000000000000000000..2963e8dd0cd02d1f9873ceffc0c473b54f98d328 --- /dev/null +++ b/Lectures/OLD_SpecViaUMLWithJava/src/DataSetTest.java @@ -0,0 +1,19 @@ +public class DataSetTest +{ public static void main(String[] args) + { DataSetInterface bankData = new DataSetInterface(); + bankData.add(new BankAccountInterface()); + BankAccountInterface b = new BankAccountInterface(); + b.deposit(134.56); + bankData.add(b); + System.out.println("Average balance = " + bankData.getAverage()); + Measurable max = bankData.getMaximum(); + System.out.println("Highest balance = " + max.getMeasure()); + DataSetInterface pointData = new DataSetInterface(); + pointData.add(new PointTInterface(1.0, 1.0)); + pointData.add(new PointTInterface(2.0, 2.0)); + pointData.add(new PointTInterface(3.0, 3.0)); + System.out.println("Average distance to origin = " + pointData.getAverage()); + max = pointData.getMaximum(); + System.out.println("Greatest distance to origin = " + max.getMeasure()); + } +} \ No newline at end of file diff --git a/Lectures/OLD_SpecViaUMLWithJava/src/Measurable.java b/Lectures/OLD_SpecViaUMLWithJava/src/Measurable.java new file mode 100644 index 0000000000000000000000000000000000000000..fb4b5d41b04585a08b5452c770dbd6de034b5e63 --- /dev/null +++ b/Lectures/OLD_SpecViaUMLWithJava/src/Measurable.java @@ -0,0 +1,4 @@ +public interface Measurable +{ + double getMeasure(); +} \ No newline at end of file diff --git a/Lectures/OLD_SpecViaUMLWithJava/src/Measurer.java b/Lectures/OLD_SpecViaUMLWithJava/src/Measurer.java new file mode 100644 index 0000000000000000000000000000000000000000..720a9e14bfbdd10eced0f123935a4e94cffb114e --- /dev/null +++ b/Lectures/OLD_SpecViaUMLWithJava/src/Measurer.java @@ -0,0 +1,4 @@ +public interface Measurer +{ + double measure(Object anObject); +} \ No newline at end of file diff --git a/Lectures/OLD_SpecViaUMLWithJava/src/PointT.java b/Lectures/OLD_SpecViaUMLWithJava/src/PointT.java new file mode 100644 index 0000000000000000000000000000000000000000..d1261c564b675207d1ab3ebf3efaca25ebeba800 --- /dev/null +++ b/Lectures/OLD_SpecViaUMLWithJava/src/PointT.java @@ -0,0 +1,12 @@ +import static java.lang.Math.*; +public class PointT { + private double xc; + private double yc; + public PointT(double x, double y) { + xc = x; + yc = y;} + // .. + public double distToOrigin() { + return sqrt(pow(xc,2.0) + pow(yc,2.0)); + } +} \ No newline at end of file diff --git a/Lectures/OLD_SpecViaUMLWithJava/src/PointTInterface.java b/Lectures/OLD_SpecViaUMLWithJava/src/PointTInterface.java new file mode 100644 index 0000000000000000000000000000000000000000..af637f83f4b242e51b62167ad198891101b5fac5 --- /dev/null +++ b/Lectures/OLD_SpecViaUMLWithJava/src/PointTInterface.java @@ -0,0 +1,17 @@ +import static java.lang.Math.*; +public class PointTInterface implements Measurable +{ + private double xc; + private double yc; + public PointTInterface(double x, double y) { + xc = x; + yc = y; + } + //.. + public double distToOrigin() { + return sqrt(pow(xc,2.0) + pow(yc,2.0)); + } + public double getMeasure(){ + return distToOrigin(); + } +} \ No newline at end of file diff --git a/Lectures/OLD_SpecViaUMLWithJava/src/RectangleMeasurer.java b/Lectures/OLD_SpecViaUMLWithJava/src/RectangleMeasurer.java new file mode 100644 index 0000000000000000000000000000000000000000..c6e4e5b2748094712abf028b8f9f71bb58f56d28 --- /dev/null +++ b/Lectures/OLD_SpecViaUMLWithJava/src/RectangleMeasurer.java @@ -0,0 +1,10 @@ +import java.awt.Rectangle; +class RectangleMeasurer implements Measurer +{ + public double measure(Object anObject) + { + Rectangle aRectangle = (Rectangle) anObject; + double area = aRectangle.getWidth() * aRectangle.getHeight(); + return area; + } +} \ No newline at end of file diff --git a/Lectures/OLD_SpecViaUMLWithJava/src/TestArraysSortComparable.java b/Lectures/OLD_SpecViaUMLWithJava/src/TestArraysSortComparable.java new file mode 100644 index 0000000000000000000000000000000000000000..9b3bce3fa5d7439814f19253f6fba5c80a97526f --- /dev/null +++ b/Lectures/OLD_SpecViaUMLWithJava/src/TestArraysSortComparable.java @@ -0,0 +1,26 @@ +import java.util.Arrays; +public class TestArraysSortComparable +{ public static void main(String [] args) + { PointT[] p = new PointT[6]; + p[0] = new PointT(0.0, 0.0); + p[1] = new PointT(10.0, 30.0); + p[2] = new PointT(4.0, 15.0); + p[3] = new PointT(41.0, 7.0); + p[4] = new PointT(9.0, 70.0); + System.out.println("p[0] compared to p[1]: " + p[0].compareTo(p[1])); + PrintPath(p, 6); + Arrays.sort(p); + PrintPath(p, 6); + } + private static void PrintPath(PointT[] pl, int n) + { int i; + PointT p; + System.out.println(); + System.out.println("i" + "\t" + "xcoord" + "\t" + "ycoord"); + for (i = 0; i < n; i++) + { p = pl[i]; + System.out.println(i + "\t" + p.xcoord() + "\t" + p.ycoord()); + } + System.out.println(); + } +} \ No newline at end of file