View Single Post
Old 11-03-2005, 05:26 PM   #1 (permalink)
ZimbuTM
Registered User
 
Join Date: Sep 2005
Posts: 10
ZimbuTM is on a distinguished road
Problem with menu-driven program, please help

Hi all. Basically this program is there to test an already created class. GDate deals with lots of date related methods, stuff like finding yesterday's date, tomorrow's date, etc. It's for an assignment.

I'm having a problem with two things here:

1. I can't figure out how to read the next CHAR from the scanner. I can do int and strings just fine, but I'm confused about chars. (I've tried nextChar(), but that doesn't work).

2. Now using this code below, I get this error when I try to compile: [Nevermind, found out that strings are not allowed in switch statements, I have to make it char, but this comes back to problem 1 up there]

incompatible types
found : java.lang.String
required: int
switch (userChoice)


I figured that using strings would be fine in a switch, but I guess I was wrong, can someone point me in the right direction?

Code:
//********************************************************
//AUTHOR: rm
//Description: Menu-driven program that tests GDate class
//Last modified: Nov. 3rd, 2005
//********************************************************

import java.util.*;

public class GDateTest02
{
	static Scanner console = new Scanner(System.in);

    public static void main(String[] args)
    {
		String userChoice;


		do
		{
			//Display menu options
			System.out.print("\n (a) Enter a date\n");
			System.out.print(" (b) Reset current date");
			System.out.print("\n (c) Print day number of current date");
			System.out.print("\n (d) Print the month name of current date");
			System.out.print("\n (e) Print number of days in current month");
			System.out.print("\n (f) Print leap year status of current year");
			System.out.print("\n (g) Print the day name of current date");
			System.out.print("\n (h) Print the current date");
			System.out.print("\n (i) Print the next day's date");
			System.out.print("\n (j) Print the previous day's date");
			System.out.print("\n (k) Compare dates");
			System.out.print("\n (l) Print calendar");
			System.out.println("\n (m) Exit program\n\n");
			System.out.print("Please make a choice: ");

			userChoice = console.next();

			switch (userChoice)
			{
				//(a) set a date
				case "a": case "A":
				System.out.print("Please enter a year, month and day (y m d): ");
				GDate date = new GDate(console.nextInt(), console.nextInt(), console.nextInt());
				break;

				//reset date to specified value
				case "b": case "B":


			}




		}
		while (userChoice != "m" || userChoice != "M");









	}

}

Last edited by ZimbuTM; 11-03-2005 at 06:48 PM.
ZimbuTM is offline   Reply With Quote