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(System.in);//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.
				System.out.print(get_month());//ouput
                                System.out.print(dis_obj());
			}
	
        }
	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();
        obj_instantiate+=1;
	}
	

	
                    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();
                            
                            obj_instantiate+=1;
                            month third_month= new month();
// I have an error here not sure why I cant do this second_month third_month=new second_month();
                            obj_instantiate+=1;
                            return month_copy;
                        }
      
        public String toString(int x){
            switch(x)
            { case 1:
                month_str="janurary";
            case 2:
                month_str="feburary";
            case 3:
                month_str="march";
            case 4:
                month_str="april";
            case 5:
                month_str="may";
            case 6:
                month_str="june";
            case 7:
                month_str="july";
            case 8:
                month_str="august";
            case 9:
                month_str="september";
            case 10:
                month_str="october";
            case 11:
                month_str="november";
            case 12:
                month_str="december";
            
                
            }
            System.out.print(month_str);
            return month_str;
        }
        
                        public boolean eqauls(month o){
                           boolean correct_month=false;
                            if(monthNumber==o.get_month()){
                               correct_month=true;
                           }
                            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");
		
		}
		else
			monthNumber=m;
	
		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;
 }
 
            
}
Member Avatar for hfx642

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: http://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html

Be a part of the DaniWeb community

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