diff --git a/Java/Activities/Activity1.java b/Java/Activities/Activity1.java new file mode 100644 index 0000000000..9416abf884 --- /dev/null +++ b/Java/Activities/Activity1.java @@ -0,0 +1,15 @@ +package Examples; + +public class Activity1 { + + public static void main(String[] args) { + Car carName = new Car();// TODO Auto-generated method stub + carName.make=2014; + carName.color="Black"; + carName.transmission="Manual"; + carName.displayCharacteristics(); + carName.accelarate(); + carName.brake(); + } + +} diff --git a/Java/Activities/Activity1.py b/Java/Activities/Activity1.py new file mode 100644 index 0000000000..386842769c --- /dev/null +++ b/Java/Activities/Activity1.py @@ -0,0 +1,4 @@ +name=input("Enter your name") +age=int(input("Enter your age")) +year = str( ( 2024 - age ) + 100 ) +print(name +"will be 100 years old in " +year) \ No newline at end of file diff --git a/Java/Activities/Activity10.java b/Java/Activities/Activity10.java new file mode 100644 index 0000000000..0332a72bc5 --- /dev/null +++ b/Java/Activities/Activity10.java @@ -0,0 +1,33 @@ +package Examples; + +import java.util.HashSet; + +public class Activity10 { + + public static void main(String[] args) { + HashSet hs = new HashSet(); + hs.add("H"); + hs.add("E"); + hs.add("L"); + hs.add("L"); + hs.add("O"); + hs.add("!"); + System.out.println("Actual HashSet is: " +hs); + System.out.println("Set size is :" +hs.size()); + hs.remove("H"); + if(hs.remove("S")) { + System.out.println("S is removed from the Set"); + } else { + System.out.println("S is not present in the Set"); + } + if(hs.contains("L")) { + System.out.println("Set has the element given"); + }else { + + System.out.println("Given element is not present in Set"); + } + System.out.println("Final Updated Set :" +hs); + + } + +} diff --git a/Java/Activities/Activity11.java b/Java/Activities/Activity11.java new file mode 100644 index 0000000000..d35148c595 --- /dev/null +++ b/Java/Activities/Activity11.java @@ -0,0 +1,29 @@ +package Examples; + +import java.util.HashMap; + +public class Activity11 { + + public static void main(String[] args) { + HashMap map=new HashMap(); + map.put(1, "Red"); + map.put(2, "Green"); + map.put(3, "Blue"); + map.put(4, "White"); + map.put(5, "Black"); + System.out.println("The Original map: " +map); + map.remove(2); + System.out.println("After removing Green: " + map); + + if(map.containsValue("Green")) { + System.out.println("Green exists in the Map"); + } else { + System.out.println("Green does not exist in the Map"); + } + + + System.out.println("Number of sets in the Map : " + map.size()); + } + } + + diff --git a/Java/Activities/Activity12.java b/Java/Activities/Activity12.java new file mode 100644 index 0000000000..eb00d4a750 --- /dev/null +++ b/Java/Activities/Activity12.java @@ -0,0 +1,21 @@ +package Package1; + +interface Addable { + int add(int a, int b); +} + +public class Activity12 { + public static void main(String[] args) { + + Addable ad1 = (a, b) -> (a + b); + System.out.println(ad1.add(10, 20)); + + + Addable ad2 = (int a, int b) -> { + return (a + b); + }; + System.out.println(ad2.add(100, 200)); + } +} + + diff --git a/Java/Activities/Activity13.java b/Java/Activities/Activity13.java new file mode 100644 index 0000000000..b9ced6f26b --- /dev/null +++ b/Java/Activities/Activity13.java @@ -0,0 +1,26 @@ +package Package1; + +import java.util.*; + +public class Activity13 { + + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + ArrayList list = new ArrayList(); + Random indexGen = new Random(); + + System.out.print("Enter integers"); + System.out.println("(EOF or non-integer to terminate): "); + + while(scan.hasNextInt()) { + list.add(scan.nextInt()); + } + + Integer nums[] = list.toArray(new Integer[0]); + int index = indexGen.nextInt(nums.length); + System.out.println("Index value generated: " + index); + System.out.println("Value in arary at generated index: " + nums[index]); + + scan.close(); + } +} \ No newline at end of file diff --git a/Java/Activities/Activity14.java b/Java/Activities/Activity14.java new file mode 100644 index 0000000000..0f09da0e23 --- /dev/null +++ b/Java/Activities/Activity14.java @@ -0,0 +1,33 @@ +package Examples; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; + +import org.apache.commons.io.FileUtils; + +public class Activity14 { + public static void main(String[] args) throws IOException { + try { + File inputFile = new File("src/main/resources/newfile.txt"); + boolean fStatus = inputFile.createNewFile(); + if (fStatus) { + System.out.println("File created successfully!"); + FileUtils.writeStringToFile(inputFile, "Some text in a file", Charset.defaultCharset()); + } else { + System.out.println("File already exists at this path."); + } + + System.out.println("Data in file: " + FileUtils.readFileToString(inputFile, "UTF8")); + File destDir = new File("src/main/resources/destDir"); + FileUtils.copyFileToDirectory(inputFile, destDir); + + File newFile = FileUtils.getFile(destDir, "newfile.txt"); + String newFileData = FileUtils.readFileToString(newFile, "UTF8"); + System.out.println("Data in new file: " + newFileData); + } catch (IOException errMessage) { + System.out.println(errMessage); + } + } + } + diff --git a/Java/Activities/Activity2.java b/Java/Activities/Activity2.java new file mode 100644 index 0000000000..b3adf9c76f --- /dev/null +++ b/Java/Activities/Activity2.java @@ -0,0 +1,28 @@ +package Examples; + +public class Activity2 { + + public static void main(String[] args) { + int[] aray= {10,77,10,54,-11,10}; + int actual=0; + int expected=30; + for(int i=0;i=0 && x passengers; + private int maxPassengers; + private Date lastTimeTookOf; + private Date lastTimeLanded; + + public Plane(int maxPassengers) { + this.maxPassengers = maxPassengers; + this.passengers = new ArrayList<>(); + } + + public void onboard(String passengerName) { + if(passengers.size() <= maxPassengers) { + this.passengers.add(passengerName); + } else { + System.out.println("Plane is full"); + } + } + + public Date takeOff() { + this.lastTimeTookOf = new Date(); + return lastTimeTookOf; + } + + public void land() { + this.lastTimeLanded = new Date(); + this.passengers.clear(); + } + + public Date getLastTimeLanded() { + return lastTimeLanded; + } + + public List getPassengers() { + return passengers; + } +} + +public class Activity6 { + + public static void main(String[] args) throws InterruptedException { + + Plane plane = new Plane(10); + + plane.onboard("John"); + plane.onboard("Steve"); + plane.onboard("Anna"); + + System.out.println("Plane took off at: " + plane.takeOff()); + + System.out.println("People on the plane: " + plane.getPassengers()); + + plane.land(); + System.out.println("Plane landed at: " + plane.getLastTimeLanded()); + System.out.println("People on the plane after landing: " + plane.getPassengers()); + } +} + + diff --git a/Java/Activities/Activity7.java b/Java/Activities/Activity7.java new file mode 100644 index 0000000000..832cc1c2eb --- /dev/null +++ b/Java/Activities/Activity7.java @@ -0,0 +1,62 @@ +package Examples; + +public class Activity7 { + public static void main(String args[]) { + MountainBike mb = new MountainBike(3, 0, 25); + System.out.println(mb.bicycleDesc()); + mb.speedUp(20); + mb.applyBrake(5); + } +} + interface BicycleParts { + public int tyres = 2; + public int maxSpeed = 25; + } + + interface BicycleOperations { + public void applyBrake(int decrement); + public void speedUp(int increment); + } + + class Bicycle implements BicycleParts, BicycleOperations { + + public int gears; + public int currentSpeed; + public Bicycle(int gears, int currentSpeed) { + this.gears = gears; + this.currentSpeed = currentSpeed; + } + + public void applyBrake(int decrement) { + currentSpeed -= decrement; + System.out.println("Current speed: " + currentSpeed); + } + + public void speedUp(int increment) { + currentSpeed += increment; + System.out.println("Current speed: " + currentSpeed); + } + + public String bicycleDesc() { + return("No of gears are "+ gears + "\nSpeed of bicycle is " + maxSpeed); + } + } + + class MountainBike extends Bicycle { + + public int seatHeight; + public MountainBike(int gears, int currentSpeed, int startHeight) { + super(gears, currentSpeed); + seatHeight = startHeight; + } + + public void setHeight(int newValue) { + seatHeight = newValue; + } + + public String bicycleDesc() { + return (super.bicycleDesc()+ "\nSeat height is " + seatHeight); + } + } + + \ No newline at end of file diff --git a/Java/Activities/Activity8.java b/Java/Activities/Activity8.java new file mode 100644 index 0000000000..de2f9903ea --- /dev/null +++ b/Java/Activities/Activity8.java @@ -0,0 +1,35 @@ +package Examples; + +class CustomException extends Exception { + private String message = null; + + public CustomException(String message) { + this.message = message; + } + + @Override + public String getMessage() { + return message; + } +} + +public class Activity8 { + public static void main(String[] a){ + try { + + Activity8.exceptionTest("print to console"); + Activity8.exceptionTest(null); + Activity8.exceptionTest("Won't execute"); + } catch(CustomException mae) { + System.out.println("Inside catch block: " + mae.getMessage()); + } + } + static void exceptionTest(String str) throws CustomException { + if(str == null) { + throw new CustomException("String value is null"); + } else { + System.out.println(str); + } + } +} + diff --git a/Java/Activities/Activity9.java b/Java/Activities/Activity9.java new file mode 100644 index 0000000000..69ec6ac7c8 --- /dev/null +++ b/Java/Activities/Activity9.java @@ -0,0 +1,26 @@ +package Examples; + +import java.util.ArrayList; + +public class Activity9 { + + public static void main(String[] args) { + ArrayList myList = new ArrayList(); + myList.add("One"); + myList.add("Two"); + myList.add("Three"); + myList.add(3, "Four"); + myList.add(1, "Five"); + for(String x:myList) { + System.out.println(x); + } + System.out.println("3rd element is: " +myList.get(2)); + if(myList.contains("One")) { + System.out.println("The list contains the object given"); + } + System.out.println(myList.size()); + myList.remove(2); + System.out.println(myList); + } + +} diff --git a/Python/Activities/Activity1.py b/Python/Activities/Activity1.py new file mode 100644 index 0000000000..386842769c --- /dev/null +++ b/Python/Activities/Activity1.py @@ -0,0 +1,4 @@ +name=input("Enter your name") +age=int(input("Enter your age")) +year = str( ( 2024 - age ) + 100 ) +print(name +"will be 100 years old in " +year) \ No newline at end of file diff --git a/Python/Activities/Activity11.py b/Python/Activities/Activity11.py new file mode 100644 index 0000000000..bf8cb7f0f1 --- /dev/null +++ b/Python/Activities/Activity11.py @@ -0,0 +1,12 @@ +fruit_dict = { + "apple": 150, + "banana": 60, + "grapes": 100, + "guava": 50 +} +fruit_to_check = input("Which fruit are you looking for? ").lower() + +if(fruit_to_check in fruit_dict): + print("This is available") +else: + print("This is not available") \ No newline at end of file diff --git a/Python/Activities/Activity12-16.py b/Python/Activities/Activity12-16.py new file mode 100644 index 0000000000..a039933a80 --- /dev/null +++ b/Python/Activities/Activity12-16.py @@ -0,0 +1,58 @@ +# Activity12 +temp=0 +for i in range(0,11): + temp+=i +print(temp) + +# Activity13 + +def calculate_sum(list): + sum = 0 + for number in list: + sum += number + return sum +numList = [45, 2, 67, 90,5] +result = calculate_sum(numList) + +print("The sum of all the elements is: " + str(result)) + +# Activity14 +def fibonacci(number): + if number <= 1: + return number + else: + return(fibonacci(number-1) + fibonacci(number-2)) + +nterms = int(input("Enter a number: ")) + +if nterms <= 0: + print("Please enter a positive number") +else: + print("Fibonacci Sequence: ") + for i in range(nterms): + print(fibonacci(i)) + +# Activity16 +class Car: + 'This class represents a car' + + def __init__(self, manufacturer, model, make, transmission, color): + self.manufacturer = manufacturer + self.model = model + self.make = make + self.transmission = transmission + self.color = color + + def accelerate(self): + print(self.manufacturer + " " + self.model + " has started moving") + + def stop(self): + print(self.manufacturer + " " + self.model + " has stopped moving") + +car1 = Car("Toyota", "Corolla", "2015", "Manual", "White") +car2 = Car("Maruti", "800", "2013", "Manual", "Red") +car3 = Car("Suzuki", "Swift", "2017", "Automatic", "Black") + +car1.accelerate() +car1.stop() + diff --git a/Python/Activities/Activity17.py b/Python/Activities/Activity17.py new file mode 100644 index 0000000000..c9dafcae91 --- /dev/null +++ b/Python/Activities/Activity17.py @@ -0,0 +1,9 @@ +import pandas +data = { + "Usernames": ["admin", "Charles", "Deku"], + "Passwords": ["password", "Charl13", "AllMight"] +} +dataframe = pandas.DataFrame(data) + +print(dataframe) +dataframe.to_csv("sample.csv", index=False) \ No newline at end of file diff --git a/Python/Activities/Activity18.py b/Python/Activities/Activity18.py new file mode 100644 index 0000000000..247fb3807b --- /dev/null +++ b/Python/Activities/Activity18.py @@ -0,0 +1,15 @@ +import pandas + +dataframe = pandas.read_csv("sample.csv") +print(dataframe) +print("Usernames:") +print(dataframe["Usernames"]) + +print("Username: ", dataframe["Usernames"][1], " | ", "Password: ", dataframe["Passwords"][1]) + +print("Data sorted in ascending Usernames:") +print(dataframe.sort_values('Usernames')) + + +print("Data sorted in descending Passwords:") +print(dataframe.sort_values('Passwords', ascending=False)) \ No newline at end of file diff --git a/Python/Activities/Activity19.py b/Python/Activities/Activity19.py new file mode 100644 index 0000000000..b4aca4195a --- /dev/null +++ b/Python/Activities/Activity19.py @@ -0,0 +1,16 @@ +import pandas +from pandas import ExcelWriter + +data = { + 'FirstName':["Satvik", "Avinash", "Lahri"], + 'LastName':["Shah", "Kati", "Rath"], + 'Email':["satshah@example.com", "avinashK@example.com", "lahri.rath@example.com"], + 'PhoneNumber':["4537829158", "4892184058", "4528727830"] +} + +dataframe = pandas.DataFrame(data) +print(dataframe) +writer = ExcelWriter('sample.xlsx') +dataframe.to_excel(writer, 'Sheet1', index = False) + +writer.close() \ No newline at end of file diff --git a/Python/Activities/Activity2.py b/Python/Activities/Activity2.py new file mode 100644 index 0000000000..2316092d98 --- /dev/null +++ b/Python/Activities/Activity2.py @@ -0,0 +1,6 @@ +num = int(input("Enter a number: ")) +result = num % 2 +if result ==0: + print("Even Number") +else: + print("Odd Number") \ No newline at end of file diff --git a/Python/Activities/Activity20.py b/Python/Activities/Activity20.py new file mode 100644 index 0000000000..38a2f55e1f --- /dev/null +++ b/Python/Activities/Activity20.py @@ -0,0 +1,11 @@ +import pandas +dataframe = pandas.read_excel('sample.xlsx') + +print(dataframe) +print("Number of rows and columns:", dataframe.shape) + +print("Emails:") +print(dataframe['Email']) + +print("Sorted data:") +print(dataframe.sort_values('FirstName')) \ No newline at end of file diff --git a/Python/Activities/Activity3.py b/Python/Activities/Activity3.py new file mode 100644 index 0000000000..aa969a0c77 --- /dev/null +++ b/Python/Activities/Activity3.py @@ -0,0 +1,21 @@ +X=input("Enter your input :") +Y=input("Enter your input :") +if X == Y: + print("It's a tie!") +elif X == 'rock': + if Y == 'scissors': + print("Rock wins!") + else: + print("Paper wins!") +elif X == 'scissors': + if Y == 'paper': + print("Scissors win!") + else: + print("Rock wins!") +elif X == 'paper': + if Y == 'rock': + print("Paper wins!") + else: + print("Scissors win!") +else: + print("Please provide a valid input.") \ No newline at end of file diff --git a/Python/Activities/Activity4.py b/Python/Activities/Activity4.py new file mode 100644 index 0000000000..3d8a96dfee --- /dev/null +++ b/Python/Activities/Activity4.py @@ -0,0 +1,34 @@ +X=input("Enter your input :") +Y=input("Enter your input :") +while True: + + + if X == Y: + print("It's a tie!") + elif X == 'rock': + if Y == 'scissors': + print("Rock wins!") + else: + print("Paper wins!") + elif X == 'scissors': + if Y == 'paper': + print("Scissors win!") + else: + print("Rock wins!") + elif X == 'paper': + if Y == 'rock': + print("Paper wins!") + else: + print("Scissors win!") + else: + print("Please provide a valid input.") + + repeat = input("Do you want to play another round? Yes/No: ").lower() + + if(repeat == "yes"): + continue + elif(repeat == "no"): + raise SystemExit + else: + print("Invalid option entered. Exiting now.") + raise SystemExit \ No newline at end of file diff --git a/Python/Activities/Activity5-10.py b/Python/Activities/Activity5-10.py new file mode 100644 index 0000000000..99037d5597 --- /dev/null +++ b/Python/Activities/Activity5-10.py @@ -0,0 +1,53 @@ +# num=int(input("enter a number")) +# for i in range(1,11): +# result=num*i +# print(num, ' x ', i, ' = ',result ) + +# Activity6 +# for i in range(10): +# print(str(i) * i) +# Activity7 +# numbers = input("Enter a list of values:") +# sum = 0 +# for number in numbers: +# sum += int(number) +# print(sum) + +# Activity8 + +# List = [24, 67, 78, 98, 10] +# print("Original list is ", List) + +# if (List[0] == List[-1]): +# print(True) +# else: +# print(False) + +# Activity9 + +# listOne = [10, 20, 23, 11, 17] +# listTwo = [13, 43, 24, 36, 12] +# print("First List ", listOne) +# print("Second List ", listTwo) + +# thirdList = [] + +# for num in listOne: +# if (num % 2 != 0): +# thirdList.append(num) + +# for num in listTwo: +# if (num % 2 == 0): +# thirdList.append(num) + +# print("result List is:") +# print(thirdList) + +# Activity10 + +tuple = int(input("Enter a tuple")) +print("Original list is ", tuple) +print("Numbers divisible by 5 are: ") +for num in tuple: + if (num % 5 == 0): + print(num) \ No newline at end of file