Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2009
    Posts
    3
    Rep Power
    0

    Unhappy [SOLVED] Assistence is needed with my code. ty

    Your program should output a title similar to "Welcome to Ken's Grading Program", using your own name of course.
    Your program should prompt the user if they will be entering numbers or letters for grades. See example below.

    If the user enters 'numbers':
    Get input for the grade number in decimal format. i.e. 74.22645 (enter it with 5 decimal places)
    Utilize the Math class and round the number to zero decimal places, then use the int cast method (Page 82) to convert to an integer.(ensure you round it before type casting it)
    Utilize a switch statement to determine the corresponding letter grade. Use the grading criteria from this course for the numbers. (ensure you accept all allowable numbers i.e. 70-79 and all in between)
    Output the corresponding letter grade along with the initial number entered in decimal format utilizing the printf method and format specifiers. Output the number in only 3 decimal places.

    if the user enters 'letters':
    Get input for the grade letter in String format.
    Utilize a switch statement to determine the corresponding output for the letter entered. (ensure you accept both upper and lower case letters.
    Use the grading criteria from this course for the numbers. (you must use charAt( ) so the string will work with your switch)
    Output the corresponding numbers values for the letter entered along with the letter initially entered.

    The code is not allowing my if statement to work, I need it to evaluate the user input and allow it to execute the correct if statement.

    import java.util.Scanner;
    import java.lang.Math;

    public class bm
    {
    /*
    * main
    */

    public static void main(String[] args) throws Exception
    {
    Scanner scanner1,scanner2,scanner3;
    String sGradeType,sGrade="",sUGrade;
    char cGrade;
    double dGrade;
    long drGrade;
    int iGrade=0;
    System.out.println("Type of Entry (Chars(C)/Digits(D)");
    scanner1 = new Scanner(System.in);
    scanner2 = new Scanner(System.in);
    sGradeType = scanner1.next();
    sGradeType = "D";
    if (sGradeType == "D")
    {
    System.out.println("Enter Grade number");
    scanner2 = new Scanner(System.in);
    dGrade = scanner2.nextDouble();
    drGrade = Math.round(dGrade);
    iGrade = (int)dGrade;
    switch (iGrade)
    {
    case 75 :
    sGrade = "A" ;
    break ;
    case 60 :
    sGrade = "B";
    break ;
    case 50 :
    sGrade = "C";
    break ;
    case 40 :
    sGrade = "D";
    break ;
    default :
    System.out.print("illegal Grade !") ;
    }
    System.out.printf("Grade Value, %8.3f. Grade %s", dGrade, sGrade);

    } else if (sGradeType == "C")
    {
    System.out.println("Enter Grade Letter");
    scanner3 = new Scanner(System.in);
    sGrade = scanner3.next();
    sUGrade = sGrade.toUpperCase();
    cGrade = sUGrade.charAt(0);

    switch (cGrade)
    {
    case 'A' :
    iGrade = 75 ;
    break ;
    case 'B' :
    iGrade = 60;
    break ;
    case 'C' :
    iGrade = 50;
    break ;
    case 'D' :
    iGrade = 40;
    break ;
    default :
    System.out.print("illegal Grade !") ;
    }
    System.out.printf("Grade Value, %d, Grade %s", iGrade, sGrade);
    }
    } // end of method main

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    This is a forum. Only thing we can do is helping to solve your problems. If you want to find a person to do your assignments, this is not the correct place. Ask your question more clearly. We can help you. But not in this way, please keep in mind.

  3. #3
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Use equals() to compare strings

    One mistake that you have is with the comparation in the "if" statement:
    Java Code:
    if (sGradeType == "D")
    Do not use "==" to compare strings... you have to use the String equals() method to compare strings:
    Java Code:
    if (sGradeType.equals("D"))
    Here's a link to the String API with all the mehtods:
    String (Java Platform SE 6)

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  4. #4
    Join Date
    Apr 2009
    Posts
    3
    Rep Power
    0

    Default

    Thanks alot CJSLMAN, you helped me out and you didnt have to rewrite my code. Also, many thanks for the link did not even know about that site. your reference helped me out enormously.
    Last edited by JOSCMS_JAVANEWB; 04-18-2009 at 09:06 AM. Reason: noticed link after post.

  5. #5
    Join Date
    Apr 2009
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    This is a forum. Only thing we can do is helping to solve your problems. If you want to find a person to do your assignments, this is not the correct place. Ask your question more clearly. We can help you. But not in this way, please keep in mind.


    Check it out; I did have a problem my code was not working properly. Is it not what the community is here? Issues that we have, and cannot find an answer to. I have searched many post on the forum that people need help with and see very little detail in what they ask. I asked a specific question on my post. And a user validated my thoughts, but since I only have 3 weeks experience I was hoping that someone even a “moderator” would help with a understanding of what java issues i was having . Here is a quote from what you said.
    “If you want to find a person to do your assignments, this is not the correct place.”

    Where does it say do my work on my post? I already did it. Did you even read what I posted? Did I miss spell something on there that was interpreted by you to have someone redo my entire work? And what did you mean by
    “Ask your question more clearly. We can help you. But not in this way, please keep in mind.”
    What is not clear? And in you say “But not in this way” what way are you talking about? Look im sure you get hundreds of post a day and you assume you know exactly what someone wants when they post on here. But please don’t assume you know why I asked the question. That was a homework assignment 1 weeks ago. So I wanted to know what I messed up onfor my own personal knowledge. Here is my post question (which is at the end).
    “The code is not allowing my if statement to work, I need it to evaluate the user input and allow it to execute the correct if statement.”
    Ultimately if what your saying is that I cannot post questions here about simple assignments fine you’re a moderator you make the rules, right? But like I said I searched post on here before I replied to your comment about "me wanting someone else to do my work." And I noticed people asking for help on job related problems, with your logic about someone doing someone else’s homework how is it your giving them help on such a serious scale. It must be because beginners like myself haven’t made it in your eyes. Is that what it is?
    Last edited by JOSCMS_JAVANEWB; 04-18-2009 at 08:56 AM. Reason: typo

  6. #6
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    I think it was probably a simple misunderstanding. We get lots of people who post assignments and say "do this, urgent". Starting a post with a verbatim homework question sets alarm bells ringing.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by JOSCMS_JAVANEWB View Post
    Here is a quote from what you said.
    “If you want to find a person to do your assignments, this is not the correct place.”

    Where does it say do my work on my post? I already did it. Did you even read what I posted?
    Look at your title of the thread. Once looking at the time, which is everyone is at first, make impressions that you are trying to do your homework from others. You said that it's not, but who knows. Your tittle is not suitable. Must use a simple, descriptive tittle.

    No I didn't read your question. As I said earlier you gave me a totally different thoughts of this.

    From the start try to give a nice impressions to readers of your question. I think you can explain your question in more simply way, just not posting a lengthy explanation and lengthy code segment. On my view, you gave me a bad impression on me and because of that I don't want to read your post and waste my time. Sorry if I say anything misguide you.

Similar Threads

  1. Hi code needed for JCA adaptor
    By lavanya82 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 03-04-2009, 10:34 AM
  2. help needed
    By amarchandar in forum New To Java
    Replies: 3
    Last Post: 02-17-2009, 01:59 PM
  3. Lucene indexing ans searching code needed
    By vgarg80 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 06-07-2008, 11:31 AM
  4. Help needed with java arrays code
    By d24706 in forum New To Java
    Replies: 2
    Last Post: 03-07-2008, 01:11 AM
  5. Replies: 1
    Last Post: 04-26-2007, 03:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •