summary refs log tree commit diff stats
path: root/java/output
diff options
context:
space:
mode:
authorSudipto Mallick <>2024-01-02 02:12:16 +0000
committerSudipto Mallick <>2024-01-02 02:12:16 +0000
commita70e0a59817ce06a3dd23b3750ae16ee6660deaf (patch)
tree0843bf4d30edf22c9c4c27ff4887351c85993ccd /java/output
parent63c589e826829c5f47f95a5642531e02b2b2c8f7 (diff)
downloadzadania-a70e0a59817ce06a3dd23b3750ae16ee6660deaf.tar.gz
Add Java assignments to the repository
.gitignore: The build files, files left by editors like *~ and the PDF
documents for the assignments are to be ignored for the purposes of
version control.

README.rst: Rewrite, with one line description in Chinese.

java/alist.txt: List of assignments, sorted in the order of the list of
assignments, with the ones with completed documentation marked with `#`.

java/buildall: Script that will build all of the assignments into one
PDF file; to be rehauled for the final document.

code/*.java: The Java source code for the assignments.

dbld: Script that builds a PDF document for a single assignment.

index.typ: The list of assignments, subject to update for further
refinement and inclusion of yet more assignments.

jbld: Script that compiles code for a single Java assignment.

output/*.typ: Typst file containing the output (sessions) obtained from
running the individual Java assignments.

state.sql: Future alternative to `alist.txt`, under development.

template.typ: The Typst template used across all of assignment,
containing common code for the uniform styling, such as page border.

text/*.typ: Typst file documenting each Java assignment.

vendor/Java.sublime-syntax: Updated Sublime Text syntax file for Java,
used for newer syntax features, such as `var`, not yet available in
syntaxes shipped with Typst.

vendor/gr.tmTheme: A grayscale TextMate theme to be used for code in the
documents generated by Typst suitable for black and white printing.

wltd: Difference between the files in `code/` and `text/`, and `code/`
and `output`; need to be rewritten along with `state.sql`.
Diffstat (limited to 'java/output')
-rw-r--r--java/output/AddTwoNumbers.typ35
-rw-r--r--java/output/ArraySearch.typ94
-rw-r--r--java/output/ArraySort.typ59
-rw-r--r--java/output/CylinderCalculations.typ16
-rw-r--r--java/output/MatrixOperations.typ132
-rw-r--r--java/output/SingletonExample.typ9
-rw-r--r--java/output/StaticExecution.typ10
-rw-r--r--java/output/StringOperations.typ76
8 files changed, 431 insertions, 0 deletions
diff --git a/java/output/AddTwoNumbers.typ b/java/output/AddTwoNumbers.typ
new file mode 100644
index 0000000..0d3da48
--- /dev/null
+++ b/java/output/AddTwoNumbers.typ
@@ -0,0 +1,35 @@
+#import "/template.typ": highlight-output
+==== Taking input from command line arguments
+#highlight-output[```
+$ java AddTwoNumbersCLI 
+Usage: AddTwoNumbersCLI first-number second-number
+$ java  AddTwoNumbersCLI 5 7
+Taking input from CLI arguments:
+5.0 + 7.0 = 12.0
+```]
+==== Taking input using `java.util.Scanner`
+#highlight-output[```
+$ java AddTwoNumbersScan
+Taking input using java.util.Scanner:
+Enter first number: 12
+Enter second number: 7.3
+12.0 + 7.3 = 19.3
+$ java AddTwoNumbersScan
+Taking input using java.util.Scanner:
+Enter first number: 5.1
+Enter second number: 2c
+Invalid numbers
+```]
+==== Taking input using `java.io.BufferedReader`
+#highlight-output[```
+$ java AddTwoNumbersBuf
+Taking input using java.io.BufferedReader:
+Enter first number: 11.1
+Enter second number: 9.6
+11.1 + 9.6 = 20.7
+$ java AddTwoNumbersBuf
+Taking input using java.io.BufferedReader:
+Enter first number: 78
+Enter second number: ab
+Invalid numbers
+```]
diff --git a/java/output/ArraySearch.typ b/java/output/ArraySearch.typ
new file mode 100644
index 0000000..709b10f
--- /dev/null
+++ b/java/output/ArraySearch.typ
@@ -0,0 +1,94 @@
+#import "/template.typ": highlight-output
+#highlight-output[```
+$ java ArraySearch 
+Menu-driven program of array searching
+
+Enter the array:
+Enter the length: 5
+Enter the array elements: 5 7 9 3 4
+Menu:
+ 1. Re-enter array
+ 2. Display array elements
+ 3. Perform linear search
+ 4. Perform binary search
+ 5. Exit
+
+Enter your choice: 2
+The array elements are: 5.0 7.0 9.0 3.0 4.0
+Menu:
+ 1. Re-enter array
+ 2. Display array elements
+ 3. Perform linear search
+ 4. Perform binary search
+ 5. Exit
+
+Enter your choice: 3
+The array elements are: 5.0 7.0 9.0 3.0 4.0
+Enter the element to find: 7
+The element 7.0 was found in the array at position 2.
+Menu:
+ 1. Re-enter array
+ 2. Display array elements
+ 3. Perform linear search
+ 4. Perform binary search
+ 5. Exit
+
+Enter your choice: 3
+The array elements are: 5.0 7.0 9.0 3.0 4.0
+Enter the element to find: 8
+The element 8.0 was not found in the array.
+Menu:
+ 1. Re-enter array
+ 2. Display array elements
+ 3. Perform linear search
+ 4. Perform binary search
+ 5. Exit
+
+Enter your choice: 4
+Array is sorted before binary search.
+The array elements are: 3.0 4.0 5.0 7.0 9.0
+Enter the element to find: 4
+The element 4.0 was found in the array at position 2.
+Menu:
+ 1. Re-enter array
+ 2. Display array elements
+ 3. Perform linear search
+ 4. Perform binary search
+ 5. Exit
+
+Enter your choice: 4
+Array is sorted before binary search.
+The array elements are: 3.0 4.0 5.0 7.0 9.0
+Enter the element to find: 8
+The element 8.0 was not found in the array.
+Menu:
+ 1. Re-enter array
+ 2. Display array elements
+ 3. Perform linear search
+ 4. Perform binary search
+ 5. Exit
+
+Enter your choice: 1
+Enter the length: 7         
+Enter the array elements: 9 -11 7 13 5 0 4  
+The array elements are: 9.0 -11.0 7.0 13.0 5.0 0.0 4.0
+Menu:
+ 1. Re-enter array
+ 2. Display array elements
+ 3. Perform linear search
+ 4. Perform binary search
+ 5. Exit
+
+Enter your choice: 2
+The array elements are: 9.0 -11.0 7.0 13.0 5.0 0.0 4.0
+Menu:
+ 1. Re-enter array
+ 2. Display array elements
+ 3. Perform linear search
+ 4. Perform binary search
+ 5. Exit
+
+Enter your choice: 5
+Bye.
+```]
+
diff --git a/java/output/ArraySort.typ b/java/output/ArraySort.typ
new file mode 100644
index 0000000..e670330
--- /dev/null
+++ b/java/output/ArraySort.typ
@@ -0,0 +1,59 @@
+#import "/template.typ": highlight-output
+#highlight-output[```
+$ java ArraySort
+Menu-driven program of array operations
+
+Enter the array:
+Enter the length: 5
+Enter the array	elements: 3 -5.2 -4.2 0	6
+Menu:
+ 1. Re-enter array
+ 2. Display array elements
+ 3. Perform bubble sort
+ 4. Perform selection sort
+ 5. Exit
+
+Enter your choice: 3
+Before sorting:	The array elements are:	3.0 -5.2 -4.2 0.0 6.0
+After sorting: The array elements are: -5.2 -4.2 0.0 3.0 6.0
+Menu:
+ 1. Re-enter array
+ 2. Display array elements
+ 3. Perform bubble sort
+ 4. Perform selection sort
+ 5. Exit
+
+Enter your choice: 2
+The array elements are:	-5.2 -4.2 0.0 3.0 6.0
+Menu:
+ 1. Re-enter array
+ 2. Display array elements
+ 3. Perform bubble sort
+ 4. Perform selection sort
+ 5. Exit
+
+Enter your choice: 1
+Enter the length: 6
+Enter the array	elements: 3.5 -1.3 6.9 11.3 2 -7.8
+The array elements are:	3.5 -1.3 6.9 11.3 2.0 -7.8
+Menu:
+ 1. Re-enter array
+ 2. Display array elements
+ 3. Perform bubble sort
+ 4. Perform selection sort
+ 5. Exit
+
+Enter your choice: 4
+Before sorting:	The array elements are:	3.5 -1.3 6.9 11.3 2.0 -7.8
+After sorting: The array elements are: -7.8 -1.3 2.0 3.5 6.9 11.3
+Menu:
+ 1. Re-enter array
+ 2. Display array elements
+ 3. Perform bubble sort
+ 4. Perform selection sort
+ 5. Exit
+
+Enter your choice: 5
+Bye.
+```]
+
diff --git a/java/output/CylinderCalculations.typ b/java/output/CylinderCalculations.typ
new file mode 100644
index 0000000..be42b58
--- /dev/null
+++ b/java/output/CylinderCalculations.typ
@@ -0,0 +1,16 @@
+#import "/template.typ": highlight-output
+==== Taking input from command line arguments
+#highlight-output[```
+$ java CylinderCalculationsCLI
+Usage: CylinderCalculationsCLI radius height
+$ java CylinderCalculationsCLI 2 6
+A cylinder with radius 2.0 units and height 6.0 units, has volume of 75.39822368615503 cubic units and surface area of 603.1857894892403 square units.
+
+```]
+==== Taking input from keyboard using `java.util.Scanner`
+#highlight-output[```
+$ java CylinderCalculationsScan
+Enter radius: 5
+Enter height: 13
+A cylinder with radius 5.0 units and height 13.0 units, has volume of 1021.0176124166828 cubic units and surface area of 7351.326809400116 square units.
+```]
diff --git a/java/output/MatrixOperations.typ b/java/output/MatrixOperations.typ
new file mode 100644
index 0000000..2cabe8e
--- /dev/null
+++ b/java/output/MatrixOperations.typ
@@ -0,0 +1,132 @@
+#import "/template.typ": highlight-output
+#highlight-output[```
+$ java MatrixOperationsCLI 
+Menu-driven program for matrix operations
+Menu options:
+ 1. Matrix input
+ 2. Matrix display
+ 3. Matrix addition
+ 4. Matrix subtraction
+ 5. Matrix multiplication
+ 6. Exit
+Enter your choice: 1
+Enter number of rows and columns: 2 3
+Enter the matrix elements: 
+1 2 3
+4 5 6
+Menu options:
+ 1. Matrix input
+ 2. Matrix display
+ 3. Matrix addition
+ 4. Matrix subtraction
+ 5. Matrix multiplication
+ 6. Exit
+Enter your choice: 1
+Enter number of rows and columns: 2 3
+Enter the matrix elements: 
+4 -3 -2
+5 7 1
+Menu options:
+ 1. Matrix input
+ 2. Matrix display
+ 3. Matrix addition
+ 4. Matrix subtraction
+ 5. Matrix multiplication
+ 6. Exit
+Enter your choice: 3
+Enter which two matrices to add (out of 2 matrices): 1 2
+The resulting matrix 3:
+5.0	-1.0	1.0	
+9.0	12.0	7.0	
+Menu options:
+ 1. Matrix input
+ 2. Matrix display
+ 3. Matrix addition
+ 4. Matrix subtraction
+ 5. Matrix multiplication
+ 6. Exit
+Enter your choice: 4
+Enter which two matrices to subtract (out of 3 matrices): 2 1
+The resulting matrix 4:
+3.0	-5.0	-5.0	
+1.0	2.0	-5.0	
+Menu options:
+ 1. Matrix input
+ 2. Matrix display
+ 3. Matrix addition
+ 4. Matrix subtraction
+ 5. Matrix multiplication
+ 6. Exit
+Enter your choice: 1
+Enter number of rows and columns: 3 4
+Enter the matrix elements: 
+1 0 -1 2
+3 2 0 1
+0 1 -1 2
+Menu options:
+ 1. Matrix input
+ 2. Matrix display
+ 3. Matrix addition
+ 4. Matrix subtraction
+ 5. Matrix multiplication
+ 6. Exit
+Enter your choice: 2
+Enter which matrix to display (out of 5 matrices): 5
+The matrix 5:
+1.0	0.0	-1.0	2.0	
+3.0	2.0	0.0	1.0	
+0.0	1.0	-1.0	2.0	
+Menu options:
+ 1. Matrix input
+ 2. Matrix display
+ 3. Matrix addition
+ 4. Matrix subtraction
+ 5. Matrix multiplication
+ 6. Exit
+Enter your choice: 5
+Enter which two matrices to multiply (out of 5 matrices): 2 5
+The resulting matrix 6:
+-5.0	-8.0	-2.0	1.0	
+26.0	15.0	-6.0	19.0	
+Menu options:
+ 1. Matrix input
+ 2. Matrix display
+ 3. Matrix addition
+ 4. Matrix subtraction
+ 5. Matrix multiplication
+ 6. Exit
+Enter your choice: 5
+Enter which two matrices to multiply (out of 6 matrices): 1 2
+Error in the operation: Incompatible matrix arguments for multiplication
+Menu options:
+ 1. Matrix input
+ 2. Matrix display
+ 3. Matrix addition
+ 4. Matrix subtraction
+ 5. Matrix multiplication
+ 6. Exit
+Enter your choice: 3
+Enter which two matrices to add (out of 6 matrices): 2 5
+Error in the operation: Incompatible matrix arguments for addition
+Menu options:
+ 1. Matrix input
+ 2. Matrix display
+ 3. Matrix addition
+ 4. Matrix subtraction
+ 5. Matrix multiplication
+ 6. Exit
+Enter your choice: 4
+Enter which two matrices to subtract (out of 6 matrices): 3 4
+The resulting matrix 7:
+2.0	4.0	6.0	
+8.0	10.0	12.0	
+Menu options:
+ 1. Matrix input
+ 2. Matrix display
+ 3. Matrix addition
+ 4. Matrix subtraction
+ 5. Matrix multiplication
+ 6. Exit
+Enter your choice: 6
+Bye
+```]
diff --git a/java/output/SingletonExample.typ b/java/output/SingletonExample.typ
new file mode 100644
index 0000000..5f1bdd9
--- /dev/null
+++ b/java/output/SingletonExample.typ
@@ -0,0 +1,9 @@
+#import "/template.typ": highlight-output
+#highlight-output[```
+$ java SingletonExample 
+Creating singleton instance
+Providing singleton instance
+Providing singleton instance
+The singleton instances are identical.
+```]
+
diff --git a/java/output/StaticExecution.typ b/java/output/StaticExecution.typ
new file mode 100644
index 0000000..43636cf
--- /dev/null
+++ b/java/output/StaticExecution.typ
@@ -0,0 +1,10 @@
+#import "/template.typ": highlight-output
+#highlight-output[```
+$ java StaticExecution 
+Executing static block in StaticExecution
+Executing static main method in StaticExecution
+Executing static block in StaticExample
+Executing StaticExample constructor for the first time
+The number of objects of StaticExample created: 7
+```]
+
diff --git a/java/output/StringOperations.typ b/java/output/StringOperations.typ
new file mode 100644
index 0000000..eae633e
--- /dev/null
+++ b/java/output/StringOperations.typ
@@ -0,0 +1,76 @@
+#import "/template.typ": highlight-output
+#highlight-output[```
+$ java StringOperations 
+Menu-driven program for string operations
+Enter a string: A quick fox jumps over a lazy dog.
+Options:
+ 1. Re-enter a string
+ 2. Display the string
+ 3. Count words in the string
+ 4. Reverse the string
+ 5. Case-insensitively check whether the string is palindrome or not
+ 6. Exit
+
+Enter your choice: 2
+The string is: A quick brown fox jumps over a lazy dog.
+Options:
+ 1. Re-enter a string
+ 2. Display the string
+ 3. Count words in the string
+ 4. Reverse the string
+ 5. Case-insensitively check whether the string is palindrome or not
+ 6. Exit
+
+Enter your choice: 3
+The string has 8 words.
+Options:
+ 1. Re-enter a string
+ 2. Display the string
+ 3. Count words in the string
+ 4. Reverse the string
+ 5. Case-insensitively check whether the string is palindrome or not
+ 6. Exit
+
+Enter your choice: 4
+The given string reversed is: .god yzal eht revo spmuj xof nworb kciuq A
+Options:
+ 1. Re-enter a string
+ 2. Display the string
+ 3. Count words in the string
+ 4. Reverse the string
+ 5. Case-insensitively check whether the string is palindrome or not
+ 6. Exit
+
+Enter your choice: 5
+The given string isn't case-insensitively palindrome.
+Options:
+ 1. Re-enter a string
+ 2. Display the string
+ 3. Count words in the string
+ 4. Reverse the string
+ 5. Case-insensitively check whether the string is palindrome or not
+ 6. Exit
+
+Enter your choice: 1
+Enter a string: Aa bB C bB Aa
+Options:
+ 1. Re-enter a string
+ 2. Display the string
+ 3. Count words in the string
+ 4. Reverse the string
+ 5. Case-insensitively check whether the string is palindrome or not
+ 6. Exit
+
+Enter your choice: 5
+The given string is case-insensitively palindrome.
+Options:
+ 1. Re-enter a string
+ 2. Display the string
+ 3. Count words in the string
+ 4. Reverse the string
+ 5. Case-insensitively check whether the string is palindrome or not
+ 6. Exit
+
+Enter your choice: 6
+Bye.
+```]