Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Branch 1 #6

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Email-Sender-Using-Java/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.ashish</groupId>
<artifactId>Email-Sender-Using-Java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Email-Sender-Using-Java</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]";
String from = "[email protected]";

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("[email protected]","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...................");




}
}
Original file line number Diff line number Diff line change
@@ -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 );
}
}
4 changes: 4 additions & 0 deletions Email-Sender-Using-Java/target/classes/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Manifest-Version: 1.0
Build-Jdk-Spec: 17
Created-By: Maven Integration for Eclipse

Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.ashish</groupId>
<artifactId>Email-Sender-Using-Java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Email-Sender-Using-Java</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added ignitershub_assign/bin/module-info.class
Binary file not shown.
3 changes: 3 additions & 0 deletions ignitershub_assign/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
10 - 2 =
100 * ( 2 + 12 ) =
(10 + 5^2) ( (5*-2) + 9 - 3^3) / 2=
3 changes: 3 additions & 0 deletions ignitershub_assign/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
10 - 2 = = 8
100 * ( 2 + 12 ) = = 1400
(10 + 5^2) ( (5*-2) + 9 - 3^3) / 2= = -490
91 changes: 91 additions & 0 deletions ignitershub_assign/src/challenge_01/input_output_files.java
Original file line number Diff line number Diff line change
@@ -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<Integer> operands = new Stack<>();
Stack<Character> 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;
}
}
37 changes: 37 additions & 0 deletions ignitershub_assign/src/challenge_03/palindrome.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

Loading