In this lab you will create small Java applications by using as reference an UML class diagram. Please consider following general notes before start implementing:
- toString() method when required will return a string like ClassName{attributeName1=attributeValue1,...,attributeNamen=attributeValuen}.
- Do not reuse (import) the same class in multiple exercises. Each exercise is standalone and should be resolved in its package.
Given the UML class diagram above, implement the corresponding Java program.
- Create Java class based on the diagram above.
- insertCard() method from ATM will compare received pin with the pin stored in card. If 2 pins match the card will be stored as attribute and will be used for executing transactions.
- removeCard() method will invalidate a previously inserted card by making the attribute null.
- Demonstrate the functionality of application in Exercise1 class main method.
- Create minimal unit tests for testing the behavior of the programm.
Note 1: Constructors and setter\getter methods are not represented in the diagram but can\should be implemented."
Note 2: You can add any extra methods if required.
Create an UML Use-Case diagram describing an ATM system. Save jpg use case diagram in /docs subfolder and display it in this readme file bellow.
>>>>insert use case diagram here<<<<
interface Playable {
void play();
}
class ColorVideo implements Playable {
private String fileName;
public ColorVideo(String fileName){
this.fileName = fileName;
loadFromDisk(fileName);
}
@Override
public void play() {
System.out.println("Play " + fileName);
}
private void loadFromDisk(String fileName){
System.out.println("Loading video..." + fileName);
}
}
class ProxyVideo implements Playable {
private ColorVideo video;
private String fileName;
public ProxyVideo(String fileName){
this.fileName = fileName;
}
@Override
public void play() {
if(video == null){
video = new ColorVideo(fileName);
}
video.play();
}
}
For the application above:
- create UML class diagram and display it bellow.
- add a new class BlackAndWhiteVideo which will display message "Play black and white video {name of the video}".
- add necessary changes in ProxyVideo class so that depending on a constructor argument given in this class the proxy to call either black and white or color playable video.
>>>>insert class diagram here<<<<
public interface Shape {
/**
* Draw a specific shape
*/
void draw();
}
public class Rectangle implements Shape {
@Override
public void draw() {
System.out.println("A rectangle is drawn");
}
}
public class RoundedRectangle implements Shape {
@Override
public void draw() {
System.out.println("A rounded rectangle is drawn");
}
}
public abstract class AbstractShapeFactory {
/**
* Get specific shape by type
* @param type - one of the values ("rectangle", "roundedRectangle", "square", "roundedSquare")
* @return instance of shape by desired type
*/
abstract Shape getShape(String type);
}
public class ShapeFactory extends AbstractShapeFactory {
@Override
Shape getShape(String type) {
if ("rectangle".equals(type)) {
return new Rectangle();
}
return null;
}
}
public class RoundedShapeFactory extends AbstractShapeFactory {
@Override
Shape getShape(String type) {
if ("roundedRectangle".equals(type)) {
return new RoundedRectangle();
}
return null;
}
}
public class ShapeFactoryProvider {
private ShapeFactoryProvider() {
}
/**
* Get an instance of {@link AbstractShapeFactory} based on <param>type</param>
* @param type - one of the values "normal" / "rounded"
* @return instance of type {@link AbstractShapeFactory}
*/
public static AbstractShapeFactory getShapeFactory(String type) {
if ("normal".equals(type)) {
return new ShapeFactory();
}
if ("rounded".equals(type)) {
return new RoundedShapeFactory();
}
return null;
}
}
public class Main {
public static void main(String[] args) {
AbstractShapeFactory roundedShapeFactory = ShapeFactoryProvider.getShapeFactory("rounded");
AbstractShapeFactory normalShapeFactory = ShapeFactoryProvider.getShapeFactory("normal");
// create instances
Shape rectangle = roundedShapeFactory.getShape("roundedRectangle");
Shape shape = normalShapeFactory.getShape("rectangle");
rectangle.draw();
shape.draw();
}
}
For the application above:
- create UML class diagram and display it bellow.
- add new two classes(Square and RoundedSquare) which will have their own implementation of draw method.
- adapt the current implementation in order to be able to create instances of these classes based on their type. Test the new functionality using Main class.
>>>>insert class diagram here<<<<