473,799 Members | 2,885 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

User storing scores of 10 students in an array

3 New Member
Hello,

I hope someone can help me. I had to do the following assignment( i have most of it done just cant finish it off, question and source code below).

Question?
Write a Java program that asks the user to input the scores, as a percentage( e.g 87.4), of 10 students. The scores entered must be stored ina n array.

The programme must determine:

The lowest score and its equivalent grade (ie A,B,etc)
The highest " " " " "
The average score and its "

The bit i cant do is tie in the equivalent grade with the lowest highest and average score.

Code:
Expand|Select|Wrap|Line Numbers
  1. //Arrayofscores.java
  2. //This programme asks the user to enter 5 exam scores and store them in an array
  3. import java.text.*;
  4.  
  5. public class Arrayofscores
  6. {
  7.     public static void main(String args[])
  8.     {
  9.         int [] scores = new int[10];
  10.         int smallest, highest,temp,total=0;
  11.         double average =0.0;
  12.  
  13.         //ask the user to enter 10 scores
  14.         for (int i = 0;i<= scores.length-1;i++)
  15.         {
  16.         System.out.print("\n\nEnter Score " + (i+1) + ": ");
  17.             scores[i] = UserInput.getInt();
  18.         }
  19.  
  20.             //find the lowest score
  21.             smallest = scores[0];
  22.  
  23.             for (int i = 1; i <= scores.length-1;i++)
  24.             if (scores[i] < smallest)
  25.                 smallest = scores[i];
  26.  
  27.     System.out.println("\nThe lowest score is : " + smallest);
  28.  
  29.             //find the highest score
  30.             highest = scores[0];
  31.  
  32.             for (int i = 1; i <= scores.length-1;i++)
  33.             if (scores[i] > highest)
  34.                 highest = scores[i];
  35.  
  36.         System.out.println("\nThe highest score is : " + highest);
  37.  
  38.                 //find the average score
  39.             for (int i = 0; i<=scores.length-1;i++)
  40.             total = total + scores[i];
  41.  
  42.             average = total/10.0;
  43.         System.out.println("\nThe average score is : " + average);    
  44.  
  45.             }    
}


Any suggestions would be greatly appreciated!!
Mar 5 '08 #1
8 15319
BigDaddyLH
1,216 Recognized Expert Top Contributor
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Mar 5 '08 #2
RedSon
5,000 Recognized Expert Expert
First I suggest you sort your array after your user enters the 10 elements. Then element [0] is your smallest and element [9] is your largest, then to find the average you add up each element 0 through 9 and divide by the number of elements 10. After that when you output all you need to do is determine which letter grade corresponds to what value.

This should be fairly easy to work out, no?
Mar 5 '08 #3
d24706
3 New Member
Im still struggling to figure out the last piece, what i have come up with since and i think im getting on the right track is;



Expand|Select|Wrap|Line Numbers
  1. public static float getGrade()
  2.  
  3.             {
  4.             float grade;
  5.  
  6.             if (score > 90) 
  7.             grade = "A"; 
  8.             else if (score > 75) 
  9.             grade = "B";
  10.  
  11.             System.out.println("\nThis is a " + getGrade(highest) + " grade.");
  12.  
  13.             return grade;
  14.  
Mar 5 '08 #4
RedSon
5,000 Recognized Expert Expert
Im still struggling to figure out the last piece, what i have come up with since and i think im getting on the right track is;



Expand|Select|Wrap|Line Numbers
  1. public static float getGrade()
  2.  
  3.             {
  4.             float grade;
  5.  
  6.             if (score > 90) 
  7.             grade = "A"; 
  8.             else if (score > 75) 
  9.             grade = "B";
  10.  
  11.             System.out.println("\nThis is a " + getGrade(highest) + " grade.");
  12.  
  13.             return grade;
  14.  
why are you making a recursive call? And why do you think getGrade(highes t) will work? Have you defined a getGrade method that takes an argument?
Mar 5 '08 #5
d24706
3 New Member
sorry,im lost,looked over my notes and i just cant figure out methods,can someone tell me what the code should look like to get this to work.
Mar 5 '08 #6
RedSon
5,000 Recognized Expert Expert
sorry,im lost,looked over my notes and i just cant figure out methods,can someone tell me what the code should look like to get this to work.
If you have:
Expand|Select|Wrap|Line Numbers
  1. public static void main(String[] args)
  2. {
  3.    int a;
  4.    int b;
  5.  
  6.    int c = addTogether(a, b);
  7. }
What would the method signature be for addTogether?
Mar 6 '08 #7
nomad
664 Recognized Expert Contributor
Im still struggling to figure out the last piece, what i have come up with since and i think im getting on the right track is;



Expand|Select|Wrap|Line Numbers
  1. public static float getGrade()
  2.  
  3.             {
  4.             float grade;
  5.  
  6.             if (score > 90) 
  7.             grade = "A"; 
  8.             else if (score > 75) 
  9.             grade = "B";
  10.  
  11.             System.out.println("\nThis is a " + getGrade(highest) + " grade.");
  12.  
  13.             return grade;
  14.  


One could use two arrays which must be of the same length do get a letter grade. So if someone enter 90 the result would be an A.
Think about it.

nomad
Mar 6 '08 #8
BigDaddyLH
1,216 Recognized Expert Top Contributor
Im still struggling to figure out the last piece, what i have come up with since and i think im getting on the right track is;



Expand|Select|Wrap|Line Numbers
  1. public static float getGrade()
  2.  
  3.             {
  4.             float grade;
  5.  
  6.             if (score > 90) 
  7.             grade = "A"; 
  8.             else if (score > 75) 
  9.             grade = "B";
  10.  
  11.             System.out.println("\nThis is a " + getGrade(highest) + " grade.");
  12.  
  13.             return grade;
  14.  
Another thing (another!) wrong with this code is the type. What is the type for a grade? A float? Then why are you trying to return strings like "A" or "B? Sit down away from the keyboard and decide what the type for a grade should be.
Mar 6 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

9
2663
by: sb | last post by:
If there is at least one user-defined constructor, no constructors are implicitly declared. struct my_vec : public vector<int> { double foo; my_vec(size_t n) : vector<int>(2*n) {} // oops, no default ctor any more // have to do a lot of stupid typing now , like: my_vec() : vector<int>() {} // etc.
22
2560
by: guitarromantic | last post by:
Hey everyone, I run a site with staff-submitted reviews, and most of them are written by one author. However, we also do "multiple" reviews. Up until now I just had a userid for a 'Multiple' account and submitted them under that, but this makes it harder to print lists of all the reviews by one person, so ideally I wanna make a multiple select form so we can just select all the contributors and have the values saved in the database - in...
3
4762
by: Akinyemi | last post by:
I am writing a Visual Basic program for calculating students scores, and also grading the highest 3 scores as "First" , "Second" and "Third" respectively. I have been able to get the program to compute the score of each student. I have not been able to grade the highest three scores into First, second and third. Kindly assist me, please.
22
2744
by: Sandman | last post by:
So, I have this content management system I've developed myself. The system has a solid community part where members can register and then participate in forums, write weblogs and a ton of other things. So, in instances where I list, for example, the latest weblogs. I list the headline of the weblog, the date and the name of the member who wrote it. Now, the name isn't just "Smith", but rather Smith's online status, his nick and his...
3
1283
namcintosh
by: namcintosh | last post by:
I am writing the following program that calculates the average of a group of test scores where the lowest score in the group is dropped. It has the following functions: void getScore-should ask the user for a test score, store it in a reference parameter variable, and validate it. This function should be called by main once for each of the five scores to be entered. void calcAverage()-should calculate and display the average of the four...
5
4951
by: joestevens232 | last post by:
Ok Im trying to use a struct to take in input from a file "grades.txt" which looks like: Smith 9 9.33 8 10 5.5 8 10 20 47.5 47 45 47.5 48 83 87 100 98 96 100 98 92 88 96 92 86 92 94 100 96 Jones 9 8 6 6 8 7.5 8 20 35 40 42.5 40 44 62 72 100 88 86 90 92 92 88 86 88 86 94 88 86 90....etc i don't know how many students their will be. And I need to store them in a structre like how I have in my code...Im unsure how to get...
0
2082
by: Racqetsports | last post by:
Hi there, In a gradebook database, student grades must be computed from 2 scores: a Daily grade, and then scores from Assignments. Knowing about nested forms, I am requesting direction on how to set up this particular case of form and subforms. Currently, there are 5 tables: STUDENTS StudentID StudentLName
13
3792
by: Eric IsWhoIAm | last post by:
I have four tables created so far: Courses, Instructors, Courses and Instructors (which shows the Course and Instructor Name fields, but holds their IDs since those are the keys), and Students. Now, I wish to create a Classrooms (or something similar) table which will allow me to pick the Course from Courses and Instructors, and hold multiple Students for each Course. I am unsure how to do this in Access. Each student can have multiple...
4
3144
by: chromis | last post by:
Hi, I know this question has been asked before, but I seem to be getting different results from everyone else. I want to return times from my db table in this format: hh:mm:ss.mmm using mssql. I'm using a datetime column to store the information and I am entering the data in this manner: yyyy-mm-dd hh:mm:ss.mmm which is I think the way that mssql stores datetime's in the database. The trouble is when I go to retrieve this data it...
0
9538
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10249
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9068
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7563
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6804
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5584
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4138
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.