I was given the assignment:
Lab 02:
Write a program that implements the decision table below using a nested if statement. Insure that the grade point average is within the range 0.0 through 4.0. If it is not just simply reprompt for it without an error message.
The main function loops prompting the user for the student names and their GPA. Create a function named transcriptMsg that is passed one argument which is the GPA. It will return the appropriate message. In this function put the messages into a container. There will be only one return statement from the function transcriptMsg.
The specification of the program is shown below the line.
GPA Transcript Message
0.0 – 0.99 Failed semester – registration suspended.
1.0 – 1.99 On probation for the next semester.
2.0 – 2.99 Average student rating.
3.0 – 3.49 Dean’s list for semester.
3.5 – 4.0 Highest honors for semester.
Here's the code I've written, it has a few errors but I really cant figure them out. A little help would be most appreciated :)
// // This program is my second lab. // // Author: // Date: November 10, 2011 // import java.util.Scanner; public class lab02_DiStephano { // // Function main // public static void main(String[] args) { String firstName; String lastName; boolean forever = true; float GPA; String message; return; displayWelcome(); while (forever) { firstName = getName("Student first name: "); lastName = getName("Student last name: "); GPA = getGPA("GPA: "); message = transcriptMsg(GPA); displayMsg(message + "\n"); } // end while displayMsg("\tStudent first name: " + firstName + "\nStudent last name: " + lastName + "\nGPA: " + transcriptMsg(GPA)); return; } // end main // // Function displayWelcome // public static void displayWelcome() { displayMsg("\nThis program presents a transcript message for individual students.\n" + "After entering the students first and last names enter their GPA.\n\n"); } // end displayWelcome // // Function displayMsg // public static void displayMsg(String message) { System.out.print(message); return; } // end displayMsg // // Function getFlt // public static float getFlt() { float valueFlt; Scanner keyboard; keyboard = new Scanner(System.in); valueFlt = keyboard.nextFloat(); return valueFlt; } // end getFlt // // Function getGPA // public static float getGPA(Float prompt) { float valueFlt; displayMsg(prompt); getFlt(); return valueFlt; } // end getGPA // // Function getName // public static String getName(String prompt) { String valueStr; displayMsg(prompt); getStr(); return valueStr; } // end getName // // Function getStr // public static String getStr() { String valueStr; Scanner keyboard; keyboard = new Scanner(System.in); valueStr = keyboard.next(); return valueStr; } // end getStr // //Function transcriptMsg // public static String transcriptMsg() { float GPA; String valueStr; valueStr = getGPA; do { if ((GPA <= 0) || (GPA > 1)) { displayMsg("\nFailed semester – registration suspended."); } else if ((GPA <= 1) || (GPA > 2)) { displayMsg("\nOn probation for the next semester."); } else if ((GPA <= 2) || (GPA > 3)) { displayMsg("\nAverage student rating."); } else if ((GPA <= 3) || (GPA > 3.5)) { displayMsg("\nDean’s list for semester."); } else if ((GPA <= 3.5) || (GPA >= 4)) { displayMsg("\nHighest honors for semester."); } } while ((GPA <= 0) || (GPA >= 4)); return valueStr; } // end transcriptMsg } // end lab02_DiStephano
Thanks to all in advance for looking this one over, even if you cannot help. :)
here are my errors :
C:\Users\Jerm\Documents\NetBeansProjects\lab02_DiS tephano\src\lab02_distephano\Lab02_DiStephano.java :32: error: method getGPA in class lab02_DiStephano cannot be applied to given types;
GPA = getGPA("GPA: ");
required: Float
found: String
reason: actual argument String cannot be converted to Float by method invocation conversion
C:\Users\Jerm\Documents\NetBeansProjects\lab02_DiS tephano\src\lab02_distephano\Lab02_DiStephano.java :33: error: method transcriptMsg in class lab02_DiStephano cannot be applied to given types;
message = transcriptMsg(GPA);
required: no arguments
found: float
reason: actual and formal argument lists differ in length
C:\Users\Jerm\Documents\NetBeansProjects\lab02_DiS tephano\src\lab02_distephano\Lab02_DiStephano.java :47: error: method transcriptMsg in class lab02_DiStephano cannot be applied to given types;
+ transcriptMsg(GPA));
required: no arguments
found: float
reason: actual and formal argument lists differ in length
C:\Users\Jerm\Documents\NetBeansProjects\lab02_DiS tephano\src\lab02_distephano\Lab02_DiStephano.java :98: error: method displayMsg in class lab02_DiStephano cannot be applied to given types;
displayMsg(prompt);
required: String
found: Float
reason: actual argument Float cannot be converted to String by method invocation conversion
C:\Users\Jerm\Documents\NetBeansProjects\lab02_DiS tephano\src\lab02_distephano\Lab02_DiStephano.java :145: error: cannot find symbol
valueStr = getGPA;
symbol: variable getGPA
location: class lab02_DiStephano