summary refs log tree commit diff stats
path: root/java/text
diff options
context:
space:
mode:
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()
08-26 11:59:21 -0700 5592 - switch register names to lowercase' href='/akkartik/mu/commit/069allocate.subx?h=hlt&id=333525360b22f3d3ea31db46a4d2f1b4edbfebdb'>33352536 ^
6a7eaa81 ^

33352536 ^

6a7eaa81 ^

33352536 ^
6a7eaa81 ^


33352536 ^

6a7eaa81 ^


33352536 ^
6a7eaa81 ^


33352536 ^
6a7eaa81 ^


d7622824 ^
6a7eaa81 ^
33352536 ^
6a7eaa81 ^


33352536 ^
6a7eaa81 ^
33352536 ^

6a7eaa81 ^

bc20cc3d ^


33352536 ^

bc20cc3d ^
33352536 ^

bc20cc3d ^
33352536 ^

bc20cc3d ^


33352536 ^


bc20cc3d ^

33352536 ^







bc20cc3d ^
33352536 ^
bc20cc3d ^
33352536 ^

bc20cc3d ^

aff782c4 ^





bc20cc3d ^


3a044623 ^
bc20cc3d ^



33352536 ^
bc20cc3d ^
33352536 ^

bc20cc3d ^


6a7eaa81 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204