first commit

This commit is contained in:
Boris
2024-01-15 20:14:10 +00:00
commit 8c81ee28b7
3106 changed files with 474415 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
## Lecture 1 - Identifiers, Arithmetic and Boolean
- Internal format of the type is predefined for numerical data types. You cannot assign a higher precision variable to a lower precision variable.
```java
float pi = 3.14159; //invalid
float pi = 3.14159f; //valid
```
- float -> double
- double -/> float
## Lecture 2 (14:00)
### Arithmetic
- 4i/3i = 1 - Any remainder is discarded as they are both integers
- 4.0d/3.0d = 1.333333333… - This is an example of an overloaded operator
- When types are mixed, a process called **arithmetic promotion** takes place. Operand of the lower precision is converted to the higher precision type so that the evaluation can proceed on operands of the same type.
- This is carried out automatically and is an example of implicit type conversion.
#### Arithmetic Promotion
- If either operand is a double - other operand is converted to double
- else, if either operand is float, other operand is float
- else, if either operand is long, other operand is long
- else, converted to int
### Type Casting
- Explicitly converting one type to another
```java
double length = 151.4;
double height = 255.7;
int area = length * height; //invalid
```
- Values of length and height are large and we are not concerned about loss of precision. We can rewrite the last line as:
```java
double length = 151.4;
double height = 255.7;
area = (int) (length * height); //valid
```
- When converting a double or float, the value after the floating point are discarded, **truncated**. ex. (int) 2.99 = 2i.
### Boolean
```java
int i = 5;
boolean iPositive = i>0; //TRUE
```
- && - produces TRUE if both sides are true
- || - produces TRUE is one side is true.
### Object and Memory Diagrams
- null = nothing
```java
Account account;
```
- This causes a memory location to be reserved for account.
```java
account = new Account(100);
```
- This causes account to be instantiated with a balance of 100
```java
Account account;
account = new Account(250);
account = new Account(700);
```
- After declaration and execution of the first assignment, the state of the memory diagram is:
- Account => Account (Balance = 250) => Account ~~(Balance 250)~~ (Balance 700).
- This is an example of Garbage Collection.
- Read up to w5 slide 39.
Next homework next Wednesday. Based mainly on Homework 1.

View File

@@ -0,0 +1,12 @@
------------------------------------------------------------------------
This is the project README file. Here, you should describe your project.
Tell the reader (someone who does not know anything about this project)
all he/she needs to know. The comments should usually include at least:
------------------------------------------------------------------------
PROJECT TITLE:
PURPOSE OF PROJECT:
VERSION or DATE:
HOW TO START THIS PROJECT:
AUTHORS:
USER INSTRUCTIONS:

View File

@@ -0,0 +1,25 @@
#BlueJ package file
objectbench.height=76
objectbench.width=686
package.editor.height=400
package.editor.width=560
package.editor.x=20
package.editor.y=51
package.numDependencies=0
package.numTargets=1
package.showExtends=true
package.showUses=true
project.charset=UTF-8
target1.editor.height=700
target1.editor.width=900
target1.editor.x=491
target1.editor.y=190
target1.height=50
target1.name=test
target1.naviview.expanded=true
target1.showInterface=false
target1.type=ClassTarget
target1.typeParameters=
target1.width=80
target1.x=70
target1.y=10

Binary file not shown.

View File

@@ -0,0 +1,10 @@
#BlueJ class context
comment0.params=
comment0.target=int\ modify()
comment1.params=
comment1.target=test()
comment1.text=\n\ Constructor\ for\ objects\ of\ class\ test\n
comment2.params=
comment2.target=float\ sampleMethod()
comment2.text=\n\ An\ example\ of\ a\ method\ -\ replace\ this\ comment\ with\ your\ own\n\ \n\ @param\ \ y\ \ \ a\ sample\ parameter\ for\ a\ method\n\ @return\ \ \ \ \ the\ sum\ of\ x\ and\ y\ \n
numComments=3

View File

@@ -0,0 +1,47 @@
/**
* Write a description of class test here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class test
{
// instance variables - replace the example below with your own
private int sum1, sum2;
private float number;
private double total;
public void modify( int num )
{
num = 10;
System.out.println( num );
}
modify();
/**
* Constructor for objects of class test
*/
public test()
{
// initialise instance variables
sum1 = 10;
number = 2.5f;
sum2 = 20;
total = 10.25d;
}
/**
* An example of a method - replace this comment with your own
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
public float sampleMethod()
{
// put your code here
number = sum1 / sum2;
return number;
}
}