diff --git a/Email-Sender-Using-Java/pom.xml b/Email-Sender-Using-Java/pom.xml new file mode 100644 index 0000000..11ef250 --- /dev/null +++ b/Email-Sender-Using-Java/pom.xml @@ -0,0 +1,30 @@ + + 4.0.0 + + com.ashish + Email-Sender-Using-Java + 0.0.1-SNAPSHOT + jar + + Email-Sender-Using-Java + http://maven.apache.org + + + UTF-8 + + + + + com.sun.mail + javax.mail + 1.6.2 + + + junit + junit + 3.8.1 + test + + + diff --git a/Email-Sender-Using-Java/src/main/java/com/sachin/Email_Sender_Using_Java/App.java b/Email-Sender-Using-Java/src/main/java/com/sachin/Email_Sender_Using_Java/App.java new file mode 100644 index 0000000..b2c7456 --- /dev/null +++ b/Email-Sender-Using-Java/src/main/java/com/sachin/Email_Sender_Using_Java/App.java @@ -0,0 +1,116 @@ +package com.sachin.Email_Sender_Using_Java; +import java.io.File; +import java.util.*; +import javax.mail.Authenticator; +import javax.mail.Message; +import javax.mail.PasswordAuthentication; +import javax.mail.Session; +import javax.mail.Transport; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeBodyPart; +import javax.mail.internet.MimeMessage; +import javax.mail.internet.MimeMultipart; + +public class App +{ + + public static void main( String[] args ) + { + System.out.println("preparing to send message ..."); + String message = "Name: Sachin Baghel, Course:PG-DAC, College: CDAC,Noida, Contact Number: 8860883929"; + String subject = "Challenge 3 Completed."; + String to = "hr@ignitershub.com"; + String from = "krishna.sachin16@gmail.com"; + + sendAttachment(message,subject,to,from); + } +private static void sendAttachment(String message, String subject, String to, String from) { + + //Variable for gmail + String host="smtp.gmail.com"; + + //get the system properties + Properties properties = System.getProperties(); + System.out.println("PROPERTIES "+properties); + + //setting important information to properties object + + //host set + properties.put("mail.smtp.host", host); + properties.put("mail.smtp.port","465"); + properties.put("mail.smtp.ssl.enable","true"); + properties.put("mail.smtp.auth","true"); + + //Step 1: to get the session object.. + Session session=Session.getInstance(properties, new Authenticator() { + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication("krishna.sachin16@gmail.com","zzkoizyjbgumjokx"); + } + }); + + session.setDebug(true); + + //Step 2 : compose the message [text,multi media] + + MimeMessage m = new MimeMessage(session); + try { + + //from email + m.setFrom(from); + + //adding recipient to message + m.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); + + //adding subject to message + m.setSubject(subject); + + + //attach + + //file path + String path="C:\\Users\\himan\\Desktop\\Springggggggg\\email.jpg"; + + + MimeMultipart mimeMultipart = new MimeMultipart(); + MimeBodyPart textMime = new MimeBodyPart();//text + MimeBodyPart fileMime = new MimeBodyPart();//file + + try { + + textMime.setText(message); //add text in it + + File file=new File(path); + fileMime.attachFile(file); //add file path in it + + mimeMultipart.addBodyPart(textMime); //add both in its parent + mimeMultipart.addBodyPart(fileMime); //add both in its parent + + + } catch (Exception e) { + + e.printStackTrace(); + } + + + m.setContent(mimeMultipart); + + + //send + + //Step 3 : send the message using Transport class + Transport.send(m); + + + + }catch (Exception e) { + e.printStackTrace(); + } + + System.out.println("Sent success..................."); + + + + +} +} diff --git a/Email-Sender-Using-Java/src/test/java/com/sachin/Email_Sender_Using_Java/AppTest.java b/Email-Sender-Using-Java/src/test/java/com/sachin/Email_Sender_Using_Java/AppTest.java new file mode 100644 index 0000000..55d7a77 --- /dev/null +++ b/Email-Sender-Using-Java/src/test/java/com/sachin/Email_Sender_Using_Java/AppTest.java @@ -0,0 +1,38 @@ +package com.sachin.Email_Sender_Using_Java; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/Email-Sender-Using-Java/target/classes/META-INF/MANIFEST.MF b/Email-Sender-Using-Java/target/classes/META-INF/MANIFEST.MF new file mode 100644 index 0000000..b087487 --- /dev/null +++ b/Email-Sender-Using-Java/target/classes/META-INF/MANIFEST.MF @@ -0,0 +1,4 @@ +Manifest-Version: 1.0 +Build-Jdk-Spec: 17 +Created-By: Maven Integration for Eclipse + diff --git a/Email-Sender-Using-Java/target/classes/META-INF/maven/com.ashish/Email-Sender-Using-Java/pom.properties b/Email-Sender-Using-Java/target/classes/META-INF/maven/com.ashish/Email-Sender-Using-Java/pom.properties new file mode 100644 index 0000000..334ddad --- /dev/null +++ b/Email-Sender-Using-Java/target/classes/META-INF/maven/com.ashish/Email-Sender-Using-Java/pom.properties @@ -0,0 +1,7 @@ +#Generated by Maven Integration for Eclipse +#Sat Jan 20 10:58:46 IST 2024 +m2e.projectLocation=C\:\\Users\\himan\\Desktop\\Springggggggg\\Email_Sender_With_attachment_using_Java-master +m2e.projectName=Email-Sender-Using-Java +groupId=com.ashish +artifactId=Email-Sender-Using-Java +version=0.0.1-SNAPSHOT diff --git a/Email-Sender-Using-Java/target/classes/META-INF/maven/com.ashish/Email-Sender-Using-Java/pom.xml b/Email-Sender-Using-Java/target/classes/META-INF/maven/com.ashish/Email-Sender-Using-Java/pom.xml new file mode 100644 index 0000000..11ef250 --- /dev/null +++ b/Email-Sender-Using-Java/target/classes/META-INF/maven/com.ashish/Email-Sender-Using-Java/pom.xml @@ -0,0 +1,30 @@ + + 4.0.0 + + com.ashish + Email-Sender-Using-Java + 0.0.1-SNAPSHOT + jar + + Email-Sender-Using-Java + http://maven.apache.org + + + UTF-8 + + + + + com.sun.mail + javax.mail + 1.6.2 + + + junit + junit + 3.8.1 + test + + + diff --git a/Email-Sender-Using-Java/target/classes/com/sachin/Email_Sender_Using_Java/App$1.class b/Email-Sender-Using-Java/target/classes/com/sachin/Email_Sender_Using_Java/App$1.class new file mode 100644 index 0000000..30f5926 Binary files /dev/null and b/Email-Sender-Using-Java/target/classes/com/sachin/Email_Sender_Using_Java/App$1.class differ diff --git a/Email-Sender-Using-Java/target/classes/com/sachin/Email_Sender_Using_Java/App.class b/Email-Sender-Using-Java/target/classes/com/sachin/Email_Sender_Using_Java/App.class new file mode 100644 index 0000000..f25f902 Binary files /dev/null and b/Email-Sender-Using-Java/target/classes/com/sachin/Email_Sender_Using_Java/App.class differ diff --git a/Email-Sender-Using-Java/target/test-classes/com/sachin/Email_Sender_Using_Java/AppTest.class b/Email-Sender-Using-Java/target/test-classes/com/sachin/Email_Sender_Using_Java/AppTest.class new file mode 100644 index 0000000..ac5356b Binary files /dev/null and b/Email-Sender-Using-Java/target/test-classes/com/sachin/Email_Sender_Using_Java/AppTest.class differ diff --git a/Output_screenshots/challenge_01/Screenshot 2024-01-20 105952.png b/Output_screenshots/challenge_01/Screenshot 2024-01-20 105952.png new file mode 100644 index 0000000..2bd77bf Binary files /dev/null and b/Output_screenshots/challenge_01/Screenshot 2024-01-20 105952.png differ diff --git a/Output_screenshots/challenge_01/Screenshot 2024-01-20 110022.png b/Output_screenshots/challenge_01/Screenshot 2024-01-20 110022.png new file mode 100644 index 0000000..451633c Binary files /dev/null and b/Output_screenshots/challenge_01/Screenshot 2024-01-20 110022.png differ diff --git a/Output_screenshots/challenge_02/Screenshot 2024-01-19 154951.png b/Output_screenshots/challenge_02/Screenshot 2024-01-19 154951.png new file mode 100644 index 0000000..2396e4a Binary files /dev/null and b/Output_screenshots/challenge_02/Screenshot 2024-01-19 154951.png differ diff --git a/Output_screenshots/challenge_02/Screenshot 2024-01-20 110123.png b/Output_screenshots/challenge_02/Screenshot 2024-01-20 110123.png new file mode 100644 index 0000000..3799cbc Binary files /dev/null and b/Output_screenshots/challenge_02/Screenshot 2024-01-20 110123.png differ diff --git a/Output_screenshots/challenge_03/Screenshot 2024-01-20 110233.png b/Output_screenshots/challenge_03/Screenshot 2024-01-20 110233.png new file mode 100644 index 0000000..47f5350 Binary files /dev/null and b/Output_screenshots/challenge_03/Screenshot 2024-01-20 110233.png differ diff --git a/Output_screenshots/challenge_04/Screenshot 2024-01-20 110306.png b/Output_screenshots/challenge_04/Screenshot 2024-01-20 110306.png new file mode 100644 index 0000000..89018a4 Binary files /dev/null and b/Output_screenshots/challenge_04/Screenshot 2024-01-20 110306.png differ diff --git a/README.md b/README.md index 822b364..d969ae1 100644 --- a/README.md +++ b/README.md @@ -1 +1,12 @@ # interns-assignments +# IgnitersHub.com + +Hello there, +This is the assignment requested via Igniters Hub. +Points to be noted before you open the Files: +1) Challenge 1,3,4 is in the "ignitershub_assign" package. +2) Challenge 2 is in "Email-Sender-Using-Java" package. +3) Screenshots of all the output is in "Out_screenshots" Folder. + +# ThankYou. +# Enjoy. diff --git a/ignitershub_assign/bin/challenge_01/input_output_files.class b/ignitershub_assign/bin/challenge_01/input_output_files.class new file mode 100644 index 0000000..c56504a Binary files /dev/null and b/ignitershub_assign/bin/challenge_01/input_output_files.class differ diff --git a/ignitershub_assign/bin/challenge_03/palindrome.class b/ignitershub_assign/bin/challenge_03/palindrome.class new file mode 100644 index 0000000..30d2eef Binary files /dev/null and b/ignitershub_assign/bin/challenge_03/palindrome.class differ diff --git a/ignitershub_assign/bin/challenge_04/string_manipulation.class b/ignitershub_assign/bin/challenge_04/string_manipulation.class new file mode 100644 index 0000000..40c42f3 Binary files /dev/null and b/ignitershub_assign/bin/challenge_04/string_manipulation.class differ diff --git a/ignitershub_assign/bin/module-info.class b/ignitershub_assign/bin/module-info.class new file mode 100644 index 0000000..57f860a Binary files /dev/null and b/ignitershub_assign/bin/module-info.class differ diff --git a/ignitershub_assign/input.txt b/ignitershub_assign/input.txt new file mode 100644 index 0000000..076a25c --- /dev/null +++ b/ignitershub_assign/input.txt @@ -0,0 +1,3 @@ +10 - 2 = +100 * ( 2 + 12 ) = +(10 + 5^2) ( (5*-2) + 9 - 3^3) / 2= \ No newline at end of file diff --git a/ignitershub_assign/output.txt b/ignitershub_assign/output.txt new file mode 100644 index 0000000..6a40062 --- /dev/null +++ b/ignitershub_assign/output.txt @@ -0,0 +1,3 @@ +10 - 2 = = 8 +100 * ( 2 + 12 ) = = 1400 +(10 + 5^2) ( (5*-2) + 9 - 3^3) / 2= = -490 diff --git a/ignitershub_assign/src/challenge_01/input_output_files.java b/ignitershub_assign/src/challenge_01/input_output_files.java new file mode 100644 index 0000000..9287f15 --- /dev/null +++ b/ignitershub_assign/src/challenge_01/input_output_files.java @@ -0,0 +1,91 @@ +package challenge; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Stack; + +public class input_output_files { + public static void main(String[] args) { + try { + BufferedReader reader = new BufferedReader(new FileReader("input.txt")); + BufferedWriter writer = new BufferedWriter(new FileWriter("output.txt")); + + String line; + while ((line = reader.readLine()) != null) { + String result = solveExpression(line); + writer.write(line + " = " + result); + writer.newLine(); + } + + reader.close(); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static String solveExpression(String expression) { + Stack operands = new Stack<>(); + Stack operators = new Stack<>(); + + for (int i = 0; i < expression.length(); i++) { + char c = expression.charAt(i); + if (Character.isDigit(c)) { + StringBuilder num = new StringBuilder(); + num.append(c); + while (i + 1 < expression.length() && (Character.isDigit(expression.charAt(i + 1)) || expression.charAt(i + 1) == '.')) { + num.append(expression.charAt(++i)); + } + operands.push(Integer.parseInt(num.toString())); + } else if (c == '(') { + operators.push(c); + } else if (c == ')') { + while (operators.peek() != '(') { + operands.push(applyOperator(operators.pop(), operands.pop(), operands.pop())); + } + operators.pop(); + } else if ("+-*/^".indexOf(c) != -1) { + while (!operators.empty() && precedence(operators.peek()) >= precedence(c)) { + operands.push(applyOperator(operators.pop(), operands.pop(), operands.pop())); + } + operators.push(c); + } + } + + while (!operators.empty()) { + operands.push(applyOperator(operators.pop(), operands.pop(), operands.pop())); + } + + return String.valueOf(operands.pop()); + } + + private static int precedence(char operator) { + if (operator == '+' || operator == '-') { + return 1; + } else if (operator == '*' || operator == '/') { + return 2; + } else if (operator == '^') { + return 3; + } + return -1; + } + + private static int applyOperator(char operator, int b, int a) { + switch (operator) { + case '+': + return a + b; + case '-': + return a - b; + case '*': + return a * b; + case '/': + if (b == 0) throw new ArithmeticException("Division by zero"); + return a / b; + case '^': + return (int) Math.pow(a, b); + } + return 0; + } +} diff --git a/ignitershub_assign/src/challenge_03/palindrome.java b/ignitershub_assign/src/challenge_03/palindrome.java new file mode 100644 index 0000000..a775100 --- /dev/null +++ b/ignitershub_assign/src/challenge_03/palindrome.java @@ -0,0 +1,37 @@ +package challenge; + +import java.util.Scanner; + +public class palindrome { + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + System.out.print("Enter a string: "); + String input = scanner.nextLine(); + + if (isPalindrome(input)) { + System.out.println("The input '"+input+"' is a palindrome."); + } else { + System.out.println("The input '"+input+"' is not a palindrome."); + } + } + + public static boolean isPalindrome(String str) { + // Remove all non-alphanumeric characters and convert to lowercase + String cleanStr = str.replaceAll("[^a-zA-Z0-9]", "").toLowerCase(); + + // Check if the cleaned string is a palindrome + int left = 0; + int right = cleanStr.length() - 1; + while (left < right) { + if (cleanStr.charAt(left) != cleanStr.charAt(right)) { + return false; + } + left++; + right--; + } + return true; + } +} + diff --git a/ignitershub_assign/src/challenge_04/string_manipulation.java b/ignitershub_assign/src/challenge_04/string_manipulation.java new file mode 100644 index 0000000..36b5f22 --- /dev/null +++ b/ignitershub_assign/src/challenge_04/string_manipulation.java @@ -0,0 +1,39 @@ +package challenge; + +import java.util.Scanner; + +public class string_manipulation { + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + System.out.print("Enter a sentence: "); + String input = scanner.nextLine(); + + // Count the number of words in the sentence + int wordCount = countWords(input); + System.out.println("Number of words in the sentence: " + wordCount); + + // Reverse the order of words in the sentence + String reversedSentence = reverseWords(input); + System.out.println("Reversed sentence: " + reversedSentence); + + // Replace all spaces with hyphens + String hyphenatedSentence = input.replace(" ", "-"); + System.out.println("Modified sentence: " + hyphenatedSentence); + } + + public static int countWords(String sentence) { + String[] words = sentence.split("\\s+"); + return words.length; + } + + public static String reverseWords(String sentence) { + String[] words = sentence.split("\\s+"); + StringBuilder reversed = new StringBuilder(); + for (int i = words.length - 1; i >= 0; i--) { + reversed.append(words[i]).append(" "); + } + return reversed.toString().trim(); + } +} diff --git a/ignitershub_assign/src/module-info.java b/ignitershub_assign/src/module-info.java new file mode 100644 index 0000000..1d126af --- /dev/null +++ b/ignitershub_assign/src/module-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * + */ +module ignitershub_assign { +} \ No newline at end of file