Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear reader,

I am originally a python programmer, but for reasons I need to learn java. I am still learning and I make a lot of basic mistakes because I confuse myself from time to time with python, sorry for that. Below you are able to find a "text based adventure", I wrote this in python which worked great! but to learn java I am rewriting it in java, however I am having a hard time and I do not understand all the errors. I am used to make a def and let the python program loop through several until there is a break or exit (I call them def loops, but correct me if it is something else). I hope you are able to understand what I tried to do down below.

I am looking forward for a reply

-Sjoerd



Java
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;

public class AppTest {
	
	public static void main(String[] args) {
	
		String[] tekendoos = new String[] {"ckv module"};
	
	
	public void Start(tekendoos) {
		System.out.println("[-De lift van WIM Inc.-]");
		System.out.println("1.) niveau 1 - Wims loerhokje");
		System.out.println("2.) niveau 2 - Juuls onderhoud station");
		System.out.println("3.) niveau 3 - Sjoerds archief");
		System.out.println("4.) niveau 4 - Adries gymzaal");
		System.out.println("5.) niveau 5 - Henks kantoor");
		System.out.println("6.) niveau 6 - Aula");
		
		List<String> cmdlist = Arrays.asList("1", "2", "3", "4", "5", "6");
		cmd = GetCmd(cmdlist);
		
		if (cmd.equals("1")) {
			System.out.println("test");
		}
		else if (cmd.equals("2")) {
			System.out.println("test");
		}
		else if (cmd.equals("3")) {
			System.out.println("test");
		}
		else if (cmd.equals("4")) {
			System.out.println("test");
		}
		else if (cmd.equals("5")) {
			System.out.println("test");
		}
		else if (cmd.equals("6")) {
			System.out.println("test");
		}
			
		
	}
	
	
	public void Onderhoud (tekendoos) {
		
	}
	
	public void GetCmd (cmdlist) {
		Scanner toetsenbord = new Scanner(System.in);
		String Help, Tekendoos, Stop;
		
		System.out.print("Sjoerd:> ");
		cmd = toetsenbord.next();
		
		if (Arrays.asList(cmdlist).contains(cmd)) {
			return cmd;			
		}
		
		else if (cmd.equalsIgnoreCase("help")) {
			System.out.println("typ: 'tekendoos' om te kijken wat je hebt");
			System.out.println("of 'stop' om op te geven, dan ben je echt zwak");
			System.out.println("of 'ckv module' om je geest op andere wezens aan te sluiten");
		}
		else if (cmd.equalsIgnoreCase("tekendoos")) {
			System.out.println("je bekijkt je tekendoos");
			System.out.println(Arrays.toString(tekendoos));
		}
		else if (cmd.equalsIgnoreCase("stop")) {
			System.out.println("Je benaderd het spoor");
			TimeUnit.SECONDS.sleep(2);
			System.out.println("Je ziet het gele licht");
			TimeUnit.SECONDS.sleep(2);
			System.out.println("Je kopt de trein");
			TimeUnit.SECONDS.sleep(2);
			System.out.println("Stef is trots");
			TimeUnit.SECONDS.sleep(2);
			System.exit();
		}
		
	}
	
} 

}


What I have tried:

I have read a lot of documentation but whenever I thought to fix it, I did some pythonic thing which only makes it worse.
Posted
Updated 10-Nov-17 7:20am

1 solution

Go to The Java™ Tutorials[^] and work through the tutorials. It is the best way to get a good grounding in the language.
 
Share this answer
 
Comments
Member 12952906 10-Nov-17 13:26pm    
Dear Richard, thanks for your post, I am indeed following tutorials, but the problem is, I write things in python.. which makes it really hard to understand where things go wrong. You got any tips for me on the problem?
Richard MacCutchan 10-Nov-17 18:16pm    
Yes, follow my suggestion above: study Java, and practice, practice, practice.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900