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 4 of 4

Thread: Beginner Objects

  1. #1
    Junior Member
    Join Date
    Oct 2018
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Beginner Objects

    Hey all, I'm in an intro class for Java in University and I'm pretty confused with Objects. Current assignment is to have a program remember, and keep track of students who have gotten As, Bs, Cs, Ds, and Fs.

    So far I have gotten the program to remember grades through if - else if statements. However I now need to have the program provide the percentage of those who have gotten As through Fs.

    Here is what I have for my working page for reference.

    Thanks in advanced.

    *****************************************

    public class GradeDistribution {
    //Instance Variables

    public int As, Bs, Cs, Ds, Fs, getTotal, addGrade, grade;
    public double percentAs, percentBs, percentCs, percentDs, percentFs;

    //Constructor
    public GradeDistribution() {
    As = 0;
    Bs = 0;
    Cs = 0;
    Ds = 0;
    Fs = 0;

    }
    //Getters

    public int getAs() {
    return As;
    }

    public int getBs() {
    return Bs;
    }

    public int getCs() {
    return Cs;
    }

    public int getDs() {
    return Ds;
    }

    public int getFs() {
    return Fs;
    }

    public double percentAs() {
    return percentAs;
    }

    public double percentBs() {
    return percentBs;
    }

    public double percentCs() {
    return percentCs;

    }

    public double percentDs() {
    return percentDs;

    }

    public double percentFs() {
    return percentFs;
    }

    public int getTotal() {
    getTotal = As+Bs+Cs+Ds+Fs;
    return getTotal;
    }

    public void addGrade(int addGrade) {
    if (addGrade >= 80 && addGrade <= 100) {
    As++;
    } else if (addGrade >= 70 && addGrade < 80) {
    Bs++;
    } else if (addGrade >= 60 && addGrade < 70) {
    Cs++;
    } else if (addGrade >= 50 && addGrade < 60) {
    Ds++;
    } else if (addGrade >= 0 && addGrade < 50) {
    Fs++;
    }
    }

    public void reset() {

    }

    //Bar Graph

    public void print() {
    System.out.println("0 10 20 30 40 50 60 70 80"
    + " 90 100");
    System.out.println("|_____|_____|_____|_____|_____ |_____|_____|_____|"
    + "_____|_____|");
    }
    }

  2. #2
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    284
    My Mood
    Cool
    Thanks
    0
    Thanked 38 Times in 36 Posts

    Default Re: Beginner Objects

    The percentage of those that got a particular grade, say B, is the number that got B's divided by the total number of grades. So if 2 got b's and 3 got c's then the percentage of B's would be 2/5 or 40%. So you need to keep a tally of individual grades as well as all grades.

    Regards,
    Jim

  3. #3
    Junior Member
    Join Date
    Oct 2018
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Beginner Objects

    I ended up doing a bit more research and figured out that methods can work off each other. (Still trying to wrap my head around that)

    Following with this. the next task for me is to have (I'm assuming) a for loop with showing a table with stars on how many scores equal an A, B, C, and so on. Ill send a more clear code sample for that if you don't mind checking it out Jim!

    *************************************************

    System.out.println("0 10 20 30 40 50 60 70 80"
    + " 90 100");
    System.out.println("|_____|_____|_____|_____|_____ |_____|_____|_____|"
    + "_____|_____|");

    That is all I have so far, however with the stars in it should look a little something like this. (This would be the output)
     
    ***************************
     
    0        10      20       30       40      50       60       70       80      90      100
    |_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|
    A******************
    B******
    C******
    D******
    F************************


    --- Update ---

    Unfortunately the forum doesn't like to have excessive spaces. For the sake of it, pretend all the numbers line up nicely with the |'s
    Last edited by Norm; October 29th, 2018 at 08:57 AM. Reason: added code tags to align numbers

  4. #4
    Junior Member
    Join Date
    Oct 2018
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Beginner Objects

    Solved.

Similar Threads

  1. [SOLVED] Beginner: Passing Objects to Methods
    By free_spirit in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 9th, 2018, 02:39 PM
  2. Objects
    By maths94 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: December 10th, 2013, 04:35 PM
  3. [Question] Objects instantiated within objects.
    By Xerosigma in forum Object Oriented Programming
    Replies: 6
    Last Post: April 25th, 2012, 10:53 AM
  4. New to Objects...
    By Java Neil in forum What's Wrong With My Code?
    Replies: 17
    Last Post: March 24th, 2011, 07:00 AM
  5. Objects
    By chronoz13 in forum Java Theory & Questions
    Replies: 5
    Last Post: January 20th, 2010, 12:50 PM

Tags for this Thread