Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
dominhduy09 committed Jul 1, 2024
1 parent 45be0a6 commit 104711a
Show file tree
Hide file tree
Showing 44 changed files with 480 additions and 0 deletions.
Binary file added OOP - Lab/Lab 5/ITITSB22029_DOMINHDUY_LAB5.rar
Binary file not shown.
Binary file added OOP - Lab/Lab 5/Lab 5.pdf
Binary file not shown.
Binary file added OOP - Lab/Lab 5/Q0/a/Leaderboard.pdf
Binary file not shown.
11 changes: 11 additions & 0 deletions OOP - Lab/Lab 5/Q0/a/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class Solution {

public static void main(String[] args) {
/*
* Enter your code here. Print output to STDOUT. Your class should be named
* Solution.
*/
System.out.println("Hello, World.");
System.out.println("Hello, Java.");
}
}
Binary file added OOP - Lab/Lab 5/Q0/a/Test.pdf
Binary file not shown.
Binary file added OOP - Lab/Lab 5/Q0/b/Leaderboard.pdf
Binary file not shown.
19 changes: 19 additions & 0 deletions OOP - Lab/Lab 5/Q0/b/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import java.util.*;

public class Solution {

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int a = scan.nextInt();
int b = scan.nextInt();
int c = scan.nextInt(); // Complete this line
scan.close(); // Complete this line

System.out.println(a);
System.out.println(b);
System.out.println(c);
// Complete this line
// Complete this line
}
}
1
Binary file added OOP - Lab/Lab 5/Q0/b/Test.pdf
Binary file not shown.
Binary file added OOP - Lab/Lab 5/Q0/c/Leaderboard.pdf
Binary file not shown.
36 changes: 36 additions & 0 deletions OOP - Lab/Lab 5/Q0/c/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Solution {



private static final Scanner scanner = new Scanner(System.in);

public static void main(String[] args) {
int N = scanner.nextInt();
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

scanner.close();


if (N % 2 != 0) {
System.out.println("Weird");
}
else if (N <= 5 && N >= 2) {
System.out.println("Not Weird");
}
else if (N <= 20 && N >= 6) {
System.out.println("Weird");
}
else {
System.out.println("Not Weird");
}
}
}
1
Binary file added OOP - Lab/Lab 5/Q0/c/Test.pdf
Binary file not shown.
Binary file added OOP - Lab/Lab 5/Q0/d/Leaderboard.pdf
Binary file not shown.
20 changes: 20 additions & 0 deletions OOP - Lab/Lab 5/Q0/d/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import java.util.Scanner;


public class Solution {
public static void main(String[] args) {


Scanner input = new Scanner(System.in);
int User = input.nextInt();

int i;
int n = 10;

for (i = 1 ; i <= n ; i++) {
int result = User * i;
System.out.println(User + " x " + i + " = " + result );
}
}
}
1
Binary file added OOP - Lab/Lab 5/Q0/d/Test.pdf
Binary file not shown.
Binary file added OOP - Lab/Lab 5/Q0/e/Leaderboard.pdf
Binary file not shown.
48 changes: 48 additions & 0 deletions OOP - Lab/Lab 5/Q0/e/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import java.util.*;
import java.security.*;

public class Solution {
public static void main(String[] args) {

DoNotTerminate.forbidExit();

try {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
in.close();
// String s=???; Complete this line below

// Write your code here
String s = Integer.toString(n); // Converting integer to string

if (n == Integer.parseInt(s)) {
System.out.println("Good job");
} else {
System.out.println("Wrong answer.");
}
} catch (DoNotTerminate.ExitTrappedException e) {
System.out.println("Unsuccessful Termination!!");
}
}
}

// The following class will prevent you from terminating the code using exit(0)!
class DoNotTerminate {

public static class ExitTrappedException extends SecurityException {

private static final long serialVersionUID = 1;
}

public static void forbidExit() {
final SecurityManager securityManager = new SecurityManager() {
@Override
public void checkPermission(Permission permission) {
if (permission.getName().contains("exitVM")) {
throw new ExitTrappedException();
}
}
};
System.setSecurityManager(securityManager);
}
}
Binary file added OOP - Lab/Lab 5/Q0/e/Test.pdf
Binary file not shown.
Binary file added OOP - Lab/Lab 5/Q0/f/Leaderboard.pdf
Binary file not shown.
22 changes: 22 additions & 0 deletions OOP - Lab/Lab 5/Q0/f/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import java.util.*;

public class Solution {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int[] a = new int[n];

// Read integers from input and store them in array a
for (int i = 0; i < n; i++) {
a[i] = scan.nextInt();
}
scan.close();

// Prints each sequential element in array a
for (int i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
}
}
Binary file added OOP - Lab/Lab 5/Q0/f/Test.pdf
Binary file not shown.
Binary file added OOP - Lab/Lab 5/Q0/g/Leaderboard.pdf
Binary file not shown.
33 changes: 33 additions & 0 deletions OOP - Lab/Lab 5/Q0/g/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

class Animal {
void walk() {
System.out.println("I am walking");
}
}

class Bird extends Animal {
void fly() {
System.out.println("I am flying");
}

void sing() {
System.out.println("I am singing");
}
}

public class Solution {

public static void main(String args[]) {

Bird bird = new Bird();
bird.walk();
bird.fly();
bird.sing();

}
}
Binary file added OOP - Lab/Lab 5/Q0/g/Test.pdf
Binary file not shown.
Binary file added OOP - Lab/Lab 5/Q0/h/Leaderboard.pdf
Binary file not shown.
34 changes: 34 additions & 0 deletions OOP - Lab/Lab 5/Q0/h/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import java.util.*;

abstract class Book {
String title;

abstract void setTitle(String s);

String getTitle() {
return title;
}
}

// Write MyBook class here
class MyBook extends Book {
// Implementing the abstract method setTitle
void setTitle(String s) {
this.title = s;
}
}

public class Main {

public static void main(String[] args) {
// Book new_novel=new Book(); This line prHMain.java:25: error: Book is
// abstract; cannot be instantiated
Scanner sc = new Scanner(System.in);
String title = sc.nextLine();
MyBook new_novel = new MyBook();
new_novel.setTitle(title);
System.out.println("The title is: " + new_novel.getTitle());
sc.close();

}
}
Binary file added OOP - Lab/Lab 5/Q0/h/Test.pdf
Binary file not shown.
Binary file added OOP - Lab/Lab 5/Q0/i/Leaderboard.pdf
Binary file not shown.
43 changes: 43 additions & 0 deletions OOP - Lab/Lab 5/Q0/i/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import java.util.*;

interface AdvancedArithmetic {
int divisor_sum(int n);
}

// Write your code here
class MyCalculator implements AdvancedArithmetic {
public int divisor_sum(int n) {
int sum = 0;
// Loop through numbers from 1 to n and find divisors
for (int i = 1; i <= n; i++) {
if (n % i == 0) {
sum += i;
}
}
return sum;
}
}

class Solution {
public static void main(String[] args) {
MyCalculator my_calculator = new MyCalculator();
System.out.print("I implemented: ");
ImplementedInterfaceNames(my_calculator);
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.print(my_calculator.divisor_sum(n) + "\n");
sc.close();
}

/*
* ImplementedInterfaceNames method takes an object and prints the name of the
* interfaces it implemented
*/
static void ImplementedInterfaceNames(Object o) {
Class[] theInterfaces = o.getClass().getInterfaces();
for (int i = 0; i < theInterfaces.length; i++) {
String interfaceName = theInterfaces[i].getName();
System.out.println(interfaceName);
}
}
}
Binary file added OOP - Lab/Lab 5/Q0/i/Test.pdf
Binary file not shown.
Binary file not shown.
55 changes: 55 additions & 0 deletions OOP - Lab/Lab 5/Question 1 (ArrayList)/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

public static void main(String[] args) {
/*
* Enter your code here. Read input from STDIN. Print output to STDOUT. Your
* class should be named Solution.
*/

Scanner scanner = new Scanner(System.in);

// First line input the length of List
int N = scanner.nextInt();

List<Integer> L = new ArrayList<Integer>(N);

for (int i = 0; i < N; i++) {
L.add(scanner.nextInt());
}

int Q = scanner.nextInt();
// System.out.println("Queries: " + Integer.toString(Q));

for (int i = 0; i < Q; i++) {
String operation = scanner.next();
// System.out.println("Current operation is: " + operation);

if (operation.equals("Insert")) {
int index = scanner.nextInt();
int value = scanner.nextInt();
// System.out.println("Inserting element: " + Integer.toString(value) + " into
// index: " + Integer.toString(index));
L.add(index, value);
}

else if (operation.equals("Delete")) {
int index = scanner.nextInt();
// System.out.println("Removing element at index: " + Integer.toString(index));
L.remove(index);
}
}

for (int element : L)

{
System.out.print(element + " ");
}

}
}
Binary file added OOP - Lab/Lab 5/Question 1 (ArrayList)/Test.pdf
Binary file not shown.
Binary file added OOP - Lab/Lab 5/Question 2 (Map)/Leaderboard.pdf
Binary file not shown.
40 changes: 40 additions & 0 deletions OOP - Lab/Lab 5/Question 2 (Map)/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

//Complete this code or write your own from scratch
import java.util.*;
import java.io.*;

class Solution {
public static void main(String[] argh) {
Scanner in = new Scanner(System.in);

int n = in.nextInt();
in.nextLine(); // this is to clear the buffer

HashMap<String, Integer> phonebook = new HashMap<String, Integer>(n);

// read in all the names and phones number
for (int i = 0; i < n; i++) {
String name = in.nextLine();
int phone = in.nextInt();
in.nextLine(); // this is to clear the buffer

phonebook.put(name, phone);
}

// this section is where the queries of the names show up
while (in.hasNext()) { // this is to check if there is a next line in the input stream
String s = in.nextLine();

Integer phonenumber = phonebook.get(s);

if (phonenumber == null) {
System.out.println("Not found");
}

else {
System.out.println(s + "=" + Integer.toString(phonenumber));
}

}
}
}
Binary file added OOP - Lab/Lab 5/Question 2 (Map)/Test.pdf
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 104711a

Please sign in to comment.