From a70e0a59817ce06a3dd23b3750ae16ee6660deaf Mon Sep 17 00:00:00 2001 From: Sudipto Mallick <> Date: Tue, 2 Jan 2024 02:12:16 +0000 Subject: 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`. --- java/text/CylinderCalculations.typ | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 java/text/CylinderCalculations.typ (limited to 'java/text/CylinderCalculations.typ') diff --git a/java/text/CylinderCalculations.typ b/java/text/CylinderCalculations.typ new file mode 100644 index 0000000..1ee8519 --- /dev/null +++ b/java/text/CylinderCalculations.typ @@ -0,0 +1,34 @@ +#import "/template.typ": * +#show: A => apply(A) +#set raw(lang: "java-new") +#set par(leading: 0.5em) + +#assignment(6)[ + Write a program to find the surface area and volume of a cylinder using constructor by taking keyboard input or command-line input. +] + +#scos("CylinderCalculations") + +=== Discussion + +#skind[Classes, interfaces and methods used from Java standard library] + +- `java.lang.Double` class: + - `static double parseDouble(String)`: Try to parse the provided string as a `double` value. +- `java.util.Scanner` class: + - `double nextDouble()`: Scan a `double` value from the the input stream. +- `java.util.InputMismatchException` is thrown by the methods of `Scanner` class when encountering invalid input. +- `java.lang.NumberFormatExeption` is thrown by `parseDouble` method when the provided string does not constitute a valid `double` value. + +#skind[Classes and methods implemented in the program] + +- The `Cylinder` class objects represents a cylinder, a 3D geometric shape. + - Constructor `Cylinder(double, double)`: Create a cylinder object of the provided radius and height. + - `double volume()`: Returns the volume of the cylinder. + - `double surfaceArea()`: Returns the surface area of the cylinder. + - `void display()`: Display information about the cylinder. +- The `CylinderCalculationsCLI` orchestrates a main program with: + - `public static void main(String[])`: Creates a cylinder object with its radius and height given as command-line arguments. +- The `CylinderCalculationsScan` orchestrates a main program with: + - `public static void main(String[])`: Creates a cylinder object with its radius and height taken from user using `java.util.Scanner`. +#signature() -- cgit 1.4.1-2-gfad0