Commit 34c2faf2 authored by antony.adewunmi-jones's avatar antony.adewunmi-jones

Revert "commit 1"

This reverts commit 7d917a08
parent 7d917a08
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
No preview for this file type
## Assessment Exercise 2 - Shapes
## 1 Skills
This exercise should help you with:
1. Member variables and member methods.
2. Unit testing.
3. Inheritance
4. Encapsulation
5. Abstraction
## 2 Shapes
The code in this project contains an abstract class `Shape` used to define the methods any shape class must possess (see the Inheritance section of the module website).
I've created a `Triangle` class as an example shape for you.
## 3 Unit Testing
This project is set up with unit testing enabled. Unit testing is a development technique where tests can be created in advance and used to help ensure the code is corrent when it is written. See Assessment Exercise 1 for more details on Unit Testing.
## 4 Task
You need to create to classes which inherit (`extend`) from `Shape`. These are
* `Square`
* `Rectangle`
### `Square`
The `Square` class should store the information and methods related to a square shape.
1. `size` should be used to represent the width and height of the square.
2. `Square` should have two constructors. The first should have no parameters and set the size equal to 3. The second should take a single integer parameter and use it to set the size.
3. You should be able to use the `getSize()` and `setSize()` methods properly for the `Square`.
4. You should correctly implement the `area()` and `circumference()` methods for `Square`.
5. You should implement a `draw()` method that will output an ascii square of the correct size.
6. All the Square unit tests must be passed.
### `Rectangle`
The `Rectangle` class should store the information and methods related to a Rectangle shape.
1. Instead of using `size` you should use `width` and `hieght` to represent the width and height of the rectangle.
2. `Rectangle` should have two constructors. The first should have no parameters and set the `width` equal to 3 and the `height` equal to 4. The second should take a two integer parameter and uses them to set the `width` and `height` (in that order).
3. You should be able to use the `getWidth()` and `setWidth()` methods properly for the `Rectangle`.
4. You should be able to use the `getHeight()` and `setHeight()` methods properly for the `Rectangle`.
5. You should correctly implement the `area()` and `circumference()` methods for `Rectangle`.
6. You should implement a `draw()` method that will output an ascii rectangle of the correct size.
7. All the Rectangle unit tests must be passed.
## 5 Marking
25 marks are available for this exercise. This breaks down as follows.
### `Square` (10 Marks)
* constructors - 2 marks
* setSize(), getSize() - 2 marks
* area(), circumference() - 2 marks
* draw() - 2 marks
* Pass all Square Unit Tests - 2 marks
### `Rectangle` (15 Marks)
* constructors - 3 marks
* setWidth(), getWidth(), setHeight(), getHeight() - 3 marks
* area(), circumference() - 3 marks
* draw() - 3 marks
* Pass all Square Unit Tests - 3 marks
## 6 Submission
Your project should be uploaded to your gitlab account and you should submit a link to the gitlab project, alongside the rest of the assessment, through moodle, by 12noon 16/05/22.
\ No newline at end of file
File added
public class App {
public static void main(String[] args) throws Exception {
//Shape shape1 = new Triangle(3);
//shape1.draw();
Shape shape1 = new Triangle(3);
shape1.draw();
Shape shape2 = new Square(4);
shape2.draw();
Shape shape3 = new Rectangle(3, 4);
shape3.draw();
}
}
abstract public class BankAccount {
protected int accountNumber, depositAmount, withdrawalAmount, overdraft;
protected double balance;
protected String name;
public BankAccount(){
this.accountNumber = 0000000000;
this.balance = 0.00;
this.name = "John Doe";}
public BankAccount(int accountNumber, double balance, String name){
this.accountNumber = accountNumber;
this.balance = balance;
this.name = name; }
public int deposit(int balance, int depositAmount){
balance = balance + depositAmount;
System.out.println(balance);
return balance;
}
public int withdrawal(int balance, int withdrawalAmount){
if (balance > withdrawalAmount){
balance = balance - withdrawalAmount;
}
else if (withdrawalAmount< balance + overdraft){
withdrawalAmount = withdrawalAmount - balance;
balance = 0;
overdraft = overdraft - withdrawalAmount;
}
return balance;
}
public int bankFees(int balance){
int fees = balance / 5;
balance = balance - fees;
return balance;
}
public void display(){
System.out.println("Name: "+ name);
System.out.println("Account number: "+ accountNumber);
System.out.println("Balance: "+ balance);
}
public int addOverdraft(int balance, int overdraft){
int newOverdraft = this.overdraft;
return newOverdraft;
}
}
## Assessment Exercise 2 - Shapes
## 1 Skills
This exercise should help you with:
1. Member variables and member methods.
2. Unit testing.
3. Inheritance
4. Encapsulation
5. Abstraction
## 2 Shapes
The code in this project contains an abstract class `Shape` used to define the methods any shape class must possess (see the Inheritance section of the module website).
I've created a `Triangle` class as an example shape for you.
## 3 Unit Testing
This project is set up with unit testing enabled. Unit testing is a development technique where tests can be created in advance and used to help ensure the code is corrent when it is written. See Assessment Exercise 1 for more details on Unit Testing.
## 4 Task
You need to create to classes which inherit (`extend`) from `Shape`. These are
* `Square`
* `Rectangle`
### `Square`
The `Square` class should store the information and methods related to a square shape.
1. `size` should be used to represent the width and height of the square.
2. `Square` should have two constructors. The first should have no parameters and set the size equal to 3. The second should take a single integer parameter and use it to set the size.
3. You should be able to use the `getSize()` and `setSize()` methods properly for the `Square`.
4. You should correctly implement the `area()` and `circumference()` methods for `Square`.
5. You should implement a `draw()` method that will output an ascii square of the correct size.
6. All the Square unit tests must be passed.
### `Rectangle`
The `Rectangle` class should store the information and methods related to a Rectangle shape.
1. Instead of using `size` you should use `width` and `hieght` to represent the width and height of the rectangle.
2. `Rectangle` should have two constructors. The first should have no parameters and set the `width` equal to 3 and the `height` equal to 4. The second should take a two integer parameter and uses them to set the `width` and `height` (in that order).
3. You should be able to use the `getWidth()` and `setWidth()` methods properly for the `Rectangle`.
4. You should be able to use the `getHeight()` and `setHeight()` methods properly for the `Rectangle`.
5. You should correctly implement the `area()` and `circumference()` methods for `Rectangle`.
6. You should implement a `draw()` method that will output an ascii rectangle of the correct size.
7. All the Rectangle unit tests must be passed.
## 5 Marking
25 marks are available for this exercise. This breaks down as follows.
### `Square` (10 Marks)
* constructors - 2 marks
* setSize(), getSize() - 2 marks
* area(), circumference() - 2 marks
* draw() - 2 marks
* Pass all Square Unit Tests - 2 marks
### `Rectangle` (15 Marks)
* constructors - 3 marks
* setWidth(), getWidth(), setHeight(), getHeight() - 3 marks
* area(), circumference() - 3 marks
* draw() - 3 marks
* Pass all Square Unit Tests - 3 marks
## 6 Submission
Your project should be uploaded to your gitlab account and you should submit a link to the gitlab project, alongside the rest of the assessment, through moodle, by 12noon 16/05/22.
\ No newline at end of file
//import java.util.Scanner;
public class Rectangle extends Shape{
int width, height;
public Rectangle() {
width = 3;
height = 4;
}
public Rectangle(int W, int H ) {
width = W;
height = H;
}
@Override
public int getWidth(){
int gWidth = width;
return gWidth;
}
@Override
public void setWidth(int sWidth){
width = sWidth;
}
@Override
public int getHeight(){
int gHeight = height;
return gHeight;
}
@Override
public void setHeight(int sHeight){
height = sHeight;
}
@Override
public void draw() {
//System.out.print(size);
//Top row
for (int loopA = 0; loopA < width; loopA++){
System.out.print("---");
}
System.out.println("");
//Left wall
for (int loopB = 0; loopB < height; loopB++){
System.out.print("|");
//Middle gap
for (int loopC = 0; loopC < width-2; loopC++){
System.out.print(" ");
}
//Right wall
System.out.println("|");
}
//Bottom
for (int loopA = 0; loopA < width; loopA++){
System.out.print("---");
}
}
@Override
public float area() {
float area = width * height;
return area;
}
@Override
public float circumference() {
float circ = (width*2) + (height*2);
return circ;
}
}
File added
abstract public class Shape {
protected int size;
protected int width;
protected int height;
abstract public void draw();
abstract public float area();
abstract public float circumference();
public int getSize() { return size; }
public void setSize(int size) { this.size = size; }
public int getWidth() { return width; }
public void setWidth(int width) { this.width = width; }
public int getHeight() { return height; }
public void setHeight(int height) { this.height = height; }
public Shape(){
this.size = 3;
}
public Shape(int size){
this.size = size;
}
}
//import java.util.Scanner;
public class Square extends Shape{
public Square() {
size = 3;
}
public Square(int i) {
size = i;
}
@Override
public int getSize(){
int sqSize = size;
return sqSize;
}
@Override
public void setSize(int sqrSize){
size = sqrSize;
}
@Override
public void draw() {
//System.out.print(size);
//Top row
for (int loopA = 0; loopA < size; loopA++){
System.out.print("---");
}
System.out.println("");
//Left wall
for (int loopB = 0; loopB < size; loopB++){
System.out.print("|");
//Middle gap
for (int loopC = 0; loopC < size-2; loopC++){
System.out.print(" ");
}
//Right wall
System.out.println("|");
}
//Bottom
for (int loopA = 0; loopA < size; loopA++){
System.out.print("---");
}
}
@Override
public float area() {
float aSize = size;
float area = aSize * aSize;
return area;
}
@Override
public float circumference() {
float aSize = size;
float circ = aSize * 4;
return circ;
}
}
public class Triangle extends Shape{
// An equilateral triangle
public Triangle() {
super();
}
public Triangle(int i) {
super(i);
}
@Override
public void draw() {
for (int loop1=0; loop1<size; loop1++){
for (int loop2=loop1; loop2<(size-1); loop2++) {
System.out.print(" ");
}
System.out.print("/");
for (int loop2=0; loop2<loop1; loop2++){
System.out.print(" ");
}
System.out.println("\\");
}
for (int loop1=0; loop1<size; loop1++){
System.out.print("--");
}
System.out.println("");
}
@Override
public float area() {
float fSize = size;
float area = 0.5f * fSize * fSize;
return area;
}
@Override
public float circumference() {
float fSize = size;
float circ = fSize + fSize +fSize;
return circ;
}
}
public class savings_account extends BankAccount{
public int addOverdraft(int overdraft){
//not allowed for savings account
overdraft = 0;
return overdraft;
}
public int accrueIntrest(int balance){
int intrest = balance / 20;
balance = balance + intrest;
return balance;
}
}
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class unitTest {
// *********************************
// Triangle Tests
// *********************************
@Test
public void testTriangleConstructor() {
// test default constructor
Shape testShape = new Triangle();
assertEquals(3, testShape.getSize());
// test constructor with size parameter
testShape = new Triangle(5);
assertEquals(5, testShape.getSize());
}
@Test
public void testTriangleSize() {
// test setSize()
Shape testShape = new Triangle(5);
testShape.setSize(6);
assertEquals(6, testShape.getSize());
}
@Test
public void testTriangleCircumference() {
// test circumference()
Shape testShape = new Triangle(6);
assertEquals(18.0, testShape.circumference(), 1e-6);
}
@Test
public void testTriangleArea() {
// test area()
Shape testShape = new Triangle(6);
assertEquals(18.0, testShape.area(), 1e-6);
}
// *********************************
// Square Tests
// *********************************
@Test
public void testSquareConstructor() {
// test default constructor
Shape testShape = new Square();
assertEquals(3, testShape.getSize());
// test constructor with size parameter
testShape = new Square(5);
assertEquals(5, testShape.getSize());
}
@Test
public void testSquareSize() {
// test setSize()
Shape testShape = new Square(5);
testShape.setSize(6);
assertEquals(6, testShape.getSize());
}
@Test
public void testSquareCircumference() {
// test circumference()
Shape testShape = new Square(6);
assertEquals(24.0, testShape.circumference(), 1e-6);
}
@Test
public void testSquareArea() {
// test area()
Shape testShape = new Square(5);
assertEquals(25.0, testShape.area(), 1e-6);
}
// *********************************
// Square Tests
// *********************************
@Test
public void testRectangleConstructor() {
// test default constructor
Shape testShape = new Rectangle();
assertEquals(3, testShape.getWidth());
assertEquals(4, testShape.getHeight());
// test constructor with size parameter
testShape = new Rectangle(5,6);
assertEquals(5, testShape.getWidth());
assertEquals(6, testShape.getHeight());
}
@Test
public void testRectangleWidth() {
// test setSize()
Shape testShape = new Rectangle(5,4);
testShape.setWidth(6);
assertEquals(6, testShape.getWidth());
}
@Test
public void testRectangleHeight() {
// test setSize()
Shape testShape = new Rectangle(7,8);
testShape.setHeight(3);
assertEquals(3, testShape.getHeight());
}
@Test
public void testRectangleCircumference() {
// test circumference()
Shape testShape = new Rectangle(6,3);
assertEquals(18.0, testShape.circumference(), 1e-6);
}
@Test
public void testRectangleArea() {
// test area()
Shape testShape = new Rectangle(5,7);
assertEquals(35.0, testShape.area(), 1e-6);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment