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