01 - Introduction to Intermediate Java Course
Goals
- Get familiar with schedule, attendance, teachers, tools
- Get to know each other
- Course introduction
- Install required software
- Learn how to create a new project with IntelliJ
- Do some basic Java exercises!
Slides
Java Basics Recap
package com.redi.j2;
public class Main {
public static void main(String[] args) {
System.out.println("Hello World");
String name = "Memet";
String profession = "skydiver";
int age = 40;
boolean smoking = false;
someMethod(profession);
for (int i = 0; i < 10; i++) {
System.out.println("hey " + i);
}
}
private static void someMethod(String profession) {
if (profession.equals("skydiver")) {
System.out.println("Cool");
} else {
System.out.println("not cool");
}
}
}
Exercises
Same exercises as on slides, copied here for convenience.
Exercise 1
Write a method that for X and Y given by arguments prints square of each number between X and Y.
2 - 4
3 - 9
β¦
Solution:
Exercise 2
In Polish language there is a rule that if name ends with βaβ itβs a female name, if not itβs a male name.
Write a method that checks if Polish name given by variable is a male or female
For example:
Krysian - male
Solution:
Exercise 3
Write a method that for X and Y, for each number between X and Y writes a number and if its odd or even.
Solution:
Exercise 4
Write a method that for age given by parameter prints if is underage (and then how many years left until becomes an adult), or adult, if can buy a beer.
In Germany you become an adult at 18 but you can buy a beer already when youβre 16.
Solution:
Exercise 5
Write a method that calculates how much money stays in the pocket of a freelancer in Poland. Each freelancer has to pay 300 EUR insurance and income tax is flat 19%.
For example, if freelancer made 5000 EUR, in his pocket stays 4700 * 81% = 3807 EUR.
Solution:
Homework
Write a program that for given value of variable βheightβ will print out right-half of the christmas tree to the console.
- Tree starts with βIβ on the top and ends with βMβ on the bottom.
- Tree is built from βXβ and βYβ characters one after another
For example for height
equals 6 it will print:
I
XY
XYX
XYXY
XYXYX
M
package com.example.demo;
public class TreeExercise {
public static void main(String[] args) {
int height = 8;
// put your code here
}
}
Thx to Elena - even better - way way more optimised solution: