Methods and constants! HELP!!!

I need help with a program, yes its a homework assignment to be honest. Im new to java and from the looks of my source file, im sure you can tell. Please dont be too harsh! :*)

I have to create a method involving this and main cant do a lot of the work.

1. asks the user for their and GPA (validate 0.0 - 4.0). students with at least 2.5 can take the exam if they are below that they should receive an error message.

2. Enter score on the exam (validate 0 and 60). If they score at least 75%, they should see a message that they passed or did not pass

A constant for 60 questions on the exam and the 2.5 minimum gpa to take the exam

This is what i have started with. Can anyone give me some direction?

import javax.swing.JOptionPane;

publicclass TestOut{

publicstaticvoid main(String [] args){

String name;

finaldouble questions = 60;

finaldouble gpa = 0.0;

finaldouble score = 0;

publicstatic String name()

String nameString = JOptionPane.showInputDialog("Enter students name:");

publicstaticdouble gpa (String name)

String gpaString = JOptionPane.showInputDialog(null,"Enter" + name"'s""GPA:","TestDo", JOptionPane.QUESTION_MESSAGE);

gpa = Double.parseDouble(gpaSt

do{

if (gpa > 2.5){

String gpaString = JOptionPane.showInputDialog(null,"Enter" + name"'s""GPA:","TestDo", JOptionPane.QUESTION_MESSAGE);

gpa = Double.parseDouble(gpaString);

}

else{

System.out.println("Your GPA does not qualify you to sit for this exam, Please register for IT 103");

}while (gpa ! > 4.0);

publicstatic String score()

String scoreString = JOptionPane.showInputDialog("Enter your score on the test:");

do{

if (score > 0.75){

String scoreString = JOptionPane.showInputDialog(null,"You passed the IT 103 Testout! You will see the credits on your transcript within 4 weeks.");

double scoredouble = Double.parseDouble(scoreString);}

else{

System.out.println("You did not pass the exam. You will need to take IT 103");

}while (score != 0);

}

}

[3896 byte] By [kumiko2ua] at [2007-11-26 20:00:24]
# 1

For starters it look as if you're trying to define methods within a method. Methods need to be defined within a class.

Also, use brackets { }

when you start methods.

Remove your methods from your main method and repost. Include any error messages.

Djaunla at 2007-7-9 22:57:53 > top of Java-index,Java Essentials,New To Java...
# 2
Where are you stuck? What should "we" be looking for?
abillconsla at 2007-7-9 22:57:53 > top of Java-index,Java Essentials,New To Java...
# 3

should i be using a do while loop with if else statements to get the correct gpa for the user and the exam score?

Also how do i incorporate the 60 questions constant into the program especially when the user enter there test scores.

import javax.swing.JOptionPane;

public class TestOut{

public static void main(String [] args) {

public static void String name(){

String nameString = JOptionPane.showInputDialog("Enter students name:");

}

public static double gpa (String name){

String gpaString = JOptionPane.showInputDialog(null,"Enter" + name "'s" "GPA:", "TestDo", JOptionPane.QUESTION_MESSAGE);

gpa = Double.parseDouble(gpaSt

do {

if (gpa > 2.5){

String gpaString = JOptionPane.showInputDialog(null,"Enter" + name "'s" "GPA:", "TestDo", JOptionPane.QUESTION_MESSAGE);

gpa = Double.parseDouble(gpaString);

}

else{

System.out.println("Your GPA does not qualify you to sit for this exam, Please register for IT 103");

} while (gpa ! > 4.0);

}

public static String score(){

String scoreString = JOptionPane.showInputDialog("Enter your score on the test:");

do {

if (score > 0.75){

String scoreString = JOptionPane.showInputDialog(null,"You passed the IT 103 Testout! You will see the credits on your transcript within 4 weeks.");

double scoredouble = Double.parseDouble(scoreString);}

else{

System.out.println("You did not pass the exam. You will need to take IT 103");

} while (score != 0);

}

}

}

kumiko2ua at 2007-7-9 22:57:53 > top of Java-index,Java Essentials,New To Java...
# 4

> should i be using a do while loop with if else

> statements to get the correct gpa for the user and

> the exam score?

You should be removing your method declarations such as:

public static void String name(){

from your main method. Place those in the CLASS, not in a METHOD. This is basic OOP. You can define methods on a class, as a class is an object. You cannot define methods on a method.

Place the methods that are currently in your main method in your class, repost your code, and post any error messages you get when you try to compile.

Message was edited by:

Djaunl

Djaunla at 2007-7-9 22:57:53 > top of Java-index,Java Essentials,New To Java...
# 5

Put the member variables outside of any method like this. That way, their scope is the class, not any method.

public class TestOut{

String name;

final double questions = 60;

final double gpa = 0.0;

final double score = 0;

public static void main(String [] args) {

==================

You can't declare methods inside another method, so take your methods out of main().

public static void main(String [] args) {

} // end main()

public static void String name(){

String nameString = JOptionPane.showInputDialog("Enter students name:");

} // end name()

=====================

You'll want to create a TestOut object inside your main method and work with that.

public static void main(String [] args) {

TestOut testout = new TestOut();

} // end main()

=====================

Your methods have to return something if they are declared with a return type other than void:

public static double gpa (String name){

has to have a

return <some double here>;

somewhere in the method.

hunter9000a at 2007-7-9 22:57:53 > top of Java-index,Java Essentials,New To Java...
# 6

ok this is what i got so far but its still not compiling

import javax.swing.JOptionPane;

public class TestOut{

public static void main(String [] args) {

String StudentName;

double gpa;

double score;

do{

StudentName = name();

gpa = StudentGpa();

score = MinScore();

} while (name != 2);

private static String name(){

String EnterName;

EnterName = JOptionPane.showInputDialog(null,"Enter students name:");

return EnterName;

}

private static double StudentGpa (String EnterName){

final double MinGpa = 2.5;

double EnterGpa;

do {

if (EnterGpa >= MinGpa)

EnterGpa = Double.parseDouble(JOptionPane.showInputDialog(null,"Enter" + StudentName + "'s GPA:"));

else{

JOptionPane.showInputDialog(null,"Your GPA does not qualify you to sit for this exam, Please register for IT 103");

} while (EnterGpa < 1 || EnterGpa < MinGpa);

return EnterGpa;

}

private static double MinScore (int num){

final double Questions = 60;

final double StudentScore = 0.75;

double FinalScore;

if (FinalScore >= Student Score)

FinalScore = num * Questions /100;

FinalScore = Double.parseDouble(JOptionPane.showMessageDialog(null,"You passed the IT 103 Testout! You will see the credits on your transcript within 4 weeks."));

else

JOptionPane.showMessageDialog(null, "You did not pass the exam. You will need to take IT 103");

return FinalScore;

}

}

kumiko2ua at 2007-7-9 22:57:53 > top of Java-index,Java Essentials,New To Java...