Jiskha Homework Help
SATURDAY
November 21, 2009
SCHOOL SUBJECTS
- Art
- Business
- Computers
- English
- Foreign Languages
- Health
- Home Economics
- Math
- Music
- Physical Education
- Science
- Social Studies
GRADE LEVELS
- Preschool
- Kindergarten
- Elementary School
- 1st Grade
- 2nd Grade
- 3rd Grade
- 4th Grade
- 5th Grade
- 6th Grade
- 7th Grade
- 8th Grade
- High School
- 9th Grade
- 10th Grade
- 11th Grade
- 12th Grade
- College
- Adult Education
Post a New Question | Current Questions | Chat With Live Tutors

Homework Help Forum: Computer Science-Java

Posted by Lisa on Tuesday, November 3, 2009 at 5:45pm.

Hi,

I am writing an application class for a Lunar Calendar I created in a service class and I have to make sure it is able to detect that the year entered is not in the range of values(I have done this in the service class using a switch statement) and be able to detect if the year is a valid integer. I need a little help with the last one.

Here is what I have so far:

package classes;

import java.util.InputMismatchException;
import java.util.Scanner;

public class LunarCalendarApp {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

final int SENTINEL = -1;
boolean validInput = false;

System.out.println("Enter a year:");
int someYear = in.nextInt();

while(someYear != SENTINEL){

LunarCalendar calen = new LunarCalendar (someYear);
calen.Calendar();

do {

try {

System.out.println("Enter a year:");
validInput = in.hasNext();
someYear = in.nextInt();

}

catch (InputMismatchException e)
{ System.out.println("This is not an integer!");
in.next();
}

}while(!validInput);

}
}

}

No one has answered this question yet.

Answer this Question

First Name:
School Subject:
Answer:

For Further Reading

SEARCH

COMMUNITY
FEATURES
- Live Tutors
- Net Riddle
- Reference
- Search