This is could some help me out and tell me why my code isnt running , thanks!

import java.util.*; // import utilities for scanner

public class month {		//declaring our class
	public static int monthNumber;			//inital month number
	public static int current_month;		//current month variable
	private static month monthnew;//declaring an object of type month
	static int obj_instantiate;
        String month_str;
        public static void main(String[] args){  						System.out.print("Please enter the month: "); //print statement
			Scanner keyboard = new Scanner(;//input statement
			while(keyboard.hasNextInt())//while the user types in an int execute the loop if the user does not the loop will exit
				monthnew.set_month(keyboard.nextInt());//here is where I was having problems, I am seeking the integer the user enters.
	public month(){							//our constructor
		int monthNumber=1;					//inital value of month if none is set
		month monthnew= new month();		//creating an object of type month
	public month(int m){
        if (m>12 || m<1){
            System.out.print("please enter a valid month") ;
        else monthNumber=m;
        month second_month=new month();

                    public  month copy(){ 
//I know I kind of screwed up here , I couldnt                                   
//figure it out how to copy the specific object its called from
                            month month_copy=new month();
                            month third_month= new month();
// I have an error here not sure why I cant do this second_month third_month=new second_month();
                            return month_copy;
        public String toString(int x){
            { case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
            case 9:
            case 10:
            case 11:
            case 12:
            return month_str;
                        public boolean eqauls(month o){
                           boolean correct_month=false;
                            return correct_month;

	public static int set_month(int m) //my set method
		if(m>12 || m<1)
			System.out.print("Please enter a valid month");
		return monthNumber;
	public static int get_month() // my get method
		System.out.print("The current month number is:");
		return monthNumber;
 public static int dis_obj(){
     System.out.print("\n the number of obj instantiated is:" );
     return obj_instantiate;

Recommended Answers

All 6 Replies

Member Avatar

Did you compile it? Did you get any errors? What errors did you get?
Did you try to run it? Did you get any errors? What errors did you get?
What output did you get? What output didn't you get? What output were you expecting?
We're not sitting beside you to see all of these things.

Your code makes no sense.
For example:
- When you make a Main object, in the constuctor you make another one, and in that constructor you make another one: a never ending loop.

I think you should first start thinking about what you want to code, and then start coding. There is not 1 problem you can fix here, you have to rewrite the code.

I am to make 2 constructors. thats why there are two of them

maybe, but that's not the point
they should not just call each other. they are supposed to give the calling class alternative ways to create an instance of the class.

I think you should google on java Objects Tutorial. Read a little about abjects and classes, then start coding. Start with a small program to test what you want.

Think of multiple constructors in a class as being different ways to create your object. If, for example, your class involved some sort of form you could construct a blank form or one already filled out. The filled out form would have a constructor that allowed parameters to fill out the form and the other form could have no parameters.

Check here for constructor information:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.