Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
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
## Folder Structure
The workspace contains two folders by default, where:
The workspace contains two folders by default, where:
-`src`: the folder to maintain sources
-`src`: the folder to maintain sources
-`lib`: the folder to maintain dependencies
-`lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
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.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
## 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).
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).
3. Creation of a class to a specification without necessarily understanding the details.
3. Creation of a class to a specification without necessarily understanding the details.
## 2 Background
## 2 Background
A complex number is one that has two parts: **real** and **imaginary**. They are written (by engineers at least) like this
A complex number is one that has two parts: **real** and **imaginary**. They are written (by engineers at least) like this
* 4.1 + j9.9
* 4.1 + j9.9
* 0.5 + j3.2
* 0.5 + j3.2
Or in general
Or in general
* a + *j*b
* a + *j*b
There are a few operations defined for complex numbers. If a complex number has a real part called **a** and an imaginary part called **b** we have
There are a few operations defined for complex numbers. If a complex number has a real part called **a** and an imaginary part called **b** we have
***magnitude** = square root of (**a** squared + **b** squared) (using `Math.sqrt()` in java)
***magnitude** = square root of (**a** squared + **b** squared) (using `Math.sqrt()` in java)
***argument** = tan−1(b/a) (using `Math.atan2(b,a)` in Java)
***argument** = tan−1(b/a) (using `Math.atan2(b,a)` in Java)
**Addition**
**Addition**
To add two complex numbers we add the real parts to give the new real part and the imaginary parts to give the new imaginary part.
To add two complex numbers we add the real parts to give the new real part and the imaginary parts to give the new imaginary part.
CN1 = a +*j*b
CN1 = a +*j*b
CN2 = c +*j*d
CN2 = c +*j*d
CN1 + CN2 = (a+c) + *j*(b+d)
CN1 + CN2 = (a+c) + *j*(b+d)
## 3 Unit Testing
## 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.
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.
Click on the `Testing` icon in the left hand tool bar. It looks like a flask. Open up `javaAssessEx1`, then `<Default Package>`, then `AppTest`. You should now see a list of tests.
Click on the `Testing` icon in the left hand tool bar. It looks like a flask. Open up `javaAssessEx1`, then `<Default Package>`, then `AppTest`. You should now see a list of tests.
* testConstructor()
* testConstructor()
* testMagnitude()
* testMagnitude()
* testArgument()
* testArgument()
* testAdd()
* testAdd()
* testToString()
* testToString()
You can right click on `AppTest` and choose `Run Test` to run all the tests or you can run each test individually by right clicking on each one and choosing `Run Test`.
You can right click on `AppTest` and choose `Run Test` to run all the tests or you can run each test individually by right clicking on each one and choosing `Run Test`.
## 4 Task
## 4 Task
You need to complete the following methods.
You need to complete the following methods.
* public double magnitude()
* public double magnitude()
* public double argument()
* public double argument()
* public String toString()
* public String toString()
* public Complex add(Complex complexNum)
* public Complex add(Complex complexNum)
Looking at the tests in AppTest.java might help you see how these methods will be used. Section 2 above will show you how to calculate the magnitude and argument and how to add two complex numbers together.
Looking at the tests in AppTest.java might help you see how these methods will be used. Section 2 above will show you how to calculate the magnitude and argument and how to add two complex numbers together.
`toString()` should return a string in the format `a + jb` where `a` is the real component and `b` is the imaginary component. Note the rules below should be followed.
`toString()` should return a string in the format `a + jb` where `a` is the real component and `b` is the imaginary component. Note the rules below should be followed.
|Real Part|Imaginary Part|String|
|Real Part|Imaginary Part|String|
|---|---|---|
|---|---|---|
|`2.6`|`5.2`|`2.6 + j5.6`|
|`2.6`|`5.2`|`2.6 + j5.6`|
|`2.6`|`0`|`2.6`|
|`2.6`|`0`|`2.6`|
|`0`|`5.2`|`j5.2`|
|`0`|`5.2`|`j5.2`|
|`2.6`|`-9.8`|`2.6 - j9.8`|
|`2.6`|`-9.8`|`2.6 - j9.8`|
If the real or imaginary part is 0 it should not be shown. If the imaginary part is negative the negative symbol should be before the j not the number (i.e. `4.3 - j2.1` not `4.3 + j-2.1`).
If the real or imaginary part is 0 it should not be shown. If the imaginary part is negative the negative symbol should be before the j not the number (i.e. `4.3 - j2.1` not `4.3 + j-2.1`).
If you have completed the methods correctly all the unit tests will pass. Please note that hardcoding the methods to return the correct answers for the tests carried out in the unit tests you will get zero marks.
If you have completed the methods correctly all the unit tests will pass. Please note that hardcoding the methods to return the correct answers for the tests carried out in the unit tests you will get zero marks.
## 5 Marking
## 5 Marking
25 marks are available for this exercise. This breaks down as follows.
25 marks are available for this exercise. This breaks down as follows.
* public double magnitude() - 5 marks
* public double magnitude() - 5 marks
* public double argument() - 5 marks
* public double argument() - 5 marks
* public String toString() - 10 marks
* public String toString() - 10 marks
* public Complex add(Complex complexNum) - 5 marks
* public Complex add(Complex complexNum) - 5 marks
## 6 Submission
## 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 12 noon 16/05/22.
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 12 noon 16/05/22.
3. Creation of a class to a specification without necessarily understanding the details.
3. Creation of a class to a specification without necessarily understanding the details.
## 2 Background
## 2 Background
A complex number is one that has two parts: **real** and **imaginary**. They are written (by engineers at least) like this
A complex number is one that has two parts: **real** and **imaginary**. They are written (by engineers at least) like this
* 4.1 + j9.9
* 4.1 + j9.9
* 0.5 + j3.2
* 0.5 + j3.2
Or in general
Or in general
* a + *j*b
* a + *j*b
There are a few operations defined for complex numbers. If a complex number has a real part called **a** and an imaginary part called **b** we have
There are a few operations defined for complex numbers. If a complex number has a real part called **a** and an imaginary part called **b** we have
***magnitude** = square root of (**a** squared + **b** squared) (using `Math.sqrt()` in java)
***magnitude** = square root of (**a** squared + **b** squared) (using `Math.sqrt()` in java)
***argument** = tan−1(b/a) (using `Math.atan2(b,a)` in Java)
***argument** = tan−1(b/a) (using `Math.atan2(b,a)` in Java)
**Addition**
**Addition**
To add two complex numbers we add the real parts to give the new real part and the imaginary parts to give the new imaginary part.
To add two complex numbers we add the real parts to give the new real part and the imaginary parts to give the new imaginary part.
CN1 = a +*j*b
CN1 = a +*j*b
CN2 = c +*j*d
CN2 = c +*j*d
CN1 + CN2 = (a+c) + *j*(b+d)
CN1 + CN2 = (a+c) + *j*(b+d)
## 3 Unit Testing
## 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.
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.
Click on the `Testing` icon in the left hand tool bar. It looks like a flask. Open up `javaAssessEx1`, then `<Default Package>`, then `AppTest`. You should now see a list of tests.
Click on the `Testing` icon in the left hand tool bar. It looks like a flask. Open up `javaAssessEx1`, then `<Default Package>`, then `AppTest`. You should now see a list of tests.
* testConstructor()
* testConstructor()
* testMagnitude()
* testMagnitude()
* testArgument()
* testArgument()
* testAdd()
* testAdd()
* testToString()
* testToString()
You can right click on `AppTest` and choose `Run Test` to run all the tests or you can run each test individually by right clicking on each one and choosing `Run Test`.
You can right click on `AppTest` and choose `Run Test` to run all the tests or you can run each test individually by right clicking on each one and choosing `Run Test`.
## 4 Task
## 4 Task
You need to complete the following methods.
You need to complete the following methods.
* public double magnitude()
* public double magnitude()
* public double argument()
* public double argument()
* public String toString()
* public String toString()
* public Complex add(Complex complexNum)
* public Complex add(Complex complexNum)
Looking at the tests in AppTest.java might help you see how these methods will be used. Section 2 above will show you how to calculate the magnitude and argument and how to add two complex numbers together.
Looking at the tests in AppTest.java might help you see how these methods will be used. Section 2 above will show you how to calculate the magnitude and argument and how to add two complex numbers together.
`toString()` should return a string in the format `a + jb` where `a` is the real component and `b` is the imaginary component. Note the rules below should be followed.
`toString()` should return a string in the format `a + jb` where `a` is the real component and `b` is the imaginary component. Note the rules below should be followed.
|Real Part|Imaginary Part|String|
|Real Part|Imaginary Part|String|
|---|---|---|
|---|---|---|
|`2.6`|`5.2`|`2.6 + j5.6`|
|`2.6`|`5.2`|`2.6 + j5.6`|
|`2.6`|`0`|`2.6`|
|`2.6`|`0`|`2.6`|
|`0`|`5.2`|`j5.2`|
|`0`|`5.2`|`j5.2`|
|`2.6`|`-9.8`|`2.6 - j9.8`|
|`2.6`|`-9.8`|`2.6 - j9.8`|
If the real or imaginary part is 0 it should not be shown. If the imaginary part is negative the negative symbol should be before the j not the number (i.e. `4.3 - j2.1` not `4.3 + j-2.1`).
If the real or imaginary part is 0 it should not be shown. If the imaginary part is negative the negative symbol should be before the j not the number (i.e. `4.3 - j2.1` not `4.3 + j-2.1`).
If you have completed the methods correctly all the unit tests will pass. Please note that hardcoding the methods to return the correct answers for the tests carried out in the unit tests you will get zero marks.
If you have completed the methods correctly all the unit tests will pass. Please note that hardcoding the methods to return the correct answers for the tests carried out in the unit tests you will get zero marks.
## 5 Marking
## 5 Marking
25 marks are available for this exercise. This breaks down as follows.
25 marks are available for this exercise. This breaks down as follows.
* public double magnitude() - 5 marks
* public double magnitude() - 5 marks
* public double argument() - 5 marks
* public double argument() - 5 marks
* public String toString() - 10 marks
* public String toString() - 10 marks
* public Complex add(Complex complexNum) - 5 marks
* public Complex add(Complex complexNum) - 5 marks
## 6 Submission
## 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 12 noon 16/05/22.
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 12 noon 16/05/22.