Results 1 to 7 of 7
  1. #1
    Wasp is offline Member
    Join Date
    Nov 2016
    Posts
    32
    Rep Power
    0

    Default Enum Method Whats Wrong

    I am writng entry Matematik or Fizik like my enum parameter but not joining my enim foreach if loop. Whats wrong this equals method?

    Java Code:
    package users;
    
    import java.util.ArrayList;
    import java.util.Scanner;
    
    public class Driver {
    
    	public static void main(String[] args) {
    		Scanner sInt = new Scanner(System.in);
    		Scanner sString = new Scanner(System.in);
    		Scanner sArrayList = new Scanner(System.in);
    		Teacher teacher = new Teacher();
    		
    		
    		System.out.println("Sistem Id :");
    		teacher.setSystemId(sInt.nextInt());
    		System.out.println("TC :");
    		teacher.setTcNo(sInt.nextInt());
    		System.out.println("İsim :");
    		teacher.setFirstName(sString.nextLine());
    		System.out.println("Soyisim :");
    		teacher.setLastName(sString.nextLine());
    		System.out.println("Sifre :");
    		teacher.setPassword(sString.nextLine());
    		System.out.println("Lütfen Uzman Olduğunuz Ders Sayısını Giriniz :");
    		int numberExpertise = sInt.nextInt();
    		String [] entryExpertise = new String[numberExpertise];
    		for (int i = 1; i<=numberExpertise; i++) {
    			System.out.println("Uzmanlık " + i + " ");
    			String entry = sArrayList.nextLine();
    			if(LessonList.checkEnum(entry.trim())){
    				teacher.setExpertise(LessonList.valueOf(entry));
    			}
    			else i--;
    			
    		}
    		
    		
    	}
    }
    Java Code:
    package users;
    
    public enum LessonList {
    
    	Matematik, Fizik, Kimya, Biyoloji, Geometri, Türkçe, Tarih, Coğrafya;
    	
    	static boolean checkEnum(String lesson){
    		
    		boolean found = false;
    		for (LessonList lessonList: LessonList.values()) {
    			if (lesson.equals(lessonList)){
    				found = true;
    				System.out.print(lessonList);
    				
    			}
    			else System.out.println("ife girmedi");
    		}
    		return found;
    	}
    	
    	
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Enum Method Whats Wrong

    The code does not compile because of missing class.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Wasp is offline Member
    Join Date
    Nov 2016
    Posts
    32
    Rep Power
    0

    Default Re: Enum Method Whats Wrong

    There is missing Class

    Java Code:
    package users;
    
    public abstract class User {
    	
    	private int systemId;
    	private int tcNo;
    	private String firstName;
    	private String lastName;
    	private String password;
    	
    	public User() {
    		super();
    	}
    
    	public User(int systemId, int tcNo, String firstName, String lastName, String password) {
    		super();
    		this.systemId = systemId;
    		this.tcNo = tcNo;
    		this.firstName = firstName;
    		this.lastName = lastName;
    		this.password = password;
    	}
    	
    	public int getSystemId() {
    		return systemId;
    	}
    	public void setSystemId(int systemId) {
    		this.systemId = systemId;
    	}
    	public int getTcNo() {
    		return tcNo;
    	}
    	public void setTcNo(int tcNo) {
    		this.tcNo = tcNo;
    	}
    	public String getFirstName() {
    		return firstName;
    	}
    	public void setFirstName(String firstName) {
    		this.firstName = firstName;
    	}
    	public String getLastName() {
    		return lastName;
    	}
    	public void setLastName(String lastName) {
    		this.lastName = lastName;
    	}
    	public String getPassword() {
    		return password;
    	}
    	public void setPassword(String password) {
    		this.password = password;
    	}
    	
    	
    	@Override
    	public int hashCode() {
    		final int prime = 31;
    		int result = 1;
    		result = prime * result + ((firstName == null) ? 0 : firstName.hashCode());
    		result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());
    		result = prime * result + ((password == null) ? 0 : password.hashCode());
    		result = prime * result + systemId;
    		result = prime * result + tcNo;
    		return result;
    	}
    	@Override
    	public boolean equals(Object obj) {
    		if (this == obj)
    			return true;
    		if (obj == null)
    			return false;
    		if (getClass() != obj.getClass())
    			return false;
    		User other = (User) obj;
    		if (firstName == null) {
    			if (other.firstName != null)
    				return false;
    		} else if (!firstName.equals(other.firstName))
    			return false;
    		if (lastName == null) {
    			if (other.lastName != null)
    				return false;
    		} else if (!lastName.equals(other.lastName))
    			return false;
    		if (password == null) {
    			if (other.password != null)
    				return false;
    		} else if (!password.equals(other.password))
    			return false;
    		if (systemId != other.systemId)
    			return false;
    		if (tcNo != other.tcNo)
    			return false;
    		return true;
    	}
    	@Override
    	public String toString() {
    		return "User [systemId=" + systemId + ", tcNo=" + tcNo + ", firstName=" + firstName + ", lastName=" + lastName
    				+ ", password=" + password + "]";
    	}
    	
    	
    
    }

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Enum Method Whats Wrong

    What data types are being compared on line 11? How does the String class's equals() method select the parts of an object to compare against?
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Wasp is offline Member
    Join Date
    Nov 2016
    Posts
    32
    Rep Power
    0

    Default Re: Enum Method Whats Wrong

    Java Code:
    package users;
    
    import java.util.ArrayList;
    
    public class Teacher extends User {
    
    	private ArrayList<LessonList> expertise;
    
    
    	public Teacher() {
    		super();
    	}
    
    	public Teacher(int systemId, int tcNo, String firstName, String lastName, String password,
    			ArrayList<LessonList> expertise) {
    		super(systemId, tcNo, firstName, lastName, password);
    	}
    
    	public ArrayList<LessonList> getExpertise() {
    		return expertise;
    	}
    
    	public void setExpertise(LessonList expertise) {
    		this.expertise.add(expertise);
    		
    	}
    
    }

  6. #6
    Wasp is offline Member
    Join Date
    Nov 2016
    Posts
    32
    Rep Power
    0

    Default Re: Enum Method Whats Wrong

    Quote Originally Posted by Norm View Post
    What data types are being compared on line 11? How does the String class's equals() method select the parts of an object to compare against?
    How can i compare enum and string?

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Enum Method Whats Wrong

    Look at the doc for enum to see what methods return a String.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. whats wrong with my GUI?
    By EscSequenceAlpha in forum New To Java
    Replies: 12
    Last Post: 05-31-2012, 08:20 PM
  2. I cant do this.Whats wrong?
    By gaston7eze in forum Java 2D
    Replies: 5
    Last Post: 05-30-2012, 12:34 AM
  3. Whats wrong with this tiny method?
    By N00Bie in forum New To Java
    Replies: 6
    Last Post: 02-17-2011, 09:08 PM
  4. whats wrong
    By atenv in forum New To Java
    Replies: 6
    Last Post: 06-15-2010, 01:55 PM
  5. whats is wrong with this app??
    By mrajan in forum New To Java
    Replies: 4
    Last Post: 06-09-2010, 10:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •