Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: JAVA HOMEWORK HELP!

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JAVA HOMEWORK HELP!

    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
    Last edited by javafirsttime; November 13th, 2011 at 09:01 PM.


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: JAVA HOMEWORK HELP!

    Can you read the exception? If yes, read it once again and carefully. You will ofcourse find the answer.
    getGPA() is accepting Float, not String.

  3. #3
    Junior Member
    Join Date
    Nov 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JAVA HOMEWORK HELP!

    I'm sorry. I'm really new to java, does this mean i should edit my method getGPA to be String instead of float

    this is what i currently have:

        //
        // Function getGPA
        //
        public static float getGPA(Float prompt) {
     
            float valueFlt;
     
            displayMsg(prompt);
     
            getStr();
     
            return valueFlt;
     
     
        } // end getGPA

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: JAVA HOMEWORK HELP!

    Does that compile ok now?

  5. #5
    Junior Member
    Join Date
    Nov 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JAVA HOMEWORK HELP!

    No, it currently will not compile ok.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: JAVA HOMEWORK HELP!

    Post the full text of the error messages if you need help.

  7. #7
    Member
    Join Date
    Oct 2011
    Posts
    40
    My Mood
    Stressed
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: JAVA HOMEWORK HELP!

    It appears that you attempted to fix your transcriptMsg(GPA) method, but several others have errors also:
    transcriptMsg(GPA);
    required: no arguments
    found: float

    your call to this method is sending in parameter GPA, which you also create in the method. Rethink this as your method isn't set up to accept parameters.



    displayMsg(prompt);
    required: String
    found: Float

    Either convert your values into a string before sending them to the method displayMsg() or change the input to include everything you're sending, or don't give it an input and just use a println with class variables and a statement. One of these is a lot easier than the others.


    error: cannot find symbol
    valueStr = getGPA;
    symbol: variable getGPA

    Are you calling a variable, or a method? What's missing?

Similar Threads

  1. New to Java Need help with Homework
    By cjg2283 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: October 20th, 2011, 09:47 PM
  2. Help On Java Homework (DUE TONIGHT!!!)
    By agmolina90 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 14th, 2011, 08:28 AM
  3. Help With Java Homework: Set Operations
    By kilroyjr in forum Java Theory & Questions
    Replies: 10
    Last Post: April 1st, 2011, 09:41 AM
  4. Help for java homework
    By Dark_Shadow in forum Object Oriented Programming
    Replies: 6
    Last Post: December 7th, 2009, 04:08 AM
  5. MORE java homework help.
    By TommyFiz in forum File I/O & Other I/O Streams
    Replies: 10
    Last Post: October 13th, 2009, 07:15 PM