diff --git a/README.md b/README.md deleted file mode 100644 index a974d78..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# JobHacker-System -This repo for JobHacker Community tasks. diff --git a/Week 5/Task 2-Word Count/.gitignore b/Week 5/Task 2-Word Count/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/Week 5/Task 2-Word Count/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Week 5/Task 2-Word Count/.idea/.gitignore b/Week 5/Task 2-Word Count/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/Week 5/Task 2-Word Count/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Week 5/Task 2-Word Count/.idea/misc.xml b/Week 5/Task 2-Word Count/.idea/misc.xml new file mode 100644 index 0000000..0548357 --- /dev/null +++ b/Week 5/Task 2-Word Count/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Week 5/Task 2-Word Count/.idea/modules.xml b/Week 5/Task 2-Word Count/.idea/modules.xml new file mode 100644 index 0000000..300f29f --- /dev/null +++ b/Week 5/Task 2-Word Count/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Week 5/Task 2-Word Count/.idea/vcs.xml b/Week 5/Task 2-Word Count/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Week 5/Task 2-Word Count/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Week 5/Task 2-Word Count/Lincoln.txt b/Week 5/Task 2-Word Count/Lincoln.txt new file mode 100644 index 0000000..e07ecc7 --- /dev/null +++ b/Week 5/Task 2-Word Count/Lincoln.txt @@ -0,0 +1,4 @@ +Java is /a -programming ,language. +Java is _easy. +the file contains 8 + diff --git a/Week 5/Task 2-Word Count/Task 2-Word Count.iml b/Week 5/Task 2-Word Count/Task 2-Word Count.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Week 5/Task 2-Word Count/Task 2-Word Count.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Week 5/Task 2-Word Count/src/Main.java b/Week 5/Task 2-Word Count/src/Main.java new file mode 100644 index 0000000..6d67607 --- /dev/null +++ b/Week 5/Task 2-Word Count/src/Main.java @@ -0,0 +1,28 @@ +import java.io.*; +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + try { + File file = new File("Lincoln.txt"); + Scanner scanner = new Scanner(file); + int count = 0; + while (scanner.hasNext()) { + scanner.next(); + count++; + } + scanner.close(); + + BufferedWriter writer = new BufferedWriter(new FileWriter(file, true)); + String str = "the file contains " + count + '\n'; + writer.write(str); + writer.newLine(); + writer.close(); + + } catch (FileNotFoundException e) { + System.out.println(e.getMessage()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/Week 5/Task 3/.gitignore b/Week 5/Task 3/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/Week 5/Task 3/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Week 5/Task 3/.idea/.gitignore b/Week 5/Task 3/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/Week 5/Task 3/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Week 5/Task 3/.idea/misc.xml b/Week 5/Task 3/.idea/misc.xml new file mode 100644 index 0000000..0548357 --- /dev/null +++ b/Week 5/Task 3/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Week 5/Task 3/.idea/modules.xml b/Week 5/Task 3/.idea/modules.xml new file mode 100644 index 0000000..40d4bd4 --- /dev/null +++ b/Week 5/Task 3/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Week 5/Task 3/.idea/vcs.xml b/Week 5/Task 3/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Week 5/Task 3/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Week 5/Task 3/Scores.txt b/Week 5/Task 3/Scores.txt new file mode 100644 index 0000000..939764e --- /dev/null +++ b/Week 5/Task 3/Scores.txt @@ -0,0 +1,2 @@ +34 34 54 14 32 24 31 34 53 74 22 29 +4 34 14 14 32 24 31 34 53 74 22 29 \ No newline at end of file diff --git a/Week 5/Task 3/Task 3.iml b/Week 5/Task 3/Task 3.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Week 5/Task 3/Task 3.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Week 5/Task 3/src/FileManipulation.java b/Week 5/Task 3/src/FileManipulation.java new file mode 100644 index 0000000..a336a03 --- /dev/null +++ b/Week 5/Task 3/src/FileManipulation.java @@ -0,0 +1,44 @@ +import java.io.*; +import java.net.URL; +import java.util.*; + +public class FileManipulation { + File readFromWebToFile(String url) throws IOException { + URL fileUrl = new URL(url); + InputStream is = fileUrl.openStream(); + String filePath = "Scores.txt"; + FileOutputStream fos = new FileOutputStream(filePath); + + byte[] buffer = new byte[1024]; + int len; + while ((len = is.read(buffer)) != -1) { + fos.write(buffer, 0, len); + } + is.close(); + fos.close(); + return new File(filePath); + } + + int getSum(File filePath) throws IOException{ + FileInputStream file =new FileInputStream(filePath); + Scanner scanner = new Scanner(file); + int sum = 0; + while (scanner.hasNextInt()) { + int score = scanner.nextInt(); + sum += score; + } + return sum; + } + + int getAverage(File filePath) throws IOException{ + FileInputStream file =new FileInputStream(filePath); + Scanner scanner = new Scanner(file); + int sum = 0 , count = 0; + while (scanner.hasNextInt()) { + int score = scanner.nextInt(); + sum += score; + count++; + } + return sum / count; + } +} diff --git a/Week 5/Task 3/src/Main.java b/Week 5/Task 3/src/Main.java new file mode 100644 index 0000000..c4c4438 --- /dev/null +++ b/Week 5/Task 3/src/Main.java @@ -0,0 +1,16 @@ +import java.io.File; +import java.io.IOException; + +public class Main { + + public static void main(String[] args) { + FileManipulation file = new FileManipulation(); + try{ + File f = file.readFromWebToFile("http://liveexample.pearsoncmg.com/data/Scores.txt"); + System.out.println("The summation of words: " + file.getSum(f)); + System.out.println("The average of words: " + file.getAverage(f)); + }catch (IOException e){ + System.out.println(e.getMessage()); + } + } +} \ No newline at end of file diff --git a/Week 5/Task1-InputMismatchException/.gitignore b/Week 5/Task1-InputMismatchException/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/Week 5/Task1-InputMismatchException/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Week 5/Task1-InputMismatchException/.idea/.gitignore b/Week 5/Task1-InputMismatchException/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/Week 5/Task1-InputMismatchException/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Week 5/Task1-InputMismatchException/.idea/misc.xml b/Week 5/Task1-InputMismatchException/.idea/misc.xml new file mode 100644 index 0000000..0548357 --- /dev/null +++ b/Week 5/Task1-InputMismatchException/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Week 5/Task1-InputMismatchException/.idea/modules.xml b/Week 5/Task1-InputMismatchException/.idea/modules.xml new file mode 100644 index 0000000..d9a6d36 --- /dev/null +++ b/Week 5/Task1-InputMismatchException/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Week 5/Task1-InputMismatchException/.idea/vcs.xml b/Week 5/Task1-InputMismatchException/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Week 5/Task1-InputMismatchException/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Week 5/Task1-InputMismatchException/InputMismatchException.iml b/Week 5/Task1-InputMismatchException/InputMismatchException.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Week 5/Task1-InputMismatchException/InputMismatchException.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Week 5/Task1-InputMismatchException/src/Main.java b/Week 5/Task1-InputMismatchException/src/Main.java new file mode 100644 index 0000000..5bf6d16 --- /dev/null +++ b/Week 5/Task1-InputMismatchException/src/Main.java @@ -0,0 +1,25 @@ +import java.util.InputMismatchException; +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + int num1 , num2 ; + boolean isValidInput = false; + + while (!isValidInput) { + try { + System.out.print("Enter first integer: "); + num1 = scanner.nextInt(); + System.out.print("Enter second integer: "); + num2 = scanner.nextInt(); + + System.out.println("You entered " + num1 + " and " + num2 + "\nThe summation is: " + (num1 + num2)); + isValidInput = true; + } catch (InputMismatchException e) { + System.out.println("Invalid input, Enter integers only."); + scanner.nextLine(); + } + } + } +}