Skip to content

Commit 66b8b8c

Browse files
Add Java Code
1 parent 92a6f69 commit 66b8b8c

26 files changed

+209
-209
lines changed

AlternateList_Q23.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static void main(String[] args) {
1515
List<Integer> list1 = Arrays.asList(1, 2, 3, 4, 5);
1616
List<Integer> list2 = Arrays.asList(6, 7, 8, 9, 10);
1717

18-
List<Integer> result1 = alternate(list1, list2);
18+
List<Integer> result1 = alternate_Q23(list1, list2);
1919
System.out.println("List 1: " + list1);
2020
System.out.println("List 2: " + list2);
2121
System.out.println("Alternating result: " + result1);
@@ -25,7 +25,7 @@ public static void main(String[] args) {
2525
List<Integer> list3 = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
2626
List<Integer> list4 = Arrays.asList(8, 9, 10);
2727

28-
List<Integer> result2 = alternate(list3, list4);
28+
List<Integer> result2 = alternate_Q23(list3, list4);
2929
System.out.println("\nList 3: " + list3);
3030
System.out.println("List 4: " + list4);
3131
System.out.println("Alternating result: " + result2);
@@ -35,7 +35,7 @@ public static void main(String[] args) {
3535
List<Integer> list5 = Arrays.asList(1, 2, 3, 4, 5);
3636
List<Integer> list6 = Arrays.asList(6, 7, 8, 9, 10, 11, 12);
3737

38-
List<Integer> result3 = alternate(list5, list6);
38+
List<Integer> result3 = alternate_Q23(list5, list6);
3939
System.out.println("\nList 5: " + list5);
4040
System.out.println("List 6: " + list6);
4141
System.out.println("Alternating result: " + result3);
@@ -51,7 +51,7 @@ public static void main(String[] args) {
5151
* @param list2 the second List of integers
5252
* @return a new List containing alternating elements from the two input lists
5353
*/
54-
public static List<Integer> alternate(List<Integer> list1, List<Integer> list2) {
54+
public static List<Integer> alternate_Q23(List<Integer> list1, List<Integer> list2) {
5555
List<Integer> result = new ArrayList<>();
5656

5757
// Determine the minimum length of the two lists

ArrayDemo_Q12.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ void arrayFunc(int A[], int p, int B[], int q) Given two sorted arrays A and B
2626

2727
import java.util.Arrays;
2828

29-
public class ArrayDemo {
29+
public class ArrayDemo_Q12 {
3030
// Method to find pairs with a given sum
31-
public void arrayFunc(int[] arr, int target) {
31+
public void arrayFunc_Q12(int[] arr, int target) {
3232
System.out.println("Finding pairs with sum = " + target);
3333

3434
boolean pairFound = false;
@@ -48,7 +48,7 @@ public void arrayFunc(int[] arr, int target) {
4848
}
4949

5050
// Overloaded method to merge two sorted arrays
51-
public void arrayFunc(int[] A, int p, int[] B, int q) {
51+
public void arrayFunc_Q12(int[] A, int p, int[] B, int q) {
5252
System.out.println("Merging two sorted arrays");
5353

5454
// Create a copy of original arrays for display
@@ -93,15 +93,15 @@ public void arrayFunc(int[] A, int p, int[] B, int q) {
9393

9494
// Main method for testing
9595
public static void main(String[] args) {
96-
ArrayDemo demo = new ArrayDemo();
96+
ArrayDemo_Q12 demo = new ArrayDemo_Q12();
9797

9898
// Test first method - find pairs with sum = 10
9999
int[] numbers = {4, 6, 5, -10, 8, 5, 20};
100100
int target = 10;
101101

102102
System.out.println("Test 1: Find pairs with sum = " + target);
103103
System.out.println("Array: " + Arrays.toString(numbers));
104-
demo.arrayFunc(numbers, target);
104+
demo.arrayFunc_Q12(numbers, target);
105105

106106
System.out.println();
107107

@@ -110,6 +110,6 @@ public static void main(String[] args) {
110110
int[] B = {2, 4, 9};
111111

112112
System.out.println("Test 2: Merge sorted arrays");
113-
demo.arrayFunc(A, A.length, B, B.length);
113+
demo.arrayFunc_Q12(A, A.length, B, B.length);
114114
}
115115
}

BankDepositCalculator_Q2.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ For option (ii) accept monthly instalment (p), rate of interest (r) and time per
1515
import java.util.Scanner;
1616
import java.lang.Math;
1717

18-
public class BankDepositCalculator {
18+
public class BankDepositCalculator_Q2 {
1919
public static void main(String[] args) {
2020
Scanner scanner = new Scanner(System.in);
2121

@@ -28,10 +28,10 @@ public static void main(String[] args) {
2828

2929
switch (choice) {
3030
case 1:
31-
calculateTermDeposit(scanner);
31+
calculateTermDeposit_Q2(scanner);
3232
break;
3333
case 2:
34-
calculateRecurringDeposit(scanner);
34+
calculateRecurringDeposit_Q2(scanner);
3535
break;
3636
default:
3737
System.out.println("Error: Invalid option selected. Please choose 1 or 2.");
@@ -40,7 +40,7 @@ public static void main(String[] args) {
4040
scanner.close();
4141
}
4242

43-
private static void calculateTermDeposit(Scanner scanner) {
43+
private static void calculateTermDeposit_Q2(Scanner scanner) {
4444
System.out.println("\nTerm Deposit Selected");
4545

4646
System.out.print("Enter Principal amount (p): ");
@@ -58,7 +58,7 @@ private static void calculateTermDeposit(Scanner scanner) {
5858
System.out.printf("Maturity Amount: %.2f\n", maturityAmount);
5959
}
6060

61-
private static void calculateRecurringDeposit(Scanner scanner) {
61+
private static void calculateRecurringDeposit_Q2(Scanner scanner) {
6262
System.out.println("\nRecurring Deposit Selected");
6363

6464
System.out.print("Enter Monthly Installment (p): ");

Bank_Q10.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import java.util.Scanner;
2727

28-
public class Bank {
28+
public class Bank_Q10 {
2929
// Static variable to generate unique account numbers
3030
private static int nextAccountNumber = 1001;
3131

@@ -36,20 +36,20 @@ public class Bank {
3636
private double balance;
3737

3838
// Constructor
39-
public Bank(String name, String address, double initialBalance) {
39+
public Bank_Q10(String name, String address, double initialBalance) {
4040
this.depositorName = name;
4141
this.depositorAddress = address;
42-
this.accountNumber = generateAccountNumber();
42+
this.accountNumber = generateAccountNumber_Q10();
4343
this.balance = initialBalance;
4444
}
4545

4646
// Method to generate unique account number
47-
private int generateAccountNumber() {
47+
private int generateAccountNumber_Q10() {
4848
return nextAccountNumber++;
4949
}
5050

5151
// Method to display information and balance
52-
public void displayInfo() {
52+
public void displayInfo_Q10() {
5353
System.out.println("\nAccount Information:");
5454
System.out.println("Account Number: " + accountNumber);
5555
System.out.println("Name: " + depositorName);
@@ -58,7 +58,7 @@ public void displayInfo() {
5858
}
5959

6060
// Method to deposit amount
61-
public void deposit(double amount) {
61+
public void deposit_Q10(double amount) {
6262
if (amount > 0) {
6363
balance += amount;
6464
System.out.println("$" + amount + " deposited successfully.");
@@ -68,7 +68,7 @@ public void deposit(double amount) {
6868
}
6969

7070
// Method to withdraw amount
71-
public void withdraw(double amount) {
71+
public void withdraw_Q10(double amount) {
7272
if (amount > 0) {
7373
if (amount <= balance) {
7474
balance -= amount;
@@ -82,13 +82,13 @@ public void withdraw(double amount) {
8282
}
8383

8484
// Method to change address
85-
public void changeAddress(String newAddress) {
85+
public void changeAddress_Q10(String newAddress) {
8686
this.depositorAddress = newAddress;
8787
System.out.println("Address updated successfully.");
8888
}
8989

9090
// Getter for account number
91-
public int getAccountNumber() {
91+
public int getAccountNumber_Q10() {
9292
return accountNumber;
9393
}
9494

@@ -102,7 +102,7 @@ public static void main(String[] args) {
102102
scanner.nextLine(); // Consume newline
103103

104104
// Create array to store Bank objects
105-
Bank[] accounts = new Bank[numDepositors];
105+
Bank_Q10[] accounts = new Bank_Q10[numDepositors];
106106

107107
// Input information for each depositor
108108
for (int i = 0; i < numDepositors; i++) {
@@ -119,8 +119,8 @@ public static void main(String[] args) {
119119
scanner.nextLine(); // Consume newline
120120

121121
// Create new Bank object
122-
accounts[i] = new Bank(name, address, balance);
123-
System.out.println("Account created with account number: " + accounts[i].getAccountNumber());
122+
accounts[i] = new Bank_Q10(name, address, balance);
123+
System.out.println("Account created with account number: " + accounts[i].getAccountNumber_Q10());
124124
}
125125

126126
// Menu for operations
@@ -143,7 +143,7 @@ public static void main(String[] args) {
143143
// Find the account
144144
int index = -1;
145145
for (int i = 0; i < accounts.length; i++) {
146-
if (accounts[i].getAccountNumber() == accNum) {
146+
if (accounts[i].getAccountNumber_Q10() == accNum) {
147147
index = i;
148148
break;
149149
}
@@ -157,25 +157,25 @@ public static void main(String[] args) {
157157
// Perform the selected operation
158158
switch (choice) {
159159
case 1:
160-
accounts[index].displayInfo();
160+
accounts[index].displayInfo_Q10();
161161
break;
162162
case 2:
163163
System.out.print("Enter amount to deposit: $");
164164
double depositAmount = scanner.nextDouble();
165-
accounts[index].deposit(depositAmount);
166-
accounts[index].displayInfo();
165+
accounts[index].deposit_Q10(depositAmount);
166+
accounts[index].displayInfo_Q10();
167167
break;
168168
case 3:
169169
System.out.print("Enter amount to withdraw: $");
170170
double withdrawAmount = scanner.nextDouble();
171-
accounts[index].withdraw(withdrawAmount);
172-
accounts[index].displayInfo();
171+
accounts[index].withdraw_Q10(withdrawAmount);
172+
accounts[index].displayInfo_Q10();
173173
break;
174174
case 4:
175175
System.out.print("Enter new address: ");
176176
String newAddress = scanner.nextLine();
177-
accounts[index].changeAddress(newAddress);
178-
accounts[index].displayInfo();
177+
accounts[index].changeAddress_Q10(newAddress);
178+
accounts[index].displayInfo_Q10();
179179
break;
180180
}
181181
}

CommandLineInput_Q1.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
Semester:
88
*/
99

10-
public class CommandLineInput {
10+
public class CommandLineInput_Q1 {
1111
public static void main(String[] args) {
1212
// Check if all required arguments are provided
1313
if (args.length < 4) {
1414
System.out.println("Please provide all required arguments:");
15-
System.out.println("java CommandLineInput <name> <rollno> <course> <semester>");
15+
System.out.println("java CommandLineInput_Q1 <name> <rollno> <course> <semester>");
1616
return;
1717
}
1818

DeleteVowels_Q9.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import java.util.Scanner;
66

7-
public class DeleteVowels {
7+
public class DeleteVowels_Q9 {
88
public static void main(String[] args) {
99
Scanner scanner = new Scanner(System.in);
1010

@@ -13,7 +13,7 @@ public static void main(String[] args) {
1313
String inputString = scanner.nextLine();
1414

1515
// Delete vowels from the string
16-
String result = deleteVowels(inputString);
16+
String result = deleteVowels_Q9(inputString);
1717

1818
// Display the result
1919
System.out.println("String after removing vowels: " + result);
@@ -22,7 +22,7 @@ public static void main(String[] args) {
2222
}
2323

2424
// Function to delete vowels from a string using StringBuffer
25-
private static String deleteVowels(String str) {
25+
private static String deleteVowels_Q9(String str) {
2626
// Convert the string to StringBuffer for efficient modification
2727
StringBuffer sb = new StringBuffer(str);
2828

0 commit comments

Comments
 (0)