473,770 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Arrays problem???

5 New Member
This program is to grade exams, now i need to add the correct answers and them loop back to grade another exam. Need help I;n stuck.

Expand|Select|Wrap|Line Numbers
  1.  import java.util.*; 
  2.  
  3. public class Grades
  4. {
  5. public static void main(String[] args)
  6. {
  7.  
  8. Scanner keyboard = new Scanner(System.in);
  9.  
  10. System.out.println("How many question are in the quiz?");
  11. int num = keyboard.nextInt(); 
  12. keyboard.nextLine();
  13.  
  14. String[] Grades = new String [num];
  15. String[] Student = new String [num];
  16.  
  17. for (int count = 0; count < Grades.length; count++)
  18. {
  19. System.out.println("Please enter key of the quiz(please upper case) " + count );
  20. Grades[count] = keyboard.nextLine(); 
  21. }
  22.  
  23. System.out.println(); 
  24. for (int st = 0; st < Student.length; st++)
  25. {
  26. System.out.println("Please enter the student answers " + st );
  27. Student[st] = keyboard.nextLine(); 
  28. }
  29.  
  30. System.out.println("quiz key\tstudent answer\tpoints.");
  31. for (int a=0; a<Student.length;++a){
  32.  
  33.  
  34. if (Grades[a].equals(Student[a])) {
  35. System.out.print(" " + Grades[a] +"\t\t "+ Student [a]+ "\t\t " + 1 );
  36. System.out.println();
  37.  
  38. }
  39. else { 
  40. System.out.print(" " + Grades[a]+ "\t\t "+ Student [a]+"\t\t" + 0); 
  41. System.out.println();
  42.  
  43. }
  44. }
  45. }
  46.  
Mar 29 '07 #1
4 1303
r035198x
13,262 MVP
This program is to grade exams, now i need to add the correct answers and them loop back to grade another exam. Need help I;n stuck.

Expand|Select|Wrap|Line Numbers
  1.  import java.util.*; 
  2.  
  3. public class Grades
  4. {
  5. public static void main(String[] args)
  6. {
  7.  
  8. Scanner keyboard = new Scanner(System.in);
  9.  
  10. System.out.println("How many question are in the quiz?");
  11. int num = keyboard.nextInt(); 
  12. keyboard.nextLine();
  13.  
  14. String[] Grades = new String [num];
  15. String[] Student = new String [num];
  16.  
  17. for (int count = 0; count < Grades.length; count++)
  18. {
  19. System.out.println("Please enter key of the quiz(please upper case) " + count );
  20. Grades[count] = keyboard.nextLine(); 
  21. }
  22.  
  23. System.out.println(); 
  24. for (int st = 0; st < Student.length; st++)
  25. {
  26. System.out.println("Please enter the student answers " + st );
  27. Student[st] = keyboard.nextLine(); 
  28. }
  29.  
  30. System.out.println("quiz key\tstudent answer\tpoints.");
  31. for (int a=0; a<Student.length;++a){
  32.  
  33.  
  34. if (Grades[a].equals(Student[a])) {
  35. System.out.print(" " + Grades[a] +"\t\t "+ Student [a]+ "\t\t " + 1 );
  36. System.out.println();
  37.  
  38. }
  39. else { 
  40. System.out.print(" " + Grades[a]+ "\t\t "+ Student [a]+"\t\t" + 0); 
  41. System.out.println();
  42.  
  43. }
  44. }
  45. }
  46.  
Now that I've added the code tags which you had forgotten can you explain what it is you say you are stuck with again because I didn't get your explanation.
Mar 29 '07 #2
ray2007colon
5 New Member
Now that I've added the code tags which you had forgotten can you explain what it is you say you are stuck with again because I didn't get your explanation.

hi, this code is to grade exams, with two arrays, one for the key and one for the student answers, then the program have to comparre the studen answers with the key, to grade the test. I got the two arrays to get the input, and storage the data. Now I need a code to grade the test for the student, add the correct answers. Them I need to loop to grade another test. Thanks for any help.
Mar 29 '07 #3
r035198x
13,262 MVP
Now that I've added the code tags which you had forgotten can you explain what it is you say you are stuck with again because I didn't get your explanation.
If I got your question well then what you need is a counter

Expand|Select|Wrap|Line Numbers
  1.  int correct = 0; 
  2. if (Grades[a].equals(Student[a])) {
  3. System.out.print(" " + Grades[a] +"\t\t "+ Student [a]+ "\t\t " + 1 );
  4. System.out.println();
  5. correct++;
  6. }
  7. else { 
  8. System.out.print(" " + Grades[a]+ "\t\t "+ Student [a]+"\t\t" + 0); 
  9. System.out.println();
  10.  
  11. }
  12.  
  13.  
Now you have the count for the correct ones in the variable correct.
Mar 29 '07 #4
ray2007colon
5 New Member
If I got your question well then what you need is a counter

Expand|Select|Wrap|Line Numbers
  1.  int correct = 0; 
  2. if (Grades[a].equals(Student[a])) {
  3. System.out.print(" " + Grades[a] +"\t\t "+ Student [a]+ "\t\t " + 1 );
  4. System.out.println();
  5. correct++;
  6. }
  7. else { 
  8. System.out.print(" " + Grades[a]+ "\t\t "+ Student [a]+"\t\t" + 0); 
  9. System.out.println();
  10.  
  11. }
  12.  
  13.  
Now you have the count for the correct ones in the variable correct.

Thank you for the help.
Mar 30 '07 #5

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

Similar topics

19
2852
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type > >pointer-to-array-of-size-N-of-type-T (which is fine) and not having type > >array-of-size-N-of-type-T (with some exceptions, which is curious). > > So far > >the consensus seems to be that while everyone is aware of this no one knows
21
3937
by: Matteo Settenvini | last post by:
Ok, I'm quite a newbie, so this question may appear silly. I'm using g++ 3.3.x. I had been taught that an array isn't a lot different from a pointer (in fact you can use the pointer arithmetics to "browse" it). So I expected that when I run this program, I get both c1.A and c2.A pointing to the same address, and changing c1.A means that also c2.A changes too. ----- BEGIN example CODE -----------
7
6889
by: Joseph Lee | last post by:
Hi All, I am having problem when i am using hashtable to keep an array of bytes value as keys. Take a look at the code snippet below --------------------------------------------------- ASCIIEncoding asciiEncoder = new ASCIIEncoding();
3
3795
by: Mark | last post by:
Hi From what I understand, you can pass arrays from classic ASP to .NET using interop, but you have to change the type of the.NET parameter to object. This seems to be because classic ASP passes a variant containing an array, and interop expects a parameter of type object if you are passing a variant (you are expected to cast it to the correct type in your code). I'd like to find a way of passing arrays so that you don't need to change...
38
10179
by: ssg31415926 | last post by:
I need to compare two string arrays defined as string such that the two arrays are equal if the contents of the two are the same, where order doesn't matter and every element must be unique. E.g. these two arrays would test as equal: servers = "Admin" servers = "Finance" servers = "Payroll" servers = "Sales"
39
19647
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1) What's the difference between these 3 statements: (i) memcpy(&b, &KoefD, n); // this works somewhere in my code
0
1098
by: Frank | last post by:
Hi, I use rpy on linux to call R functions. Works fine up to the following problem: How to parse arrays (no vectors, that means 2-dimensional) to R without much effort? The following code solves the problem (in two different ways). However, it seems to me that there might be a way to do it more efficiently.
1
2449
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are of different lengths (e.g. usually between 25 and 45 rows. The columns in each file have the same length). The text files have been numbered sequentially e.g. cb0, cb1, cb2 and so on. I would like to read the data from each text file into...
2
2005
by: Dr Dav | last post by:
Hello all, I'm a physicist whose rewriting a numerical simulation, previously written in IDL, in C with the goal reducing runtime. As you may imagine, my C programming skills are quite poor but I am learning. My problem is this. I had sucessfully written a C code that worked ( with considerable speedup over the IDL version ) using an array size of 100x100. However, I am working towards making the array size closer to 300x300. Since I had...
127
4921
by: sanjay.vasudevan | last post by:
Why are the following declarations invalid in C? int f(); int f(); It would be great if anyone could also explain the design decision for such a language restricton. Regards, Sanjay
0
9618
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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,...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9906
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8933
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
7456
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
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
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
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.