HELP with really basic Java programming stuff!

Currently reading:
HELP with really basic Java programming stuff!

what / why are you trying to do?

for simple text input i just used to use a simple input class that somone sent me. This is the menu for a quiz program i wrote a bizzillion yeasr ago;

Code:
	private static void quizMenu()
	{
		int quizMenuChoice;

		System.out.println("Welcome to the Quiz\n");
		System.out.println("1.\tPlay Quiz");
		System.out.println("2.\tView High Scores");
		System.out.println("3.\tAdminister Quiz");
		System.out.println("4.\tQuit");
		System.out.print("Please select an option: ");

		quizMenuChoice = SimpleInput.readInt();

		while (quizMenuChoice < 1 | quizMenuChoice > 4)
		{
			System.out.print("\nInvalid Choice. Please enter a number between 1 and 4: ");
			quizMenuChoice = SimpleInput.readInt();
		}

		if (quizMenuChoice == 1)
		{
			newQuizr();
		}
		else if (quizMenuChoice == 2)
		{
			viewScores();
		}
		else if (quizMenuChoice == 3)
		{
			adminQuiz();
		}
		else if (quizMenuChoice == 4)
		{
			System.out.print("\n");
			System.out.print("Are you sure you wish to close the program? Please enter Y or N: ");
	
			string closeProgram = SimpleInput.readString();
		
			while (closeProgram != 'Y' & closeProgram != 'y' & closeProgram != 'N' & closeProgram != 'n')
				{
					System.out.print("\nInvalid Choice. Please enter Y or N: ");
					closeProgram = SimpleInput.readString();
				}
		
				if (closeProgram == 'n' | closeProgram == 'N')
				{
					System.out.print("\n\n");
					int exit = 0;
					System.exit(exit);
			}
		else
		{
			System.out.println("Error");
		}
	}
 
Last edited:
Would it be easier to dump the terminal input (system.in) into an arrayList and then use a foreach loop?

P(y)
 
thanks for all yourt help

this wont be the last time i ask for it trust me!!!!

as promised, i need your help again!...

I've been at this for litrally hours just trying to get this to work...



I'm using switch to make a simple menu that reads towns and temperatures from a file, into 2 arraylists (one 'places' the other 'temps') now i need to be able to sort them, to display then either alphabetically or by temperature. i've worked a certain amount out but i'm constantly getting the same 4 errors, and the internet or my text books are not being any help:

Code:
C:\Java\Projects\zOLD\Menu>build
src\MenuApp.java:68: operator < cannot be applied to java.lang.String,java.lang.String
                if (places.get(j)<places.get(min)){
                                 ^
src\MenuApp.java:73: incompatible types
found   : java.lang.String
required: int
        temp = places.get(i);
                         ^
src\MenuApp.java:74: unexpected type
required: variable
found   : value
        places.get(i) = places.get(min);
                  ^
src\MenuApp.java:75: unexpected type
required: variable
found   : value
        places.get(min) = temp;
                  ^

here is the bit of the code

Code:
        case 3: System.out.println("Exit selected");
                    
            int min;
            int temp;

        for(int i = 0; i < places.size() - 1; i++){
        min = i;

        for(int j=i+1; j<places.size(); j++){
        if (places.get(j)<places.get(min)){
        min = j;
        }
    }

    temp = places.get(i);
    places.get(i) = places.get(min);
    places.get(min) = temp;
}
 
< > and = are numerical operators.

it is saying that are you trying to use them on a string, it's like if "hello" > "goodbye" - ie gibberish.

i'm guessing places is a method and it isn't coded correctly - hence every time you try and call it, it flunks.

lets have a look at what 'places' is trying to do, put the whole code up - it's hard to work out what you're doing with only snippets.
 
< > and = are numerical operators.

it is saying that are you trying to use them on a string, it's like if "hello" > "goodbye" - ie gibberish.

i'm guessing places is a method and it isn't coded correctly - hence every time you try and call it, it flunks.

lets have a look at what 'places' is trying to do, put the whole code up - it's hard to work out what you're doing with only snippets.
Thanks for the reply, i litrally just this second fixed it, by simply replacing "string" with "int" earier on in the program.

now i'm trying to work out how to get the program to close a scanner after 2 pieces of information are inputed from the keyboard without creating some freaky error. :p
 
Back
Top