5 Replies - 1264 Views - Last Post: 29 January 2011 - 11:30 AM Rate Topic: -----

#1 dirtyrice1977  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 23-January 11

scanner objects and methods

Posted 29 January 2011 - 12:46 AM

I'm trying to figure out a way for one method to be recognized by another. I would like the first applicant method to recognize the satscore and actscore. if i enter a 1 i want to be able to execute the satScore portion and so on.
A hint or resource is all i'm looking for.

import java.util.*;
public class Admit {
public static void main(String [] args)
{
	Scanner console = new Scanner(System.in);
	introduction();
	int applicant1 = firstApplicant (console);
	int applicant2 = secondApplicant(console);
	double scoreOne = satScore(console);
	double scoreTwo = actScore(console);
	scoreComparison (scoreOne, scoreTwo);
}
public static void introduction()
{
	System.out.println("This program compares two applicants to");
	System.out.println("determine which one seems like the stronger");
	System.out.println("applicant.  For each candidate I will need");
	System.out.println("either SAT or ACT scores plus a weighted GPA.");
	System.out.println();
}
public static int firstApplicant (Scanner console) 
{
	System.out.println("Information for the first applicant:");
	System.out.print("do you have 1) SAT sores or 2) ACT scores? ");
	int testType = console.nextInt();
	return testType;
}
public static int secondApplicant (Scanner console)
{
	System.out.println("Information for the second applicant:");
	System.out.print("do you have 1) SAT sores or 2) ACT scores? ");
	int testType = console.nextInt();
	return testType;
}
public static double satScore (Scanner console)
{
	
	
	System.out.print("SAT math? ");
	double math = console.nextDouble();
	System.out.print("SAT verbal? ");
	double verbal = console.nextDouble();
	System.out.print("actual GPA? ");
	double gpa = console.nextDouble();
	System.out.print("max GPA? ");
	double maxGPA = console.nextDouble();
	double score = (2 * verbal + math) / 24;
	double gpaScore = (gpa/maxGPA) * 100;
	double totalScore = score + gpaScore;
	return totalScore;
	
}
public static double actScore(Scanner console)
{
	System.out.print("ACT English? ");
	int english = console.nextInt();
	System.out.print("ACT math? ");
	int math = console.nextInt();
	System.out.print("ACT reading? ");
	int reading = console.nextInt();
	System.out.print("ACT science? ");
	int science = console.nextInt();
	System.out.print("actual GPA? ");
	double gpa = console.nextDouble();
	System.out.print("max GPA? ");
	double maxGPA = console.nextDouble();
	double score2 = (2 * reading + english + math + science) / 1.8;
	double gpaScore2 = (gpa/maxGPA) * 100;
	double totalScore2 = gpaScore2 + score2;
	return totalScore2;
}
public static void scoreComparison(double scoreOne, double scoreTwo)
{
	System.out.println("First applicant overall score = " + scoreOne);
	System.out.println("Second applicant overall score = " + scoreTwo);
	if (scoreOne > scoreTwo)
	{
		System.out.println("The first applicant seems to be better.");
	}
	else if (scoreOne == scoreTwo)
	{
		System.out.println("The tow applicants seem equal.");
	}
		else 
		{
			System.out.println("The second applicant seems to be better.");
		}
	}

 
}



Is This A Good Question/Topic? 0
  • +

Replies To: scanner objects and methods

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: scanner objects and methods

Posted 29 January 2011 - 05:14 AM

What do you mean, "one method to be recognized by another?" That methods "see" each other and can be used by one another (within the limits of scope and visibility) is a basic feature of the language, most languages for that matter.

If you're getting errors or your program isn't working as you'd like it to, explain what's not working, and perhaps we can help.
Was This Post Helpful? 0
  • +
  • -

#3 dirtyrice1977  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 23-January 11

Re: scanner objects and methods

Posted 29 January 2011 - 10:13 AM

View PostGregBrannon, on 29 January 2011 - 05:14 AM, said:

What do you mean, "one method to be recognized by another?" That methods "see" each other and can be used by one another (within the limits of scope and visibility) is a basic feature of the language, most languages for that matter.

If you're getting errors or your program isn't working as you'd like it to, explain what's not working, and perhaps we can help.


I'm not getting any errors. All the pieces seem to be working. I just don't know how to get the program to prompt the SAT questions when a number 1 is entered and ACT questions when a number 2 is entered. Do I have to create a new method to get these two methods to work together?
Was This Post Helpful? 0
  • +
  • -

#4 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: scanner objects and methods

Posted 29 January 2011 - 10:59 AM

Your program determines the test type, SAT or ACT and assigns it to integers applicant1 and applicant2, but then doesn't do anything with the information. Without spending too much time analyzing your program, I'm thinking you would call satScore() or actScore() depending on the value of applicant1 and applicant2, possibly using an if statement.
Was This Post Helpful? 1
  • +
  • -

#5 dirtyrice1977  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 23-January 11

Re: scanner objects and methods

Posted 29 January 2011 - 11:11 AM

View PostGregBrannon, on 29 January 2011 - 10:59 AM, said:

Your program determines the test type, SAT or ACT and assigns it to integers applicant1 and applicant2, but then doesn't do anything with the information. Without spending too much time analyzing your program, I'm thinking you would call satScore() or actScore() depending on the value of applicant1 and applicant2, possibly using an if statement.



This is what I've been trying to do. The scanner console is a new concept and we haven't gone over if statements yet. I'm trying to work ahead a little. It seems i'm on the right track with the logic. I'll try again. Thank you for the response.
Was This Post Helpful? 0
  • +
  • -

#6 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: scanner objects and methods

Posted 29 January 2011 - 11:30 AM

Yes, do look up if statements, but you'll find the logic will be something like:

if ( applicant1 == 1 )
{
   satScore();
}
else
{
   actScore();
}



and the same for applicant2. Note the "==" rather than "=" in the if statement. The double equals is used for comparison while the single equals is used for assignment. And I simplified the method calls, but I think the logic example answers your original question.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1