How do I solve this Java Program?
-
What is an Array and how does it work? An Array Program with a Client? Arrays with this Program? How do you do arrays in this Java Program? Write a class encapsulating the concept of converting integer grades to letter grades (A , B, C, D, or F), assuming grades are composed of a list of integers between 0 and 100. Write the following methods: • A constructor with just one parameter, the number of student; all grades can be randomly generated. • Accessor, mutator, toString(), and equals() methods. • A methods returning an array of chars corresponding to the integer grades (90 or above should be converted to A, 80 or above to B, 70 or above to C, 60 or above to D, and 59 or less to F). • A method returning the number of A’s. • A method returning an array of ints counting how many A’s, B’s, C’s, D’s, and F’s were received. Write a client class to test all the methods in your class. I am using Java Unlimited 3
-
Answer:
I won't provide exact answers, but the following should help you get started. For the class to handle converting number grades to letters, create your class with a method like: public static String getLetterGrade(final double grade) { // Initialize the letter grade to a value (let's default to a failing grade): String result = "F"; // then use conditional if/else statements to change the grade when appropriate: if (grade >= 90) { result = "A"; } else (if grade >= 80) { .. .. .. } return result; } For the constructor, this is just like the default constructor but with a parameter. You'll create like: public Foo(final int studentsToCreate) { // then include your logic to generate student data // Note: I'd recommend creating a "helper" method to generate a // single random student, then loop to call that method based // on the studentsToCreate variable using a "for" loop. } // Here is a helper method signature: private double generateGrade() { // Look up random number generation. If you want to create "double" // type values, create random grades from 0 - 1000 and divide // by 10. Ex. random is 897 and would become 89.7 as a double. } For the toString and equals methods, this is just overriding the ones inherited from the Object class. You can find samples of doing so online. For the method to get the number number of any letter grade, use a method like: public int getA() { // Then loop through the grade array. You could use your method to see what the letter // grade is and if the result equals "A" (remember String.equals("A") not String == "A"). } Ideally you'd use a more generic method like: public int getLetterGrade(final String grade) { // where "grade" is one of letter grades. } For your array, if you write the getLetterGrade(final String grade) method, you'll practically have all the logic for that method available to you. Just write as: public int[] getGradeArray() { // Position in array // A - 0 // B - 1 // C - 2 // D - 3 // F - 4 int[] gradeArray = new int[5]; // Then call per grade letter the getLetterGrade(...) method to populate your array. }
KnightHu... at Yahoo! Answers Visit the source
Other answers
To store related data, we use arrays. An array is collection of similar elements. String is collection of characters. Integer array is a collection of integers. You please do show your efforts towards academic assignments and then come to us for help
James Bond
Related Q & A:
- How can I design a workout program for myself?Best solution by Yahoo! Answers
- How do I solve the problem of downloading word document attached to my email?Best solution by support.google.com
- How do I solve a DNS error?Best solution by Yahoo! Answers
- How do I solve the coin problem?Best solution by Quora
- How can I find an exchange program?Best solution by exchanges.state.gov
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.