I need help with enums. I don't get them. This is part of a larger assignment, so all I need to do is fix this. I'm trying to assign year levels of school to constants.

public class Student extends Person
{
	public Student( String name, String address, String phone,
		String email, String grade )
	{
		super( name, address, phone, email);
	}
	
	public enum Year
	{
	FIRST( "Freshmen"),
	SECOND("Sophmore"),
	THIRD("Junior"),
	FOURTH("Senior");
	
	public final String gradeLevel;
	
	Year( String grade )
	{
		gradeLevel = grade;
	}
	
	public String getGradeLevel()
	{
		return gradeLevel;
	}
	
}
	
	public String toString()
	{
		return String.format( "%s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n\n" ,
			"Student Object",
			"Name", getFullName(),
			"Address" , getHomeAddress(),
			"Phone #" , getPhoneNumber(),
			"E-mail Address" , getEmailAddress(),
			"Grade Level" );
	}
}

You need a variable of type Year to hold that value in the Student class. Your constructor would also pass a Year value instead of a String. toString() can access the getGradeLevel() method of the enum value to display the string representation you have given those constants.

So bascially I change String grade to Year grade? I don't understand what you mean in the first sentence.

So bascially I change String grade to Year grade? I don't understand what you mean in the first sentence.

Yes, and that needs to be stored in a variable of the enum type Year in your class.

public class Student extends Person
{
	public Student( String name, String address, String phone,
		String email, Year grade )
	{
		super( name, address, phone, email);
	}
	
	public enum Year
{
	Year FIRST = new Year( "Freshmen"),
	Year SECOND = new Year("Sophmore"),
	Year THIRD = new Year("Junior"),
	Year FOURTH = new Year("Senior");

	public final String gradeLevel;
	
	Year( String grade )
	{
		gradeLevel = grade;
	}
	
	public String getGradeLevel()
	{
		return gradeLevel;
	}
	
}
	
	public String toString()
	{
		return String.format( "%s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n\n" ,
			"Student Object",
			"Name", getFullName(),
			"Address" , getHomeAddress(),
			"Phone #" , getPhoneNumber(),
			"E-mail Address" , getEmailAddress(),
			"Grade Level", getGradeLevel() );
	}
}

Is this sorta what you meant? Even if I got the variables wrong.

Well, that is one piece. You have to actually use that variable though

public class Student extends Person
{
  Year studentYear;

	public Student( String name, String address, String phone,
		String email, Year grade )
	{
		super( name, address, phone, email);
                this.studentYear = grade;
	}
	
	public enum Year
        {
	Year FIRST = new Year( "Freshmen"),
	Year SECOND = new Year("Sophmore"),
	Year THIRD = new Year("Junior"),
	Year FOURTH = new Year("Senior");

	public final String gradeLevel;
	
	Year( String grade )
	{
		gradeLevel = grade;
	}
	
	public String getGradeLevel()
	{
		return gradeLevel;
	}
	
    }
	
	public String toString()
	{
		return String.format( "%s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n\n" ,
			"Student Object",
			"Name", getFullName(),
			"Address" , getHomeAddress(),
			"Phone #" , getPhoneNumber(),
			"E-mail Address" , getEmailAddress(),
			"Grade Level", studentYear.getGradeLevel() );
	}
}
commented: thanks +1

I need to do this:
In the Hi-Lo game, the player begins with a score of 1000. The player is prompted for the number of points to risk and a second promt asks the player to choose either High or Low (1 or 2). The player's choice of either High or Low is compared to random number between ! and 13, inclusive. If the number is between 1 and 6, it is considered low (1), if the number is between 8 and 13, it is considered high (2), and 7 is neutral and the player loses points. If the player guessed correctly, the points wagered are doubled and added to the total points. A wrong guess, the player loses the wagered points.


This is what I wrote:

import java.util.*;

public class HiLo
{
public static int oneRound (int choice, int wager, int points)
{
int rand;

rand = (int)(Math.random()*13 - 1);

if (choice == 1 && rand <=6)
{
return (points + wager);
}
else if (choice == 1 && rand ==7)
{
return (points - wager);
}
else if (choice == 1 && rand >= 8)
{
return (points - wager);
}
else if (choice == 2 && rand <= 6)
{
return (points - wager);
}
else if (choice == 2 && rand ==7)
{
return (points - wager);
}
else if (choice == 2 && rand >= 8)
{
return (points + wager);
}
}

public static void main(String[] args)
{
int wager;
int points = 1000;
int choice;

Scanner input = new Scanner(System.in);

System.out.println("Enter a 1 for numbers 1-6, or a 2 for numbers 8-13.");
choice = input.nextInt();

System.out.println("you have 1000 points, enter your wager.");
wager = input.nextInt();

do
{
points = oneRound(choice, wager, points);

System.out.println("You have " + points + " points left.");
}
while (wager < points || wager == 0);
}
}

The problem is that I keep getting a missing return statement

Please help
thank you

I need to do this:
<snip>

Please do not hijack other people's threads for unrelated questions. Post this as a new thread of its own.

I finally compiled, thank you very much. One last question, how do I represent it in a contructor?

public class Student extends Person
{
	Year studentYear;
  
	public Student( String name, String address, String phone,
		String email, Year grade )
	{
		super( name, address, phone, email);
		this.studentYear = grade;
	}
	
	public enum Year
 {
 
	FIRST( "Freshmen"),
	SECOND("Sophmore"),
	THIRD("Junior"),
	FOURTH("Senior");


	public final String gradeLevel;
	
	Year( String grade )
	{
		gradeLevel = grade;
	}
	
	public String getGradeLevel()
	{
		return gradeLevel;
	}
	
 }
	
	public String toString()
	{
		return String.format( "%s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n\n" ,
			"Student Object",
			"Name", getFullName(),
			"Address" , getHomeAddress(),
			"Phone #" , getPhoneNumber(),
			"E-mail Address" , getEmailAddress(),
			"Grade Level", studentYear.getGradeLevel() );
	}
}

This is what I compiled and here's my test program.

public class PersonTest
{
	public static void main( String args[] )
	{
		
	
		Person person1 = new Employee("John Smith", "123 Cranberry Lane",
			"555-5555", "JohnSmith@boringname.net", "$56.00 per hour",
			"September 23, 2004");
			
		Person person2 = new Student("John Smith", "123 Cranberry Lane",
			"555-5555", "JohnSmith@boringname.net", Year.FIRST );
		
		Person person3 = new Faculty("John Smith", "123 Cranberry Lane",
			"555-5555", "JohnSmith@boringname.net", "$56.00 per hour",
			"September 23, 2004", "Mondays from 1:00 P.M to 3:30 P.M.",
			"Assistant Professor");
		
		Person person4 = new Staff("John Smith", "123 Cranberry Lane",
			"555-5555", "JohnSmith@boringname.net", "$56.00 per hour",
			"September 23, 2004", "Groundskeeper");
					
		System.out.print( person1.toString() );
		
		System.out.print( person2.toString() );
		
		System.out.print( person3.toString() );
		
		System.out.print( person4.toString() );
	}
}

I did that, it says "cannot find symbol".

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.