Results 1 to 7 of 7
  1. #1
    snewman8771 is offline Member
    Join Date
    Feb 2013
    Posts
    1
    Rep Power
    0

    Default Need help with program!!

    Hi I am seth. New to programming. Ok so I am supposed to make a program that will take ONLY 5 grades, compute the final grade
    PERCENTAGE of a student, and return it. However, each individual letter grade will be converted to a
    numerical value. I am using two different classes. If you guys could help me out with where I proceed after this it would be much appreciated. Here is what I have so far.


    The Constructor Class

    public class LabStudent
    {
    private String NameOfStudent;
    private String LetterGrades;

    double avg;
    public LabStudent(String name, String grades)
    {
    NameOfStudent = name;
    LetterGrades = grades;

    }
    public double calculateAverage(String grades)
    {
    double sum=0;

    for(int i = 0; i < grades.length(); i++)
    {
    sum+= letterToPercent(grades.charAt(i));
    //sum = sum + leter
    }

    avg = sum/grades.length();

    return avg;


    // for loop // iterate through the grades string
    // sum += letterToPercent(grades.charAt(i))

    // avg = sum / grades.length();

    }
    public double letterToPercent(char letterGrade)
    {
    if(letterGrade=='A')
    return 100;
    else if(letterGrade=='B')
    {
    return 80;
    }
    else if(letterGrade=='C')
    {
    return 70;
    }
    else if(letterGrade=='D')
    {
    return 65;
    }
    else return 0;
    }
    //public double letterToPercent()
    //{

    //}
    public char PercenttoLetter(double percent)
    {
    if(percent >=90) //&& percent <=100)
    return 'A';
    else if(percent >90 && percent <=80)
    {
    return 'B';
    }
    else if(percent >80 && percent<=70)
    {
    return 'C';
    }
    else if(percent >=70 && percent <= 60)
    {
    return 'D';
    }
    else return 'F';
    }
    public String toString()
    {
    return "Output:" + NameOfStudent + " " + avg;
    }
    }

    The Driver Class
    import java.util.Scanner;

    public class ComputerLab
    {
    public static void main(String [] args)
    {
    enterStudents();
    {
    Scanner scan = new Scanner(System.in);
    System.out.println("enter number of Students");
    LabStudent s = new Student("Robert", "ABCDD");
    LabStudent s1 = new Student("smith" , "ABDFC");
    int N = scan.nextInt();

    //for (int index, index < N, index++)
    for (int i=0; i<N; i++)
    {
    String name = scan.next();
    String grades = scan.next();
    //LabStudent s = new LabStudent();
    System.out.println("check " + name + " " + grades);
    while(isError(grades))
    { name=scan.next();
    grades=scan.next();



    System.out.println("ERROR");
    }
    }
    }


    {
    boolean isError(String grades)

    // System.out.println("Tracer 1 " + grades);
    //System.out.println("Tracer 1 " + grades.length());

    if(grades.length() !=5)
    return true;
    for( int i =0; i < grades.length(); i++)
    {
    if(grades.charAt(i)!='A'
    &&grades.charAt(i)!='A'
    &&grades.charAt(i)!='B'
    &&grades.charAt(i)!='C'&&grades.charAt(i)!='D'
    &&grades.charAt(i)!='F')
    return true;
    }
    return false;

    }
    }



    I dont know where to procede after this. As well as How to make it runnable.
    If yall could help me it would be appreciated. Thanks
    Also the part I put in comments I am not sure if It will run with it.
    Last edited by snewman8771; 02-14-2013 at 03:09 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Need help with program!!

    Please go through the Forum Rules, particularly the third paragraph. Also go through Guide For New Members and BB Code List - Java Programming Forum - Learn Java Programming and edit your post accordingly.

    To change the subject line, click 'Edit Post' and then 'Go Advanced'

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Default Re: Need help with program!!

    Please wrap code tags around your code.
    what is
    enterStudents();
    in your driver class.If it is a method to be called,I do not find it anywhere in your code.
    all the // statements will not be interpreted by the jvm.

  4. #4
    Wizard0860 is offline Member
    Join Date
    Nov 2012
    Posts
    29
    Rep Power
    0

    Default Re: Need help with program!!

    create a joptionpanel. create 5 boxes. parse int/double those to lets say int a,b,c,d,e. get average into int x. if(x==(insert array here, might not work tho not sure, for ex:83-86(in array))) System.out.println("B"). just do that for rest.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Need help with program!!

    Quote Originally Posted by Wizard0860 View Post
    create a joptionpanel.
    A what?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    Wizard0860 is offline Member
    Join Date
    Nov 2012
    Posts
    29
    Rep Power
    0

    Default Re: Need help with program!!


  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: Need help with program!!

    First off, they have a Scanner and seem happy reading from the console.
    Second Java is case sensitive.
    Please do not ask for code as refusal often offends.

Similar Threads

  1. Replies: 4
    Last Post: 11-21-2012, 01:19 PM
  2. Replies: 2
    Last Post: 04-02-2011, 12:57 PM
  3. Replies: 13
    Last Post: 03-22-2011, 06:49 AM
  4. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 06:53 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 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
  •