Java - Einführung

From Coders.Bay Wiki
Jump to navigation Jump to search

Woche 1 / Tag 1

Variablen und Datentpyen

Aufgabe 1.1 - Erzähl mir etwas über dich

Deklariere Variablen für dein Alter, deinen Vornamen, dein Geschlecht, deinen Nachnamen, dein Geburtsdatum, deinen Notendurchschnitt und dafür ob du verheiratet bist oder nicht. Überleg dir gut welchen Datentyp du für welche Variablen am besten verwenden solltest.

Gib alle Variablen mit System.out.println auf der Konsole aus.

Aufgabe 1.2 - Einfache Rechenaufgaben

Deklariere zwei numerische Variablen mit beliebigen Werten. Errechne deren Summe, Differenz, Produkt und Quotient und gib die Rechnung mit dem Ergebnis mit System.out.println/System.out.printf auf der Konsole aus. Rechne einmal mit ganzzahligen und einmal mit gebrochenen Zahlen!

Bonus: Gib die Kommazahlen schön formatiert auf der Konsole aus.

Eine Ausgabe sollte folgendermaßen aussehen:

Beispiel Ausgabe

138 + 235 = 373 138 - 235 = -97

Aufgabe 1.3 - Arbeiten mit Strings [🤓 Advanced]

Lege einen String mit dem Inhalt “ Hello World! ” an (enthält vorne und hinten Leerzeichen).

  • Gib den String und seine Länge auf der Konsole aus.
  • Gib den String in einigen Abwandlungen auf der Konsole aus:
    • alle Buchstaben in Großbuchstaben
    • alle Buchstaben in Kleinbuchstaben
    • ersetze “World” mit “Codersbay”
    • ohne Leerzeichen zu Beginn des Texts
  • Gib den String 15 mal wiederholt mit einem Zeilenumbruch zum Trennen aus (ohne die Codezeile 15 mal zu kopieren 😉)

Suche auf der offiziellen Dokumentations-Seite von Strings nach nützlichen Methoden.

Variables and Datatypes

Exercise 1.1 - Tell me about yourself

Declare variables to express your age, first name, gender, last name, birthday, average grade and whether you are married or not. Think which datatype is well suited for which variable.

Print all variables to the console with System.out.println

Exercise 1.2 - Simple Calculations

Declare two numeric variables with arbitary values. Calculate their sum, difference, product and quotient and print the calculation with the result on the console with System.out.println/System.out.printf. Perform all calculations with whole numbers and fractional numbers.

Bonus: Try to limit the decimal places of your calculations with the fractional numbers.

Your output should look like this:

138 + 235 = 373 138 - 235 = -97

Exercise 1.3 - Working with Strings [🤓 Advanced]

Create a variable of type String with “ Hello World! ” as its content (contains leading and trailing spaces).

  • Print the String and its length to the console.
  • Print the String with some variations:
    • all letters in uppercase
    • all letters in lowercase
    • replace “World” with “Codersbay”
    • without the leading spaces
  • Repeat the printed String 15 times seperated with linebreaks (don't copy the code 15 times 😉)

You might find the official documentation of the String class helpful.

Woche 1 / Tag 2

Zuweisungs- und logische Operatoren

Aufgabe 2.2 Eigenschaften einer Zahl

Schreibe ein Programm, dass von der Konsole eine Zahl einliest und ausgibt:

  • ob es sich um eine runde Zahl handelt
  • ob die Zahl gerade ist
  • ob die Zahl deiner Glückszahl entspricht (denk dir hierfür einfach eine eigene Glückszahl aus und gib sie zu Beginn des Programms auf der Konsole aus)
  • ob die Zahl zweistellig ist

Tipp: Für die ersten beiden Punkte wirst du die Modulo Funktion brauchen.

Aufgabe 2.3 Arbeits- oder Freizeit?

In der CODERS.BAY arbeiten wir von 8 bis 16 Uhr. Schreibe ein Programm, dass eine Zahl von der Konsole einliest und ausgibt ob die Stunde in der Arbeitszeit liegt oder nicht.

Bonus: von 12 bis 13 Uhr ist immer Mittagspause, gib also in der Zeit aus, dass Mittag ist.

Assignment and logical operators

Aufgabe 2.2 Characteristics of a number

Write a program that reads a number from the console and calculates and prints characteristics of it:

  • is the number round
  • is the number even
  • does the number equal your lucky number (choose any lucky number for this and print it to the console at the start of the program)
  • does it have two digits

Hint: You might find the modulo operation helpful for the first two exercises.

Exercise 2.3 free time or work time?

At CODERS.BAY we usually work from 8 to 16 o'clock. Write a program, that reads a number from the console and prints whether that hour is during our work time or not.

Bonus: We go for a lunch break between 12 and 13 o'clock, print that info in case the given number is between 12 and 13.

Bedingungen

Aufgabe: Noten übersetzen

Schreibe ein Programm, dass eine Schulnote in numerischer Form (1-5) in seine textuelle Form übersetzt:

  • Bei einer 1 wird "Sehr gut" auf die Konsole geschrieben
  • Bei einer 2 wird "Gut" auf die Konsole geschrieben
  • Bei einer 3 wird "efriedigend" auf die Konsole geschrieben
  • Bei einer 4 wird "Genügend" auf die Konsole geschrieben
  • Bei einer 5 wird "Nicht Gengügend" auf die Konsole geschrieben

Conditionals

Exercise: Translating grades

Write a program that translates grades from its numerical form to a word representation.

  • Print "Very good" in case of a 1.
  • Print "Good" in case of a 2.
  • Print "Satisfactory" in case of a 3.
  • Print "Sufficient" in case of a 4.
  • Print "Not sufficient" in case of a 5.