有什么遗失的吗?添加数组? [英] Is there something missing? add array?

查看:63
本文介绍了有什么遗失的吗?添加数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿guyz


我有一个实践,我是初学者,我做了这个代码>

我的代码是完整的,如果不完整我怎么能完成它?

以及我如何安排更多?

如何将我的驱动程序设置为一个生成20个学生阵列的数组,而不是我的手动方式来手动输入?非常感谢

我会提出问题然后我会回答我的答案

这是两个代码,一个是 学生 哪个是主要的,另一个是 driverStu 这是一个测试驱动程序


这是我的实践问题:

假设一个名为Student的类具有以下属性和方法:

属性:

?一个唯一的?idNumber ?,存储为整数。

?名字和姓氏

?单位代码(例如FIT1002)

?一个名为?的数组? float类型的存储,每个存储20个标记中的5个评估任务的结果。

方法:

?一种计算并返回最终成绩的computeGrade方法。最终成绩基于最终成绩,即五个评估项目的总和,最终成绩使用以下规则计算:

HD如果最终成绩在80到100之间

D如果最终标记大于或等于70且小于80

C如果最终标记大于或等于60且小于70

P如果最终标记大于或等于50且小于60

N如果最终标记小于50

?一种显示方法,可以打印以显示其?idNumber?在一条线上,学生的全名,每个评估任务的标记在一行上用空格分隔,最后一个标记和最终成绩在另一行上。

a)绘制Student类的类图。

b)编写定义Student类的Java代码。它应包括以下内容:

i。为实例变量idNumber分配唯一编号的构造函数,

为结果数组创建空间,并将其他实例变量留空。

提示:使用静态变量身份证号码。在代码的属性声明部分初始化idNumber,然后在构造函数中递增。

ii。每个实例变量的访问器方法。

iii。一些实例变量的Mutator方法。在mutator方法上面写注释证明这些mutator方法的包含是正确的。

注意setResults方法可以为结果数组中的每个评估任务设置标记。此方法有两个参数:评估任务编号,指示要设置的评估任务结果以及该特定评估任务的结果。因此,该方法在结果数组中设置相应元素的结果。但是,如果作为参数发送的评估任务编号的值超出了数组的边界,或者如果结果小于零或大于20,则该方法不会为该任务设置结果?它将结果作为现值。如果设置了发送给它的标记,则此方法返回true;如果未设置,则返回false。

iv。一种显示方法。

v。一种computeGrade方法。

c)编写一个测试驱动程序类,演示你的构造函数,访问器和mutator是否正常工作。


这是我的代码:

此代码名为学生


/ **

* @(#)Student.java

*

*

* @author

* @version 1.00 2008/5/17

* /


公共班学生{


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 s etsname(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)

返回false;

else

结果[t] = m;

返回true;


}

public String getfname(){


返回fname;

} $ / $
public String getsname(){


返回sname;

}

public String getucode ()$

返回ucode;

}


public int getID(){


返回ID;

}

public String computeGrade(){


for(int i = 0; i< 5; i ++)

fmark + = result [i];


t = fmark;

t / = 2;

if(t> = 80& t< = 100)

返回HD;

if(t> = 70& t< 80)

返回D;

if(t> = 60& t< 70)

返回C;

if(t> = 50& t< 60)

返回P;

else

返回N;


}

public void display(){

System.out.println(" ID FULL NAME) UCODE A1 A2 A3 A4 A5 fINAL MARK FINAL GRADE \\\
;

System.out.print(getID()+"" + getfname()+ getsname()+"" ; + getucode()+"");

for(int i = 0; i< 5; i ++)

System.out.print(result [i ] +"");

System.out.print(fmark +"" + computeGrade());


}


}



这是测试学生程序的驱动程序代码名为 driverStu


/ **

* @(#)driverStu.java < br $>
*

*

* @author

* @version 1.00 2008/5/17

* /


公共类driverStu {


public static void main(String args []){

学生s =新学生();

s.setfname(" Erick");

s.setsname(" Mouinten");

s.setucode(" FIT1002");


if(s.setresult(25.5,0))

系统.out.println(" true It was set marks");

else

System.out.println(" False It 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();


学生s1 =新学生();

s1。 setfname(" David");

s1.setsname(" Carmen);

s1.setucode(" FIT2107");


if(s1.setresult(25.5,0))

System.out.println(" true它是设置标记");

else

System.out.println(" False它没有设置标记" ;);

s1.setresult(9.5,1);

s1.setresult(11.5,2);

s1.setresult(14.5 ,3);

s1.setresult(18.5,4);

s1.computeGrade();

s1.display(); < br $>


}


}






等待你的回复并非常感谢。

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.

推荐答案

所有学生都没有自己独特的识别码。顺便说一下,我刚刚在Sun的Java论坛上看到了你的
。那里有任何答案吗?


亲切的问候,


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



没有学生拥有自己独特的识别码。顺便说一下,我刚刚在Sun的Java论坛上看到了你的
。那里有任何答案吗?


亲切的问候,


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



学生的唯一ID代码在构造函数中递增。


那里有任何答案吗?


尚未

谢谢



学生唯一ID代码在构造函数中递增。
the Students unique ID code is incremented in the constructor.



当然可以,但它是一个静态变量,因此所有学生只有一个。


亲切的问候,


Jos

Sure it is but it is a static variable so there is only one for all Students.

kind regards,

Jos


这篇关于有什么遗失的吗?添加数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆