Created
June 13, 2024 20:37
-
-
Save audunolsen/18480f82aa3be5ccad5110937a2ffdd7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Menu { | |
public static void main(String[] args) { | |
promptUser(); | |
} | |
static void promptUser() { | |
Scanner scanner = new Scanner(System.in); | |
System.out.println("Velg alternativ"); | |
System.out.println("1. Informasjon om alle funn"); | |
System.out.println("2. Informasjon om alle funn eldre enn årstall"); | |
System.out.println("3. Informasjon om antall registrerte funn"); | |
System.out.println("4. Avslutt program"); | |
System.out.print("\nVennligst skriv inn menyvalg (1-4): "); | |
int option = scanner.nextInt(); | |
switch (option) { | |
case 1: | |
System.out.println("Valg 1"); | |
showSeparator(); | |
promptUser(); | |
break; | |
case 2: | |
System.out.println("Valg 2"); | |
listAfterYear(); | |
showSeparator(); | |
promptUser(); | |
break; | |
case 3: | |
System.out.println("Valg 3"); | |
showSeparator(); | |
promptUser(); | |
break; | |
case 4: | |
System.out.println("Valg 4, avslutter program"); | |
break; | |
default: | |
System.out.println("Ugyldig valg"); | |
showSeparator(); | |
promptUser(); | |
break; | |
} | |
} | |
static void listAfterYear() { | |
Scanner scanner = new Scanner(System.in); | |
System.out.print("\nSkriv inn årstall: "); | |
int chosenYear = scanner.nextInt(); | |
System.out.print("\nDu valgte årstall: "); | |
System.out.print(chosenYear); | |
} | |
static void showSeparator() { | |
System.out.println("\n--------------\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment