-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindowsJava
1725 lines (1318 loc) · 38.4 KB
/
WindowsJava
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
app-conponent.html
<!-- app.component2.html -->
<table style="width: 100%;">
<tr>
<!-- Left side (Login Component) -->
<td style="width: 30%;">
<app-login></app-login>
</td>
<!-- Right side (Instructions and Advertisement stacked) -->
<td style="vertical-align: top;">
<!-- Instructions Component -->
<app-instructions></app-instructions>
<!-- Advertisement Component -->
<app-advertisement></app-advertisement>
</td>
</tr>
</table>
// Implementation of the overloaded function
function sum(x: number | string, y: number | string, z?: number, p?: number): number | string {
if (typeof x === 'number' && typeof y === 'number') {
if (z !== undefined && p !== undefined) {
// Implementation for overloaded function: int sum(int x, int y, int z, int p)
return x + y + z + p;
} else {
// Implementation for overloaded function: int sum(int x, int y)
return x + y;
}
} else if (typeof x === 'string' && typeof y === 'string') {
// Implementation for overloaded function: string sum(string x, string y)
return x + y;
}
// Return a default value or handle the case as needed
return 0; // For example, you can return 0 for invalid cases
}
// Examples
console.log(sum(1, 2)); // Output: 3
console.log(sum('Hello', ' World')); // Output: Hello World
console.log(sum(1, 2, 3, 4)); // Output: 10
// Employees.cs
using System.Collections.Generic;
public class Employees
{
private List<Employee> empList;
public Employees()
{
empList = new List<Employee>();
// Add 3 employees to empList (as per your requirement)
empList.Add(new Employee(1, "John Doe"));
empList.Add(new Employee(2, "Jane Smith"));
empList.Add(new Employee(3, "Bob Johnson"));
}
public List<Employee> ReturnList()
{
return empList;
}
public void AddEmp(int id, string name)
{
empList.Add(new Employee(id, name));
}
}
Controller:
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
public class MCQController : Controller
{
// Action for the first question
public IActionResult Question1()
{
return View();
}
// Action for processing the answer to the first question
[HttpPost]
public IActionResult Question1(string answer)
{
// Set or update the cookie for Question 1
Response.Cookies.Append("Q1", answer);
// Redirect to the second question
return RedirectToAction("Question2");
}
// Action for the second question
public IActionResult Question2()
{
return View();
}
// Action for processing the answer to the second question
[HttpPost]
public IActionResult Question2(string answer)
{
// Set or update the cookie for Question 2
Response.Cookies.Append("Q2", answer);
// Redirect to the third question
return RedirectToAction("Question3");
}
// Action for the third question
public IActionResult Question3()
{
return View();
}
// Action for processing the answer to the third question
[HttpPost]
public IActionResult Question3(string answer)
{
// Set or update the cookie for Question 3
Response.Cookies.Append("Q3", answer);
// Redirect to the "See Results" page
return RedirectToAction("SeeResults");
}
// Action to see the results
public IActionResult SeeResults()
{
// Calculate total marks based on correct answers
int totalMarks = CalculateTotalMarks();
// Pass the total marks to the view
ViewBag.TotalMarks = totalMarks;
// Display the results
return View();
}
// Helper method to calculate total marks
private int CalculateTotalMarks()
{
int totalMarks = 0;
// Compare user answers with correct answers
if (HttpContext.Request.Cookies["Q1"] == "CorrectAnswerForQ1")
{
totalMarks++;
}
if (HttpContext.Request.Cookies["Q2"] == "CorrectAnswerForQ2")
{
totalMarks++;
}
if (HttpContext.Request.Cookies["Q3"] == "CorrectAnswerForQ3")
{
totalMarks++;
}
return totalMarks;
}
}
Question1.cshtml
<!DOCTYPE html>
<html>
<head>
<title>Question 1</title>
</head>
<body>
<h2>Question 1</h2>
<p>Select the correct answer:</p>
<form method="post" action="/MCQ/Question1">
<select name="answer">
<option value="Option1">Option 1</option>
<option value="Option2">Option 2</option>
<option value="Option3">Option 3</option>
<option value="Option4">Option 4</option>
</select>
<button type="submit">Next</button>
</form>
</body>
</html>
Question2.cshtml
<!DOCTYPE html>
<html>
<head>
<title>Question 2</title>
</head>
<body>
<h2>Question 2</h2>
<p>Select the correct answer:</p>
<form method="post" action="/MCQ/Question2">
<select name="answer">
<option value="Option1">Option 1</option>
<option value="Option2">Option 2</option>
<option value="Option3">Option 3</option>
<option value="Option4">Option 4</option>
</select>
<button type="submit">Next</button>
</form>
<form method="post" action="/MCQ/Question1">
<button type="submit">Previous</button>
</form>
</body>
</html>
Question3.cshtml
<!DOCTYPE html>
<html>
<head>
<title>Question 3</title>
</head>
<body>
<h2>Question 3</h2>
<p>Select the correct answer:</p>
<form method="post" action="/MCQ/Question3">
<select name="answer">
<option value="Option1">Option 1</option>
<option value="Option2">Option 2</option>
<option value="Option3">Option 3</option>
<option value="Option4">Option 4</option>
</select>
<button type="submit">Submit</button>
</form>
<form method="post" action="/MCQ/Question2">
<button type="submit">Previous</button>
</form>
</body>
</html>
Last:
<!DOCTYPE html>
<html>
<head>
<title>See Results</title>
</head>
<body>
<h2>Results</h2>
<p>Your total marks: @ViewBag.TotalMarks</p>
</body>
</html>
public class AccountController : Controller
{
// Implement login actions here
public ActionResult Login()
{
return View();
}
[HttpPost]
public ActionResult Login(string username, string password)
{
// Check if the input is valid (you can implement validation logic here)
if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
{
// Save user input in cookies
SetLoginCookies(username, password);
return RedirectToAction("Inbox");
}
else
{
ViewBag.ErrorMessage = "Invalid input. Please try again.";
return View();
}
}
private void SetLoginCookies(string username, string password)
{
// Set cookies for username and password (you can also encrypt the password)
Response.Cookies["Username"].Value = username;
Response.Cookies["Password"].Value = password;
}
}
public class InboxController : Controller
{
// Implement inbox actions here
public ActionResult Inbox()
{
// Check if the user input (cookies) is present
if (Request.Cookies["Username"] != null && Request.Cookies["Password"] != null)
{
// Retrieve scratch messages and display them
List<ScratchMessage> messages = GetScratchMessages();
return View(messages);
}
else
{
// Redirect to the login page if input is not provided
return RedirectToAction("Login", "Account");
}
}
private List<ScratchMessage> GetScratchMessages()
{
// Implement code to retrieve scratch messages (e.g., from a database)
// For demo purposes, return some dummy data
return new List<ScratchMessage>
{
new ScratchMessage { Subject = "Message 1", Content = "Hello, World!" },
new ScratchMessage { Subject = "Message 2", Content = "This is a test message." }
};
}
}
cmd.Parameters.AddWithValue("@Name", name);
cmd.Parameters.AddWithValue("@UserName", userName);
cmd.Parameters.AddWithValue("@Password", password);
Database:-
using System;
using System.Data.SqlClient;
class Program
{
static void Main(string[] args)
{
Console.Write("Enter username: ");
string username = Console.ReadLine();
Console.Write("Enter password: ");
string password = Console.ReadLine();
string connectionString = "Data Source=yourServerName;Initial Catalog=yourDatabaseName;Integrated Security=True";
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
string query = "SELECT COUNT(*) FROM Login WHERE uname = @username AND passwd = @password";
using (SqlCommand command = new SqlCommand(query, connection))
{
command.Parameters.AddWithValue("@username", username);
command.Parameters.AddWithValue("@password", password);
int count = (int)command.ExecuteScalar();
if (count > 0)
{
Console.WriteLine("Login successful");
}
else
{
Console.WriteLine("Login NOT successful");
}
}
}
}
}
Form.cshtml
@model ExerciseMVC.Models.Student
<h2>Student Form</h2>
<form asp-controller="Student" asp-action="Welcome" method="post">
<div class="form-group">
<label for="firstName">First Name:</label>
<input type="text" class="form-control" id="firstName" name="firstName">
</div>
<div class="form-group">
<label for="lastName">Last Name:</label>
<input type="text" class="form-control" id="lastName" name="lastName">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
Contact:-----
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contact Us - ABC IT Solutions</title>
</head>
<body>
<header>
<h1>Contact Us</h1>
</header>
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About Us</a></li>
<li><a href="contact.html">Contact Us</a></li>
</ul>
</nav>
<section>
<h2>Contact Information</h2>
<p>If you have any questions or inquiries, please contact us using the form below:</p>
<form action="index.html" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<br>
<!-- Add other form fields as needed -->
<input type="submit" value="Submit">
</form>
</section>
</body>
</html>
About:----
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>About Us - ABC IT Solutions</title>
</head>
<body>
<header>
<h1>About Us</h1>
</header>
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About Us</a></li>
<li><a href="contact.html">Contact Us</a></li>
</ul>
</nav>
<section>
<h2>About Our Directors</h2>
<p>Our directors are dedicated professionals with years of experience in the IT industry.</p>
</section>
</body>
</html>
Main:-------
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ABC IT Solutions</title>
</head>
<body>
<header>
<h1>Welcome to ABC IT Solutions</h1>
</header>
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About Us</a></li>
<li><a href="contact.html">Contact Us</a></li>
</ul>
</nav>
<section>
<h2>Our Directors</h2>
<ul>
<li>Director 1</li>
<li>Director 2</li>
<li>Director 3</li>
<li>Director 4</li>
<li>Director 5</li>
</ul>
<h2>About Our Services</h2>
<p>We provide a wide range of IT solutions to meet your business needs.</p>
</section>
</body>
</html>
CREATE FUNCTION GetEligibleGifts()
RETURNS TABLE
AS
RETURN (
SELECT
c.Customer_id,
c.ZipCode,
CASE WHEN dbo.chkPrime(c.ZipCode) = 'yes' THEN 'yes' ELSE 'no' END AS EligibleGift
FROM
customers c
);
CREATE FUNCTION chkPrime(@n INT)
RETURNS NVARCHAR(50)
AS
BEGIN
DECLARE @i INT;
DECLARE @isPrime BIT = 1;
-- Check if the number is even
IF @n % 2 = 0
BEGIN
RETURN 'even';
END
-- Check if the number is 1
IF @n = 1
BEGIN
RETURN 'odd';
END
-- Check for odd prime numbers
SET @i = 3;
WHILE @i <= SQRT(@n)
BEGIN
IF @n % @i = 0
BEGIN
SET @isPrime = 0;
BREAK;
END
SET @i = @i + 2;
END
IF @isPrime = 1
BEGIN
RETURN 'oddprime';
END
ELSE
BEGIN
RETURN 'odd';
END
END;
using System;
using System.Collections.Generic;
class Employee
{
public string Name { get; set; }
public string Designation { get; set; }
}
class Program
{
static void Main()
{
DesignationLists d = new DesignationLists();
int choice;
do
{
Console.WriteLine("Menu:");
Console.WriteLine("1. Add Employee");
Console.WriteLine("2. Display Employees");
Console.WriteLine("3. Exit");
Console.Write("Enter your choice: ");
if (int.TryParse(Console.ReadLine(), out choice))
{
switch (choice)
{
case 1:
Employee e = new Employee();
Console.Write("Enter employee name: ");
e.Name = Console.ReadLine();
Console.Write("Enter employee designation (PM/PrM/TL/SP/JP): ");
e.Designation = Console.ReadLine();
e.Designation = e.Designation.ToUpper(); // Convert to uppercase for consistency
e.Input(d);
break;
case 2:
d.Display();
break;
case 3:
Environment.Exit(0);
break;
default:
Console.WriteLine("Invalid choice. Please try again.");
break;
}
}
else
{
Console.WriteLine("Invalid input. Please enter a valid number.");
}
} while (choice != 3);
}
}
class DesignationLists
{
private List<Employee> PM = new List<Employee>();
private List<Employee> PrM = new List<Employee>();
private List<Employee> TL = new List<Employee>();
private List<Employee> SP = new List<Employee>();
private List<Employee> JP = new List<Employee>();
public void Input(Employee e)
{
switch (e.Designation)
{
case "PM":
PM.Add(e);
break;
case "PRM":
PrM.Add(e);
break;
case "TL":
TL.Add(e);
break;
case "SP":
SP.Add(e);
break;
case "JP":
JP.Add(e);
break;
default:
Console.WriteLine("Invalid designation. Employee not added.");
break;
}
}
public void Display()
{
Console.WriteLine("Employees:");
DisplayList(PM);
DisplayList(PrM);
DisplayList(TL);
DisplayList(SP);
DisplayList(JP);
}
private void DisplayList(List<Employee> employees)
{
foreach (var employee in employees)
{
Console.WriteLine($"Name: {employee.Name}, Designation: {employee.Designation}");
}
}
}
using System;
public class MaxMinFinder<T> where T : IComparable<T>
{
public T FindMax(T a, T b, T c)
{
if (a.CompareTo(b) >= 0 && a.CompareTo(c) >= 0)
{
return a;
}
else if (b.CompareTo(a) >= 0 && b.CompareTo(c) >= 0)
{
return b;
}
else
{
return c;
}
}
public T FindMin(T a, T b, T c)
{
if (a.CompareTo(b) <= 0 && a.CompareTo(c) <= 0)
{
return a;
}
else if (b.CompareTo(a) <= 0 && b.CompareTo(c) <= 0)
{
return b;
}
else
{
return c;
}
}
}
class Program
{
static void Main()
{
MaxMinFinder<double> doubleFinder = new MaxMinFinder<double>();
double num1 = 12.5;
double num2 = 9.3;
double num3 = 15.7;
double max = doubleFinder.FindMax(num1, num2, num3);
double min = doubleFinder.FindMin(num1, num2, num3);
Console.WriteLine($"Max: {max}");
Console.WriteLine($"Min: {min}");
}
}
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
Queue<Person> seniorCitizenQueue = new Queue<Person>();
Queue<Person> generalQueue = new Queue<Person>();
// Input for 6 people
for (int i = 1; i <= 6; i++)
{
Console.Write($"Enter name for Person {i}: ");
string name = Console.ReadLine();
Console.Write($"Enter age for Person {i}: ");
int age = int.Parse(Console.ReadLine());
Person person = new Person(name, age);
if (age >= 60)
{
seniorCitizenQueue.Enqueue(person);
}
else
{
generalQueue.Enqueue(person);
}
}
Console.WriteLine("Processing Sequence:");
while (seniorCitizenQueue.Count > 0)
{
Console.WriteLine(seniorCitizenQueue.Dequeue());
if (generalQueue.Count > 0)
Console.WriteLine(generalQueue.Dequeue());
}
while (generalQueue.Count > 0)
{
Console.WriteLine(generalQueue.Dequeue());
}
}
}
class Person
{
public string Name { get; set; }
public int Age { get; set; }
public Person(string name, int age)
{
Name = name;
Age = age;
}
public override string ToString()
{
return $"Name: {Name}, Age: {Age}";
}
}
using System;
using System.Collections;
class Question
{
public string QuestionName { get; set; }
public bool CorrectAnswer { get; set; }
public Question(string questionName, bool correctAnswer)
{
QuestionName = questionName;
CorrectAnswer = correctAnswer;
}
}
class Paper
{
public BitArray AnsActual { get; set; }
public Paper()
{
AnsActual = new BitArray(4);
}
}
class Program
{
static void Main()
{
Question[] questions = new Question[4];
questions[0] = new Question("Q1: Collection namespace has ICollection interface (T/F):", true);
questions[1] = new Question("Q2: An IList in C# represents the class List in other languages (T/F):", false);
questions[2] = new Question("Q3: An Array and any collection is interchangeable object types (T/F):", false);
questions[3] = new Question("Q4: Collection is a part of BCL in .Net Framework (T/F):", true);
Paper paper = new Paper();
Console.WriteLine("Please answer the following questions with 'T' for True or 'F' for False:");
for (int i = 0; i < questions.Length; i++)
{
Console.Write($"{questions[i].QuestionName} ");
string userAnswerStr = Console.ReadLine();
bool userAnswer = (userAnswerStr.ToUpper() == "T");
paper.AnsActual[i] = userAnswer;
if (userAnswer == questions[i].CorrectAnswer)
{
Console.WriteLine("Correct! +5 Marks");
}
else
{
Console.WriteLine("Incorrect! 0 Marks");
}
}
int totalMarks = paper.AnsActual.Cast<bool>().Count(ans => ans) * 5;
Console.WriteLine($"Total Marks: {totalMarks} out of 20 marks.");
}
}
BitArray actual = new BitArray(4);
actual[0] = true; // Q1: Collection namespace has ICollection interface (True)
actual[1] = false; // Q2: An IList in C# represents the class List in other languages (False)
actual[2] = false; // Q3: An Array and any collection is interchangeable object Types (False)
actual[3] = true; // Q4: Collection is a part of BCL in .Net Framework (True)
BitArray userAnswers = new BitArray(4);
Console.WriteLine("Please answer the following questions with 'T' for True or 'F' for False:");
// Q1
Console.Write("Q1: Collection namespace has ICollection interface (T/F): ");
string q1Answer = Console.ReadLine();
userAnswers[0] = (q1Answer.ToUpper() == "T");
// Q2
Console.Write("Q2: An IList in C# represents the class List in other languages (T/F): ");
string q2Answer = Console.ReadLine();
userAnswers[1] = (q2Answer.ToUpper() == "F");
// Q3
Console.Write("Q3: An Array and any collection is interchangeable object types (T/F): ");
string q3Answer = Console.ReadLine();
userAnswers[2] = (q3Answer.ToUpper() == "F");
// Q4
Console.Write("Q4: Collection is a part of BCL in .Net Framework (T/F): ");
string q4Answer = Console.ReadLine();
userAnswers[3] = (q4Answer.ToUpper() == "T");
// Calculate marks
int totalMarks = 0;
for (int i = 0; i < 4; i++)
{
if (userAnswers[i] == actual[i])
{
totalMarks += 5;
}
}
Console.WriteLine($"You scored {totalMarks} out of 20 marks.");
using System;
class Employee
{
public string Name { get; set; }
public int Age { get; set; }
public Employee(string name, int age)
{
Name = name;
Age = age;
}
}
class DuplicateNameException : Exception
{
public DuplicateNameException(string name)
: base($"Duplicate Name: {name} (Need double Salary??)")
{
}
}
class InvalidAgeException : Exception
{