Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

If statements && mod not working as expected

$
0
0
For some reason the overiding qualifiedforscholarship method is always returning true for grad and law students.
Mark Adams and Joan Short should be returning false

Name: Fred Blunt SSN: 111-11-1111 GPA: 2.75 Qualified For Scholarship: false
Name: Jean Green SSN: 222-22-2222 GPA: 3.5 Qualified For Scholarship: true
Name: Joan Short SSN: 333-33-3333 GPA: 4.0 Qualified For Scholarship: true
Name: Jack Jones SSN: 444-44-4444 GPA: 3.6 Qualified For Scholarship: true
Name: Mark Adams SSN: 555-55-5555 GPA: 3.5 Qualified For Scholarship: true LSAT: 145
Name: Anne Sachs SSN: 666-66-6666 GPA: 3.25 Qualified For Scholarship: true LSAT: 150


public class GradStudent extends Student {

	public GradStudent(String N, String S, int C, int Q) {
		super(N, S, C, Q);
	}

	public boolean qualifiedForScholarshipLawStudent() 
	{
		double gpa = getGPA();
		if(gpa < 3.5 || creditHours < 30)
			return false;
		return true;
	}
	


}


public class LawStudent extends Student {
	
	int LSAT;
	public LawStudent(String N, String S, int C, int Q, int L) {
		super(N, S, C, Q);
		LSAT = L;
	}
	public boolean qualifiedForScholarshipLawStudent() 
	{
		double gpa = getGPA();
		if(gpa >= 3.25 && LSAT >= 150 )
			return true;
		return false;
	}
	public  String toString() {
		return super.toString() + " LSAT: " + LSAT;
	}
}



public class TestStudents {

	
	public static void main(String[] args) {
		Student[] students = new Student[6];
		
		
		for(int y=0; y< students.length; y++)
			{
				students[y] = new Student();
			}
		
		
		students[0] = new Student("Fred Blunt", "111-11-1111", 40, 110);
		students[1] = new Student("Jean Green", "222-22-2222", 80, 280);
		students[2] = new GradStudent("Joan Short", "333-33-3333",15, 60);
		students[3] = new GradStudent("Jack Jones", "444-44-4444", 30 , 108);
		students[4] = new LawStudent("Mark Adams", "555-55-5555", 20, 70 ,145 );
		students[5] = new LawStudent("Anne Sachs", "666-66-6666",20 ,65, 150 );
		
		for(int x=0; x < students.length; x++)
		{
				System.out.println(students[x]);
		}
	
	}
}


public class Student {
	
		String name;
		String ssn;
		int creditHours;
		int qualityHours;
		
		public Student(String N, String S, int C, int Q)
		{
			creditHours = C;
			name = N;
			ssn = S;
			qualityHours = Q;
		}
		
		public Student()
		{
			
		}
		public int getHoursAttempted()
		{
			return creditHours;
		}
		
		public double getGPA()
		{
			double gpa = (double) qualityHours/creditHours;
			if(gpa == 0)
				return 0.0;
			return gpa;
		}
		public boolean qualifiedForScholarship()
		{
			double gpa = getGPA(); 
			if(gpa < 3.0)
				return false;
			return true;
		}
		
		public  String toString() {
			double gpa = getGPA();
			boolean x = qualifiedForScholarship();
			return( "Name: " + name + " SSN: " + ssn + " GPA: " + gpa + " Qualified For Scholarship: " + x );
		}
		
	}

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>