Computer Science-Java

posted by .


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




Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. computer science

    Hi, I have this quick question: A Java interface can be used almost anywhere a class can be. Describe the one place/situation where it cannot be used in a place of a class name. Thanks a lot. Not sure what you mean by "in a place of …
  2. English

    Which class are you in? I'm in class 2. What class are you in?
  3. Computer Science Java

    I have to write program for a dice game and use a boolean variable in the application class of the dice game that equals true when snake eyes, doubles, and box cars have been meet. I am having a little trouble doing that in my application …
  4. Computer Science - Java

    Hi, For an assignment I am doing, we have to have 2 service classes and one application class. One service class is already written (i.e. DiceGame1) and I am writing another one (i.e. Player) that is supposed to use the previous service …
  5. Computer Science

    Could someone show me an example of a service class that reads an input file (Java)?
  6. Computer Science

    Consider the following application files: /JavaCS1/src/guiprojectcity2/ import java.awt.*; import javax.swing.*; public class DisplayWindow extends JFrame{ private Container c; public DisplayWindow(){ super("Display"); …
  7. Math

    Your class decides to publish a calendar to raise money. The initial cost, regardless of the number of calendars printed, is $900. After the initial cost, each calendar costs $1.50 to produce. What is the minimum number of calendars …
  8. C# Programming

    There are three seating categories at an athletic stadium. For a baseball game, Class A seats cost $15 dollars each, Class B seats cost $12 each, and Class C seats cost $9 each. Create an application that allows the user to enter the …
  9. computer science java

    write a program in java for a grocery (fruit shop calculate the prize of bananas @ $.89/kg declaring the the prices of all either as instances or class variables.declare the weight of the fruit as local variables
  10. Programming

    Widget company runs a small factory that makes several types of nuts and bolts. They employ (a)1 (b)2 (c)3. Each factory worker can work a maximum of (a)40 hours normal working hours per week. All hours over 40 are paid as over-time …

More Similar Questions