summary refs log tree commit diff stats
path: root/java/text
diff options
context:
space:
mode:
authorSudipto Mallick <smlckz@termux-alpine>2024-01-27 11:33:43 +0000
committerSudipto Mallick <smlckz@termux-alpine>2024-01-27 11:34:11 +0000
commitcd6a9243c056710794549a1ab5d51fbdd082ce2e (patch)
treef3f4df42bcfa96b9d6ef48da2b33be148adfdd2b /java/text
parent1db2841d10c6920eba89f1e55eb3c90aa770ad07 (diff)
downloadzadania-cd6a9243c056710794549a1ab5d51fbdd082ce2e.tar.gz
Complete Java assignments #7-13
Diffstat (limited to 'java/text')
-rw-r--r--java/text/BankAccountExample.typ57
-rw-r--r--java/text/ComplexCalculations.typ15
-rw-r--r--java/text/FindNumberInArray.typ36
-rw-r--r--java/text/ShapeAreaCalculations.typ27
-rw-r--r--java/text/SingletonExample.typ24
-rw-r--r--java/text/StaticExecution.typ4
-rw-r--r--java/text/StudentsArray.typ38
-rw-r--r--java/text/Template.typ20
8 files changed, 212 insertions, 9 deletions
diff --git a/java/text/BankAccountExample.typ b/java/text/BankAccountExample.typ
new file mode 100644
index 0000000..2cb1cc8
--- /dev/null
+++ b/java/text/BankAccountExample.typ
@@ -0,0 +1,57 @@
+#import "/template.typ": *
+#show: A => apply(A)
+#set raw(lang: "java-new")
+#set par(leading: 0.5em)
+
+#assignment(12, block: true)[
+  Write a program wherein design a class to represent a bank account. Include the following:
+  #pad(left: 1em)[
+  / Fields :
+    - Name of the depositor
+    - Address of the depositor
+    - Account number
+    - Balance amount in the account
+  / Methods :
+    - To assign initial values
+    - To deposit an amount
+    - To withdraw an amount after checking balance
+    - To display the name, address and balance of a customer.
+  ]
+  From `main()` create object and call these methods.
+]
+
+#scos("BankAccountExample")
+
+=== Discussion
+
+#skind[Classes, interfaces and methods used from Java standard library]
+
+- `java.util.ArrayList<E>` class provides a dynamic array implementation, allowing for the flexible storage and manipulation of elements in a resizable list.
+  - `boolean add(E)`: Adds the specified element to the end of the list.
+  - `E remove(int)`: Removes the element at the specified position in the list.
+  - `int size()`: Returns the number of elements in the list.
+- `java.util.Scanner` class:
+  - `String nextLine()`: Scan a line of text from the input stream.
+  - `long nextLong()`: Scan a `long` value from the input stream.
+  - `double nextDouble()`: Scan a `double` value from the input stream.
+
+#skind[Classes and methods implemented in the program]
+
+- The `BankAccount` class represents a bank account with details like name, address, account number, and balance.
+  - Constructor `BankAccount(String, String, long, double)`: Create a bank account with the given details.
+  - `static BankAccount takeInput(Scanner)`: Takes input for a bank account from the user.
+  - `long getAccountNo()`: Returns the account number of the bank account.
+  - `double getBalance()`: Returns the balance of the bank account.
+  - `boolean equals(Object)`: Compares bank accounts based on account number.
+  - `void deposit(double)`: Deposits money into the account.
+  - `static String formatBalance(double)`: Formats a balance value for display.
+  - `void withdraw(double) throws Exception`: Withdraws money from the account, handling exceptions.
+  - `void display()`: Displays the details of the bank account.
+  - `static BankAccount lookup(ArrayList<BankAccount>, long)`: Looks up a bank account in the list based on account number.
+
+- The `BankAccountExample` class contains the main program for interacting with bank accounts through a menu:
+  - `static void menu()`: Displays a menu of operations.
+  - `static BankAccount findAccount(Scanner, ArrayList<BankAccount>)`: Finds a bank account based on user input.
+  - `public static void main(String[])`: Implements a menu-driven program for managing bank accounts, allowing creation, display, deposit, withdrawal, and closure of accounts.
+  
+#signature()
diff --git a/java/text/ComplexCalculations.typ b/java/text/ComplexCalculations.typ
index b8df211..ffa9304 100644
--- a/java/text/ComplexCalculations.typ
+++ b/java/text/ComplexCalculations.typ
@@ -1,9 +1,9 @@
 #import "/template.typ": *
 #show: A => apply(A)
 #set raw(lang: "java-new")
-#set par(leading: 0.5em)
+#set par(leading: 0.65em)
 
-#assignment(6)[
+#assignment(7)[
   Write a program to add two complex numbers using concept of methods returning objects and methods taking objects as parameters.
 ]
 
@@ -23,9 +23,10 @@
 - The `Complex` class objects represents a a complex number.
   - Constructor `Complex(double, double)`: Create a complex number object from the provided real and imaginary parts.
   - `public String toString()` method returns the string representation of the complex number.
-- The `ComplexOperations` class 
-- 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`.
+- The `ComplexOperations` class contains operations that can be performed on `Complex` objects.
+  - `static Complex add(Complex a, Complex b) `: Returns the sum of two complex numbers provided.
+- The `ComplexCalculations` orchestrates a main program with:
+  - `static Complex takeComplexInput()`: Returns the complex number provided by the user.
+  - `public static void main(String[])`: Performs addition of two complex numbers.
+
 #signature()
diff --git a/java/text/FindNumberInArray.typ b/java/text/FindNumberInArray.typ
new file mode 100644
index 0000000..9c6a4bd
--- /dev/null
+++ b/java/text/FindNumberInArray.typ
@@ -0,0 +1,36 @@
+#import "/template.typ": *
+#show: A => apply(A)
+#set raw(lang: "java-new")
+#set par(leading: 0.7em)
+
+#assignment(8, pad: true)[
+  Write a program to find a number from an array of number objects.
+]
+
+#scos("FindNumberInArray")
+
+#v(1em)
+
+=== Discussion
+
+#skind[Classes, interfaces and methods used from Java standard library]
+
+- `java.util.Scanner` class:
+  - `int nextInt()`: Scan an `int` value from the input stream.
+  - `double nextDouble()`: Scan a `double` value from the input stream.
+- `java.util.InputMismatchException` is thrown by the methods of `Scanner` class when encountering invalid input.
+
+#skind[Classes and methods implemented in the program]
+
+- The `Number` class objects represent a `double` value and provide methods for equality comparison.
+  - Constructor `Number(double)`: Create a number object for the provided value.
+  - `double valueOf()`: Returns the underlying number.
+  - `boolean equals(Object)`: Compares the equality of the number with another object.
+- The `NumberArray` class manages an array of `Number` objects.
+  - Constructor `NumberArray(double[])`: Create a `NumberArray` object from an array of `double` values.
+  - `int find(Number)`: Find the position of a given `Number` in the array, or return -1 if not found.
+  - `void display()`: Display the elements of the array.
+- The `FindNumberInArray` class contains the main program for finding a number in an array:
+  - `public static void main(String[])`: Takes user input for the length and elements of an array, creates a `NumberArray`, and finds a specified number in the array.
+  
+#signature()
diff --git a/java/text/ShapeAreaCalculations.typ b/java/text/ShapeAreaCalculations.typ
new file mode 100644
index 0000000..f34c1a0
--- /dev/null
+++ b/java/text/ShapeAreaCalculations.typ
@@ -0,0 +1,27 @@
+#import "/template.typ": *
+#show: A => apply(A)
+#set raw(lang: "java-new")
+#set par(leading: 0.6em)
+
+#assignment(13)[
+  Write a program to create a class `Shape` with 4 methods to calculate the areas of triangle, rectangle, square, and circle using method overloading.
+]
+
+#scos("ShapeAreaCalculations")
+
+=== Discussion
+
+#skind[Classes and methods implemented in the program]
+
+- The `Shape` class provides static methods for calculating the area of different geometric shapes:
+  - `static double area(double a, double b, double c)`: Calculates the area of a triangle using its side lengths.
+  - `static int area(int length, int width)`: Calculates the area of a rectangle using its length and width.
+  - `static int area(int sideLength)`: Calculates the area of a square using its side length.
+  - `static double area(double radius)`: Calculates the area of a circle using its radius.
+
+- The `ShapeAreaCalculations` class contains the main program for calculating the area of geometric shapes based on user input through a menu-driven interface:
+  - `static void menu()`: Displays a menu of shape choices.
+  - `public static void main(String[])`: Implements a menu-driven program for calculating the area of different shapes (_i.e._ triangle, rectangle, square, or circle) based on user input.
+
+  
+#signature()
diff --git a/java/text/SingletonExample.typ b/java/text/SingletonExample.typ
new file mode 100644
index 0000000..84a5cff
--- /dev/null
+++ b/java/text/SingletonExample.typ
@@ -0,0 +1,24 @@
+#import "/template.typ": *
+#show: A => apply(A)
+#set raw(lang: "java-new")
+#set par(leading: 0.4em)
+
+#assignment(10, reduce-gap: true, pad: true)[
+  Write a program to implement a singleton class.
+]
+#v(-1em)
+#scos("SingletonExample")
+
+=== Discussion
+
+#skind[Classes and methods implemented in the program]
+
+- The `Singleton` class implements the Singleton design pattern to ensure a single instance of the class is created.
+  - `private static Singleton instance`: Private static variable to hold the single instance of the class.
+  - `private Singleton()`: Private constructor to prevent external instantiation and prints a message when the instance is created.
+  - `public static Singleton getInstance()`: Public method to retrieve the singleton instance. If the instance does not exist, it creates one and prints a message.
+  
+- The `SingletonExample` class contains the main program to demonstrate the Singleton pattern:
+  - `public static void main(String[])`: Creates two instances of `Singleton` using the `getInstance()` method and checks if they refer to the same instance.
+    - If `s1` and `s2` reference the same object, it prints "The singleton instances are identical."  
+#signature()
diff --git a/java/text/StaticExecution.typ b/java/text/StaticExecution.typ
index 00b4ed0..d89c8f0 100644
--- a/java/text/StaticExecution.typ
+++ b/java/text/StaticExecution.typ
@@ -3,10 +3,10 @@
 #set raw(lang: "java-new")
 #set par(leading: 0.75em)
 
-#assignment(10)[
+#assignment(9)[
   Write a program to show that `static` blocks get executed before any object creation and implement the use of static variable to count the number of objects.
 ]
-
+#v(-1em)
 #scos("StaticExecution")
 
 === Discussion
diff --git a/java/text/StudentsArray.typ b/java/text/StudentsArray.typ
new file mode 100644
index 0000000..18921ef
--- /dev/null
+++ b/java/text/StudentsArray.typ
@@ -0,0 +1,38 @@
+#import "/template.typ": *
+#show: A => apply(A)
+#set raw(lang: "java-new")
+#set par(leading: 0.6em)
+
+#assignment(11, block: true)[
+  Write a program to make a student class with attributes for _roll number_, _name_ and _stream_. Assume that a student studies 3 subjects having full marks of 100 each. Each subject has a _title_ and _theory marks_. From the main class, create an array of such students. Show their specific information, along with average percentage of marks.
+]
+
+#scos("StudentsArray", pad: 3em)
+
+=== Discussion
+
+#skind[Classes, and methods used from Java standard library]
+
+- `java.util.Scanner` class:
+  - `long nextLong()`: Scan a `long` value from the input stream.
+  - `String nextLine()`: Scan a line of text from the input stream.
+  - `int nextInt()`: Scan an `int` value from the input stream.
+
+#skind[Classes and methods implemented in the program]
+
+- The `Subject` class represents a subject with a title and theory marks.
+  - Constructor `Subject(String, int)`: Create a subject with the given title and theory marks.
+  - `static Subject input(Scanner)`: Takes input for subject details from the user.
+  - `int getTheoryMarks()`: Returns the theory marks for the subject.
+  - `void display()`: Display the marks obtained in the subject.
+
+- The `Student` class represents a student with a roll number, name, stream, and an array of subjects.
+  - Constructor `Student(long, String, String, Subject[])`: Create a student with the given details.
+  - `static Student input(Scanner)`: Takes input for student details from the user.
+  - `void display()`: Display the student details, including roll number, name, stream, subject details, and average percentage.
+
+- The `StudentsArray` class contains the main program to take input for multiple students and display their details:
+  - `public static void main(String[])`: Takes the number of students, inputs details for each student, and displays their details including average percentage.
+
+  
+#signature()
diff --git a/java/text/Template.typ b/java/text/Template.typ
new file mode 100644
index 0000000..d72ff21
--- /dev/null
+++ b/java/text/Template.typ
@@ -0,0 +1,20 @@
+#import "/template.typ": *
+#show: A => apply(A)
+#set raw(lang: "java-new")
+#set par(leading: 0.7em)
+
+#assignment()[
+
+]
+
+#scos("")
+
+=== Discussion
+
+#skind[Classes, interfaces and methods used from Java standard library]
+
+
+#skind[Classes and methods implemented in the program]
+
+  
+#signature()