March 28, 2015

Homework Help: Computer Science-Java

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


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(;

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

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!");;




Answer this Question

First Name:
School Subject:

Related Questions

Computer Science - Java - Hi, For an assignment I am doing, we have to have 2 ...
computer science - Hi, I have this quick question: A Java interface can be used ...
Computer Science - Could someone show me an example of a service class that ...
Computer Science Java - I have to write program for a dice game and use a ...
Computer Science - Consider the following application files: /JavaCS1/src/...
English - Which class are you in? I'm in class 2. What class are you in? I'm in ...
Math - Your class decides to publish a calendar to raise money. The initial cost...
C# Programming - There are three seating categories at an athletic stadium. For ...
java - I hava a Employee class and my main class. But in my netbeans it is ...
social studies - How do I make a calendar for the month of November? if you want...