Difference between revisions of "Grades, Easy"

From Progzoo
Jump to navigation Jump to search
 
(45 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
<table style='float:right'><tr><td style='font-family:monospace'>
 +
#http://progzoo.net/grades10.txt
 +
#Sample data for Easy questions 1-5
 +
#One line per student. One grade per module
 +
#Matric  name    RAD SD1a PS IIS
 +
#
 +
05001001 Alpha, A 50 51 52 53
 +
05001002 Bravo, B 40 41 42 43
 +
05001003 Charlie, C 30 31 32 33
 +
05001004 Delta, D 20 50 50 50
 +
04001005 Echo, E. 50 20 50 50
 +
04001006 Foxtrot, F 50 50 20 50
 +
05001007 Golf, G. 50 50 50 20
 +
05001008 Hotel, H 50 50 50 20
 +
</td></tr></table>
 
<p>Each student takes four modules: RAD, SD1A, PS and IIS. The passing
 
<p>Each student takes four modules: RAD, SD1A, PS and IIS. The passing
grade is 40% in every module.</p>
+
grade is 40% in every module.</p><p>The input data <code>grades10.txt</code> contains one line per student.
<p>The input data <code>grades10.txt</code> contains one line per student.
 
 
The line begins with the matriculation number and the name.
 
The line begins with the matriculation number and the name.
 
The marks for each of the subjects are given in the sequence RAD, SD1a,
 
The marks for each of the subjects are given in the sequence RAD, SD1a,
Line 9: Line 23:
 
==RAD pass list==
 
==RAD pass list==
 
<question className="Grades" title="RAD pass list" copyFile="grades10.txt">
 
<question className="Grades" title="RAD pass list" copyFile="grades10.txt">
<blurb>        
+
<blurb>        
 
<p class="imper">Print the names of the students who have passed the
 
<p class="imper">Print the names of the students who have passed the
 
RAD module.
 
RAD module.
</p>    
+
</p>
 +
<p>
 +
Try adding an if statement, for example try replacing</p>
 +
  System.out.println(name);
 +
with something like ...
 +
if (iis&lt;50)
 +
  System.out.println(name);
 +
   
 
</blurb>  
 
</blurb>  
 
<shell lang="java" import="shellsGrades.xml#easy"/>
 
<shell lang="java" import="shellsGrades.xml#easy"/>
Line 34: Line 55:
 
==Average grade==
 
==Average grade==
 
<question className="Grades" title="Average grade" copyFile="grades10.txt">
 
<question className="Grades" title="Average grade" copyFile="grades10.txt">
<blurb>
+
<blurb>      
 
<p class="imper">
 
<p class="imper">
 
For each student print the name followed by the average grade over the
 
For each student print the name followed by the average grade over the
 
four modules.
 
four modules.
 
</p>   
 
</p>   
 +
<hint tease='Help'>
 +
*Print the name and a number on each line:
 +
System.out.println(name+" "+rad);
 +
*Calculate the average of four numbers:
 +
int average = (rad+iis+ps+sd1a)/4;
 +
</hint>
 
</blurb>
 
</blurb>
 
<shell lang="java" import="shellsGrades.xml#easy"/>
 
<shell lang="java" import="shellsGrades.xml#easy"/>
Line 65: Line 92:
 
Print the names of the students who have passed all four modules.
 
Print the names of the students who have passed all four modules.
 
</p>
 
</p>
 +
You need to print some names but not other. An <code>if</code> statement will do this.
 +
<hint tease='A sample if statement'>
 +
if (rad&lt;50)
 +
  System.out.println(name);
 +
 +
</hint>
 +
<hint tease="Using &amp;&amp; to test multiple conditions">
 +
if (rad&lt;50 &amp;&amp; iis&lt;50)
 +
  System.out.println(name);
 +
</hint>
 
</blurb>
 
</blurb>
 
<shell lang="java" import="shellsGrades.xml#easy"/>
 
<shell lang="java" import="shellsGrades.xml#easy"/>
Line 74: Line 111:
 
}
 
}
 
</prog>
 
</prog>
 +
<answer lang="java"><![CDATA[
 +
static void oneLine(String matric, String name,
 +
                    int rad, int sd1a, int ps, int iis)
 +
{
 +
  if (rad>=40 && sd1a>=40 && ps>=40 && iis>=40)
 +
    System.out.println(name);
 +
}]]>
 +
</answer>
 
</question>
 
</question>
  
Line 80: Line 125:
 
<blurb>
 
<blurb>
 
<p class="imper">
 
<p class="imper">
Print the names of the students who have a matriculation number that
+
Print the matriculation number and the name of the students who have a matriculation number that
 
starts with 04.
 
starts with 04.
</p>  
+
</p>
 +
<hint>
 +
Use the <code>startsWith</code> method.
 +
</hint>
 
</blurb>
 
</blurb>
 
<shell lang="java" import="shellsGrades.xml#easy"/>
 
<shell lang="java" import="shellsGrades.xml#easy"/>
Line 92: Line 140:
 
}
 
}
 
</prog>
 
</prog>
 +
<answer lang="java">
 +
static void oneLine(String matric, String name,
 +
                    int rad, int sd1a, int ps, int iis)
 +
{
 +
  if (matric.startsWith("04"))
 +
    System.out.println(name);
 +
}
 +
</answer>
 
</question>
 
</question>
  
Line 100: Line 156:
 
Print the number of students who have failed the module SD1a.
 
Print the number of students who have failed the module SD1a.
 
</p>  
 
</p>  
 +
You need an accunulator to answer this question.
 +
Recall that the accumulator must be ''initialise'' before the loop and ''updated'' inside the loop.
 
</blurb>
 
</blurb>
 
<shell lang="java" import="shellsGrades.xml#null"/>
 
<shell lang="java" import="shellsGrades.xml#null"/>
Line 121: Line 179:
 
}
 
}
 
</prog>
 
</prog>
 +
 +
<answer lang="java">
 +
import java.io.BufferedReader;
 +
import java.io.FileReader;
 +
public class Grades{
 +
  public static void main(String [] argv)
 +
    throws Exception{
 +
    BufferedReader fh =
 +
      new BufferedReader(new FileReader("grades10.txt"));
 +
    String line;
 +
    int acc=0;
 +
    while((line=fh.readLine())!=null){
 +
      if (line.startsWith("#")) continue;
 +
      String [] wrds = line.split("\t");
 +
      String matric = wrds[0];
 +
      String name  = wrds[1];
 +
      int sd1a = Integer.parseInt(wrds[3]);
 +
      if (sd1a&lt;40)
 +
        acc++;
 +
    }
 +
    System.out.println(acc);
 +
  }
 +
}
 +
</answer>
 
</question>
 
</question>

Latest revision as of 00:01, 8 December 2007

#http://progzoo.net/grades10.txt
#Sample data for Easy questions 1-5
#One line per student. One grade per module
#Matric   	name    	RAD	SD1a	PS	IIS
#
05001001	Alpha, A	50	51	52	53
05001002	Bravo, B	40	41	42	43
05001003	Charlie, C	30	31	32	33
05001004	Delta, D	20	50	50	50
04001005	Echo, E.	50	20	50	50
04001006	Foxtrot, F	50	50	20	50
05001007	Golf, G.	50	50	50	20
05001008	Hotel, H	50	50	50	20

Each student takes four modules: RAD, SD1A, PS and IIS. The passing grade is 40% in every module.

The input data grades10.txt contains one line per student.

The line begins with the matriculation number and the name. The marks for each of the subjects are given in the sequence RAD, SD1a, PS and IIS. Each of these fields is separated by the tab character.

http://progzoo.net/grades10.txt

RAD pass list

Print the names of the students who have passed the RAD module.

Try adding an if statement, for example try replacing

 System.out.println(name);

with something like ...

if (iis<50)
 System.out.println(name);
   



[Font] [Default] [Show] [Resize] [History] [Profile]

Average grade

For each student print the name followed by the average grade over the four modules.



[Font] [Default] [Show] [Resize] [History] [Profile]

Semester pass list

Print the names of the students who have passed all four modules.

You need to print some names but not other. An if statement will do this.



[Font] [Default] [Show] [Resize] [History] [Profile]

Matric 04

Print the matriculation number and the name of the students who have a matriculation number that starts with 04.



[Font] [Default] [Show] [Resize] [History] [Profile]

Count SD1a fails

Print the number of students who have failed the module SD1a.

You need an accunulator to answer this question. Recall that the accumulator must be initialise before the loop and updated inside the loop.




[Font] [Default] [Show] [Resize] [History] [Profile]