Hey guyz
I have a prac and I am beginner and I did this code>
Is my code is complete and if is it not complete how i can complete it?
and how i can arrange it more?
How I can make my driver to an array that generates an array of 20 students instead of my way of driver to enter it manually? THANK YOU VERY MUCH
I will put the question then I will put my answer
It is two codes one is Student which is the main one and the other one is driverStu which is a test driver
This is my prac question:
Assume a class called Student has the following attributes and methods:
Attributes:
• a unique “idNumber”, which is stored as an integer.
• a firstname and surname
• unit code (eg FIT1002)
• an array called “results” of type float that stores the results of 5 assessment tasks each out of 20 marks.
Methods:
• A computeGrade method that computes and returns the final grade. The final grade is based on the final mark which is the sum of the five assessment items and the final grade is computed using the following rules:
HD if final mark is between 80 and 100
D if final mark is greater than or equal to 70 and less than 80
C if final mark is greater than or equal to 60 and less than 70
P if final mark is greater than or equal to 50 and less than 60
N if final mark is less than 50
• A display method that prints to screen its “idNumber” on a line by itself, the student’s full name, the mark for each assessment task on one line separated by a space, and the final mark and final grade on another line by itself.
a) Draw a class diagram for the Student class.
b) Write the Java code defining the class Student. It should include the following:
i. A constructor which assigns a unique number to instance variable idNumber,
creates space for the results array and leaves the other instance variables empty.
HINT: Use a static variable for the idNumber. Initialise idNumber in the attribute declaration part of the code, then incremented in the constructor.
ii. Accessor methods for each instance variable.
iii. Mutator methods for some of the instance variables. Write comments above the mutator methods justifying the inclusions of these mutator methods.
NOTE The setResults method that can set the mark for each assessment task in the results array. This method takes two parameters: the assessment task number that indicates which assessment task result to set and the result of that particular assessment task. The method therefore sets the result of the appropriate element in the results array. However, if the value of the assessment task number sent as a parameter is outside the bounds of the array or if the result is less than zero or greater than 20, the method does not set the result for that task – it leaves the results as its present value. This method returns true if the mark sent to it was set, and false if it was not set.
iv. A display method.
v. A computeGrade method.
c) Write a test driver class that demonstrates that your constructor, accessors and mutators are working correctly.
This is my codes:
This code is called Student:
/**
* @(#)Student.java
*
*
* @author
* @version 1.00 2008/5/17
*/
public class Student {
private static int ID=0;
String fname;
String sname;
String ucode;
double result[]= new double[5];
double fmark=0;
double t=0;
public Student() {
ID++;
fname="";
sname="";
ucode="";
}
public void setfname(String f){
fname=f;
}
public void setsname(String f){
sname=f;
}
public void setucode(String f){
ucode=f;
}
public boolean setresult(double m, int t){
if(m<0.0 || m>20.0)
return false;
else
result[t]=m;
return true;
}
public String getfname(){
return fname;
}
public String getsname(){
return sname;
}
public String getucode(){
return ucode;
}
public int getID(){
return ID;
}
public String computeGrade(){
for(int i=0; i<5; i++)
fmark+=result[i];
t=fmark;
t/=2;
if(t>=80 && t<=100)
return "HD";
if(t>=70 && t<80)
return "D";
if(t>=60 && t<70)
return "C";
if(t>=50 && t<60)
return "P";
else
return "N";
}
public void display(){
System.out.println("ID FULL NAME UCODE A1 A2 A3 A4 A5 fINAL MARK FINAL GRADE\n");
System.out.print(getID()+" "+getfname()+getsname()+" "+getucode()+" ");
for(int i=0; i<5; i++)
System.out.print(result[i]+" ");
System.out.print(fmark+" "+computeGrade());
}
}
This is the test driver code of the Student program it is called driverStu:
/**
* @(#)driverStu.java
*
*
* @author
* @version 1.00 2008/5/17
*/
public class driverStu {
public static void main(String args[]){
Student s = new Student();
s.setfname("Erick");
s.setsname(" Mouinten");
s.setucode(" FIT1002");
if( s.setresult(25.5,0))
System.out.println("true It was set marks");
else
System.out.println(" False It was NOT set marks");
s.setresult(15.5,1);
s.setresult(15.5,2);
s.setresult(15.5,3);
s.setresult(15.5,4);
s.computeGrade();
s.display();
Student s1 = new Student();
s1.setfname("David");
s1.setsname(" Carmen");
s1.setucode(" FIT2107");
if( s1.setresult(25.5,0))
System.out.println("true It was set marks");
else
System.out.println(" False It was NOT set marks");
s1.setresult(9.5,1);
s1.setresult(11.5,2);
s1.setresult(14.5,3);
s1.setresult(18.5,4);
s1.computeGrade();
s1.display();
}
}
Waiting your replies and thank you very much.
10 1841
None of the Students have their own unique identification code. btw I just saw you
on Sun's Java forum. Any answers from there yet?
kind regards,
Jos
None of the Students have their own unique identification code. btw I just saw you
on Sun's Java forum. Any answers from there yet?
kind regards,
Jos
the Students unique ID code is incremented in the constructor.
Any answers from there yet?
not yet
thanks
the Students unique ID code is incremented in the constructor.
Sure it is but it is a static variable so there is only one for all Students.
kind regards,
Jos
what is the best way to do it then?
thanks
what is the best way to do it then?
thanks
Just keep it as it is but add a private int id to your class and copy the current
ID value to it at construction time; like this: -
public class Student {
-
private static int ID; // initialized to 0
-
...
-
private int id; // private copy, one per Student instance
-
...
-
public Student( ... ) {
-
id= ID++; // copy current ID value and increment for the next Student
-
...
-
}
-
}
-
kind regards,
Jos
ps. @OP: see? people don't like massive crossposts all over the place. Not even
across forums; don't do that anymore.
kind regards,
Jos
and inclose your code with a codetag next time...
eg. [/code] at the end and [code=JAVA] at the top of your code...
regards,
sukatoa
Hey guyz
I have a prac and I am beginner and I did this code>
Is my code is complete and if is it not complete how i can complete it?
and how i can arrange it more?
How I can make my driver to an array that generates an array of 20 students instead of my way of driver to enter it manually? THANK YOU VERY MUCH
I will put the question then I will put my answer
It is two codes one is Student which is the main one and the other one is driverStu which is a test driver
This is my prac question:
Assume a class called Student has the following attributes and methods:
Attributes:
• a unique “idNumber”, which is stored as an integer.
• a firstname and surname
• unit code (eg FIT1002)
• an array called “results” of type float that stores the results of 5 assessment tasks each out of 20 marks.
Methods:
• A computeGrade method that computes and returns the final grade. The final grade is based on the final mark which is the sum of the five assessment items and the final grade is computed using the following rules:
HD if final mark is between 80 and 100
D if final mark is greater than or equal to 70 and less than 80
C if final mark is greater than or equal to 60 and less than 70
P if final mark is greater than or equal to 50 and less than 60
N if final mark is less than 50
• A display method that prints to screen its “idNumber” on a line by itself, the student’s full name, the mark for each assessment task on one line separated by a space, and the final mark and final grade on another line by itself.
a) Draw a class diagram for the Student class.
b) Write the Java code defining the class Student. It should include the following:
i. A constructor which assigns a unique number to instance variable idNumber,
creates space for the results array and leaves the other instance variables empty.
HINT: Use a static variable for the idNumber. Initialise idNumber in the attribute declaration part of the code, then incremented in the constructor.
ii. Accessor methods for each instance variable.
iii. Mutator methods for some of the instance variables. Write comments above the mutator methods justifying the inclusions of these mutator methods.
NOTE The setResults method that can set the mark for each assessment task in the results array. This method takes two parameters: the assessment task number that indicates which assessment task result to set and the result of that particular assessment task. The method therefore sets the result of the appropriate element in the results array. However, if the value of the assessment task number sent as a parameter is outside the bounds of the array or if the result is less than zero or greater than 20, the method does not set the result for that task – it leaves the results as its present value. This method returns true if the mark sent to it was set, and false if it was not set.
iv. A display method.
v. A computeGrade method.
c) Write a test driver class that demonstrates that your constructor, accessors and mutators are working correctly.
This is my codes:
This code is called Student:
/**
* @(#)Student.java
*
*
* @author
* @version 1.00 2008/5/17
*/
public class Student {
private static int ID=0;
String fname;
String sname;
String ucode;
double result[]= new double[5];
double fmark=0;
double t=0;
public Student() {
ID++;
fname="";
sname="";
ucode="";
}
public void setfname(String f){
fname=f;
}
public void setsname(String f){
sname=f;
}
public void setucode(String f){
ucode=f;
}
public boolean setresult(double m, int t){
if(m<0.0 || m>20.0)
return false;
else
result[t]=m;
return true;
}
public String getfname(){
return fname;
}
public String getsname(){
return sname;
}
public String getucode(){
return ucode;
}
public int getID(){
return ID;
}
public String computeGrade(){
for(int i=0; i<5; i++)
fmark+=result[i];
t=fmark;
t/=2;
if(t>=80 && t<=100)
return "HD";
if(t>=70 && t<80)
return "D";
if(t>=60 && t<70)
return "C";
if(t>=50 && t<60)
return "P";
else
return "N";
}
public void display(){
System.out.println("ID FULL NAME UCODE A1 A2 A3 A4 A5 fINAL MARK FINAL GRADE\n");
System.out.print(getID()+" "+getfname()+getsname()+" "+getucode()+" ");
for(int i=0; i<5; i++)
System.out.print(result[i]+" ");
System.out.print(fmark+" "+computeGrade());
}
}
This is the test driver code of the Student program it is called driverStu:
/**
* @(#)driverStu.java
*
*
* @author
* @version 1.00 2008/5/17
*/
public class driverStu {
public static void main(String args[]){
Student s = new Student();
s.setfname("Erick");
s.setsname(" Mouinten");
s.setucode(" FIT1002");
if( s.setresult(25.5,0))
System.out.println("true It was set marks");
else
System.out.println(" False It was NOT set marks");
s.setresult(15.5,1);
s.setresult(15.5,2);
s.setresult(15.5,3);
s.setresult(15.5,4);
s.computeGrade();
s.display();
Student s1 = new Student();
s1.setfname("David");
s1.setsname(" Carmen");
s1.setucode(" FIT2107");
if( s1.setresult(25.5,0))
System.out.println("true It was set marks");
else
System.out.println(" False It was NOT set marks");
s1.setresult(9.5,1);
s1.setresult(11.5,2);
s1.setresult(14.5,3);
s1.setresult(18.5,4);
s1.computeGrade();
s1.display();
}
}
Waiting your replies and thank you very much.
Please put your code in code tags. It is much easier to read.
i am sorry guyz for Crossposting
i just wanted many ideas thats all
sorry and i am not doing it again
thanks again
and i will put as code format next time i am sorry
thanks
thanks
i want to ask you how i can change the test drive to an array?
and do u think the mutator methods are correct?
thank you
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mike Wilcox |
last post by:
I have the following code to select an item from a drop down menu and
call the same script over again. I am expecting that after the first
time the script is run the first echo would produce the...
|
by: Sonoman |
last post by:
Hi all:
I am getting a "missing storage class or idetifier" error and I do not
understand what it means, therefore and I cannot figure it out. I am just
starting a new project and I cannot get...
|
by: Adolfo López Escribano |
last post by:
I'm try to launch db2Backup from Borland Delphi, but I obtain an
undocumented SQLCODE -1152.
Any idea?
My code is the next:
Type
Tsqlca = record
sqlcaid: Array of Char;
sqlcabc: LongInt;...
|
by: Harsha Srinath |
last post by:
Athough this might not be directly relayed to C syntax, I thought some
of you may find this an interesting problem :-
1.One number, in an array integers from 1 to 1,000,000 is present
twice. How...
|
by: Caladin |
last post by:
I'm sure once someone answers this I'll feel really dumb.
I'm a c++ programmer playing with c# an here's my conundrum
I declare a class in the for
public class Form1 :...
|
by: Justin Emlay |
last post by:
I'm hopping someone can help me out on a payroll project I need to
implement.
To start we are dealing with payroll periods. So we are dealing with an
exact 10 days (Monday - Friday, 2 weeks).
...
|
by: Terry |
last post by:
In the code below, I open a file using filestream, copy it to a byte
array, and the write that array out to a new file. But when I check
the size of the original file and the new file, the new...
|
by: manimarank |
last post by:
Greetings to all!!!
Has someone help me the algorithm to find out the missing flatoing values in an array pls..
For example an array contains the value of 1.1 to 1.20 with the increment of 0.1...
|
by: Tarik Monem |
last post by:
Hi guys, it's me one more time today.
I have a PHP file echoing an array back to a javascript file.
Here's the Array being generated:
$myTempArray .=...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
| |