Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > Java

Reply
 
LinkBack Thread Tools Display Modes
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
Old 11-03-2005, 06:59 PM   #2 (permalink)
ZimbuTM
Registered User
 
Join Date: Sep 2005
Posts: 10
ZimbuTM is on a distinguished road
Ok, I did this, is it ok?

Code:
//********************************************************
//AUTHOR: Rahul Malik
//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)
    {
		int 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.nextByte();
			userChoice = (char)userChoice;


			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');









	}

}
ZimbuTM is offline   Reply With Quote
Old 11-04-2005, 01:45 AM   #3 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,161
Belisarius is on a distinguished road
A char is an int by another name. You should be able to cast back and forth between them.
__________________
GitS
Belisarius is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
learning to program C++ problem 1 cheawick Standard C, C++ 0 09-18-2005 08:22 PM
SDL program problem... slashdot Standard C, C++ 3 07-22-2005 05:30 PM
need help with copying backwards rogue Standard C, C++ 9 04-24-2005 04:39 PM
C++ Deadlock Detection Program Help... coolsc81 Standard C, C++ 2 10-26-2004 06:14 AM
dynamic allocation..urgent help needed!!! kashif Standard C, C++ 4 04-21-2003 08:50 AM


All times are GMT -8. The time now is 06:19 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting