From a8a36513261f4e9dc14bdad47bfc49532aa02606 Mon Sep 17 00:00:00 2001 From: Eva Kktsidou Date: Wed, 18 Oct 2017 17:00:29 +0200 Subject: [PATCH 1/4] Exarcises 1 and 2 --- Structures/src/AssignGrade.java | 9 ++++++++- Structures/src/EvenOdd.java | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Structures/src/AssignGrade.java b/Structures/src/AssignGrade.java index 8b8e871..49b599d 100644 --- a/Structures/src/AssignGrade.java +++ b/Structures/src/AssignGrade.java @@ -5,8 +5,15 @@ public class AssignGrade { public static void main(String[] args) { - Scanner scan = new Scanner(System.in); + int score = 80; + double grade = ((100 - score)/50.0) * 3 + 1; + + if (grade <= 4.0) { + System.out.println("Pass with grade: " + grade); + } else { + System.out.println("Fail with grade: " + grade); + } //todo: when executing the program you will be ask to write a score. //The program converts the score then into a grade and prints that grade (1.0, 1.3, 1.7, ...) //Note that the student passed when the student gets a score of 50.0 points (4.0) diff --git a/Structures/src/EvenOdd.java b/Structures/src/EvenOdd.java index 8a382c3..a57b1c0 100644 --- a/Structures/src/EvenOdd.java +++ b/Structures/src/EvenOdd.java @@ -7,6 +7,15 @@ public class EvenOdd { public static void main(String[] args) { Scanner scan = new Scanner(System.in); + int number = 15; + + for (int count = 0; count < number; count ++) { + if (count % 2 != 0) { + System.out.println(count); + } + } + + //todo: The program takes a number as input. //It then goes through all integer values till reaching that value and prints all the odd ones. From aa1db78f3e75c6dfc1731162a1fc488166e8d1da Mon Sep 17 00:00:00 2001 From: EvaKoktsidou Date: Tue, 24 Oct 2017 11:07:22 +0200 Subject: [PATCH 2/4] Exercises 1 and 2 --- Structures/src/AssignGrade.java | 4 +++- Structures/src/EvenOdd.java | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Structures/src/AssignGrade.java b/Structures/src/AssignGrade.java index 49b599d..5440627 100644 --- a/Structures/src/AssignGrade.java +++ b/Structures/src/AssignGrade.java @@ -5,8 +5,10 @@ public class AssignGrade { public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + System.out.println("Score: "); + int score = scan.nextInt(); - int score = 80; double grade = ((100 - score)/50.0) * 3 + 1; if (grade <= 4.0) { diff --git a/Structures/src/EvenOdd.java b/Structures/src/EvenOdd.java index a57b1c0..db1fbae 100644 --- a/Structures/src/EvenOdd.java +++ b/Structures/src/EvenOdd.java @@ -6,8 +6,9 @@ public class EvenOdd { public static void main(String[] args) { Scanner scan = new Scanner(System.in); + System.out.println("Number: "); + int number = scan.nextInt(); - int number = 15; for (int count = 0; count < number; count ++) { if (count % 2 != 0) { From abc16227f02e9b08fc043b5c6951165d3280fe42 Mon Sep 17 00:00:00 2001 From: EvaKoktsidou Date: Wed, 25 Oct 2017 15:37:17 +0200 Subject: [PATCH 3/4] Exercise 3.1 --- Methods/src/Circle.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Methods/src/Circle.java b/Methods/src/Circle.java index 76aa810..d8a0fbb 100644 --- a/Methods/src/Circle.java +++ b/Methods/src/Circle.java @@ -1,5 +1,33 @@ +import java.util.Scanner; public class Circle { //todo: add some methods to compute a circle's diameter, circumference and area. //print some outputs to confirm you methods are working right. + public static double diameter(double r) { + double d = 2 * r; + return d; + } + + public static double circ(double r) { + double pi = Math.PI ; + double c = 2 * pi * r ; + return c ; + } + + public static double area(double r) { + double pi = Math.PI ; + double a = pi * r * r ; + return a ; + } + + public static void main(String[] args) { + + Scanner scan = new Scanner(System.in); + System.out.println("Radius: "); + Double r = scan.nextDouble(); + + System.out.println(diameter(r)); + System.out.println(circ(r)); + System.out.println(area(r)); + } } From ad1254365a539dff67c0e74a80a76854170a506f Mon Sep 17 00:00:00 2001 From: EvaKoktsidou Date: Wed, 25 Oct 2017 15:47:49 +0200 Subject: [PATCH 4/4] Exercise 3.2 --- Methods/src/Prime.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Methods/src/Prime.java b/Methods/src/Prime.java index 15ab306..6f44a9b 100644 --- a/Methods/src/Prime.java +++ b/Methods/src/Prime.java @@ -3,9 +3,30 @@ public class Prime { + public static boolean prime(int n) { + + if (n <= 1) { + return false; + } else if (n <= 3 ) { + return true; + } else if (n % 2 == 0 || n % 3 == 0) { + return false; + } else { + for (int i = 5; i * i <= n; i = i + 6 ) { + if (n % i == 0 || n % (i + 2) == 0) { + return false; + } + return true; + } + } return true; + } + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int n = scan.nextInt(); + System.out.println("The number " + n + " is prime: " + prime(n)); //todo: write a method which tells you if a given number is a prime or not }