Java程序设计.在线等,求高手帮忙.
设计一个学生类CStudent,其数据成员是学生的注册号、姓名、数学、外语、计算机课程成绩,试着建立几个学生实例,输入相关信息,并在屏幕上显示出来。2楼那位,运行的时候提...
设计一个学生类CStudent,其数据成员是学生的注册号、姓名、数学、外语、计算机课程成绩,试着建立几个学生实例,输入相关信息,并在屏幕上显示出来。
2楼那位,运行的时候提示错误
s[0] = new Student("s001", "张三", 89, 93, 98);
s[1] = new Student("s002", "李四", 86, 79, 90);
s[2] = new Student("s003", "王五", 93, 80, 93);
s[3] = new Student("s004", "赵六", 81, 87, 80); 展开
2楼那位,运行的时候提示错误
s[0] = new Student("s001", "张三", 89, 93, 98);
s[1] = new Student("s002", "李四", 86, 79, 90);
s[2] = new Student("s003", "王五", 93, 80, 93);
s[3] = new Student("s004", "赵六", 81, 87, 80); 展开
5个回答
展开全部
新建一个Student.java类,代码如下:
***************************************************************
public class Student {
// 注册号、姓名、数学、外语、计算机课程成绩
private String id;
private String name;
private Integer maths;
private Integer english;
private Integer computer;
public Student() {
}
public Student(String id, String name, Integer maths, Integer english,
Integer computer) {
this.id = id;
this.name = name;
this.maths = maths;
this.english = english;
this.computer = computer;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getMaths() {
return maths;
}
public void setMaths(Integer maths) {
this.maths = maths;
}
public Integer getEnglish() {
return english;
}
public void setEnglish(Integer english) {
this.english = english;
}
public Integer getComputer() {
return computer;
}
public void setComputer(Integer computer) {
this.computer = computer;
}
public static void main(String[] args) {
Student[] s = new Student[4];
s[0] = new Student("s001", "张三", 89, 93, 98);
s[1] = new Student("s002", "李四", 86, 79, 90);
s[2] = new Student("s003", "王五", 93, 80, 93);
s[3] = new Student("s004", "赵六", 81, 87, 80);
System.out.println("学生信息如下:");
for (int i = 0; i < 4; i++) {
System.out.println("注册号:" + s[i].getId() + ", 姓名:" + s[i].getName()
+ ", 数学:" + s[i].getMaths() + ", 外语:" + s[i].getEnglish()
+ ", 计算机:" + s[i].getComputer());
}
}
}
***************************************************************
运行结果如下:
学生信息如下:
注册号:s001, 姓名:张三, 数学:89, 外语:93, 计算机:98
注册号:s002, 姓名:李四, 数学:86, 外语:79, 计算机:90
注册号:s003, 姓名:王五, 数学:93, 外语:80, 计算机:93
注册号:s004, 姓名:赵六, 数学:81, 外语:87, 计算机:80
***************************************************************
***************************************************************
***************************************************************
回答楼主问题补充:
我是在MyEclipse下运行的,你是在CMD里运行的吧,可能不识别汉语,这样,我把汉字全改为拼音或英文,你试试,代码如下:
***************************************************************
public class Student {
private String id;
private String name;
private Integer maths;
private Integer english;
private Integer computer;
public Student() {
}
public Student(String id, String name, Integer maths, Integer english,
Integer computer) {
this.id = id;
this.name = name;
this.maths = maths;
this.english = english;
this.computer = computer;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getMaths() {
return maths;
}
public void setMaths(Integer maths) {
this.maths = maths;
}
public Integer getEnglish() {
return english;
}
public void setEnglish(Integer english) {
this.english = english;
}
public Integer getComputer() {
return computer;
}
public void setComputer(Integer computer) {
this.computer = computer;
}
public static void main(String[] args) {
Student[] s = new Student[4];
s[0] = new Student("s001", "zhangsan", 89, 93, 98);
s[1] = new Student("s002", "lisi", 86, 79, 90);
s[2] = new Student("s003", "wangwu", 93, 80, 93);
s[3] = new Student("s004", "zhaoliu", 81, 87, 80);
System.out.println("Students' information as follow: ");
for (int i = 0; i < 4; i++) {
System.out.println("ID: " + s[i].getId() + ", Name: "
+ s[i].getName() + ", Maths: " + s[i].getMaths()
+ ", English: " + s[i].getEnglish() + ", Computer: "
+ s[i].getComputer());
}
}
}
***************************************************************
运行结果如下:
Students' information as follow:
ID: s001, Name: zhangsan, Maths: 89, English: 93, Computer: 98
ID: s002, Name: lisi, Maths: 86, English: 79, Computer: 90
ID: s003, Name: wangwu, Maths: 93, English: 80, Computer: 93
ID: s004, Name: zhaoliu, Maths: 81, English: 87, Computer: 80
***************************************************************
public class Student {
// 注册号、姓名、数学、外语、计算机课程成绩
private String id;
private String name;
private Integer maths;
private Integer english;
private Integer computer;
public Student() {
}
public Student(String id, String name, Integer maths, Integer english,
Integer computer) {
this.id = id;
this.name = name;
this.maths = maths;
this.english = english;
this.computer = computer;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getMaths() {
return maths;
}
public void setMaths(Integer maths) {
this.maths = maths;
}
public Integer getEnglish() {
return english;
}
public void setEnglish(Integer english) {
this.english = english;
}
public Integer getComputer() {
return computer;
}
public void setComputer(Integer computer) {
this.computer = computer;
}
public static void main(String[] args) {
Student[] s = new Student[4];
s[0] = new Student("s001", "张三", 89, 93, 98);
s[1] = new Student("s002", "李四", 86, 79, 90);
s[2] = new Student("s003", "王五", 93, 80, 93);
s[3] = new Student("s004", "赵六", 81, 87, 80);
System.out.println("学生信息如下:");
for (int i = 0; i < 4; i++) {
System.out.println("注册号:" + s[i].getId() + ", 姓名:" + s[i].getName()
+ ", 数学:" + s[i].getMaths() + ", 外语:" + s[i].getEnglish()
+ ", 计算机:" + s[i].getComputer());
}
}
}
***************************************************************
运行结果如下:
学生信息如下:
注册号:s001, 姓名:张三, 数学:89, 外语:93, 计算机:98
注册号:s002, 姓名:李四, 数学:86, 外语:79, 计算机:90
注册号:s003, 姓名:王五, 数学:93, 外语:80, 计算机:93
注册号:s004, 姓名:赵六, 数学:81, 外语:87, 计算机:80
***************************************************************
***************************************************************
***************************************************************
回答楼主问题补充:
我是在MyEclipse下运行的,你是在CMD里运行的吧,可能不识别汉语,这样,我把汉字全改为拼音或英文,你试试,代码如下:
***************************************************************
public class Student {
private String id;
private String name;
private Integer maths;
private Integer english;
private Integer computer;
public Student() {
}
public Student(String id, String name, Integer maths, Integer english,
Integer computer) {
this.id = id;
this.name = name;
this.maths = maths;
this.english = english;
this.computer = computer;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getMaths() {
return maths;
}
public void setMaths(Integer maths) {
this.maths = maths;
}
public Integer getEnglish() {
return english;
}
public void setEnglish(Integer english) {
this.english = english;
}
public Integer getComputer() {
return computer;
}
public void setComputer(Integer computer) {
this.computer = computer;
}
public static void main(String[] args) {
Student[] s = new Student[4];
s[0] = new Student("s001", "zhangsan", 89, 93, 98);
s[1] = new Student("s002", "lisi", 86, 79, 90);
s[2] = new Student("s003", "wangwu", 93, 80, 93);
s[3] = new Student("s004", "zhaoliu", 81, 87, 80);
System.out.println("Students' information as follow: ");
for (int i = 0; i < 4; i++) {
System.out.println("ID: " + s[i].getId() + ", Name: "
+ s[i].getName() + ", Maths: " + s[i].getMaths()
+ ", English: " + s[i].getEnglish() + ", Computer: "
+ s[i].getComputer());
}
}
}
***************************************************************
运行结果如下:
Students' information as follow:
ID: s001, Name: zhangsan, Maths: 89, English: 93, Computer: 98
ID: s002, Name: lisi, Maths: 86, English: 79, Computer: 90
ID: s003, Name: wangwu, Maths: 93, English: 80, Computer: 93
ID: s004, Name: zhaoliu, Maths: 81, English: 87, Computer: 80
展开全部
楼主真幽默。。
二楼写的是sql代码。。。你先搞清楚人家在说什么
再说别人有错误吧
你用JVM运行sql代码。。。
二楼写的是sql代码。。。你先搞清楚人家在说什么
再说别人有错误吧
你用JVM运行sql代码。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
/*****************数据库是Oracle数据库************************/
create database stu;
use stu;
create table CStudent(num id,number,varchar(20),name varchar(20),math num,foLanguage num,computer num);
insert into CStudent values(1,'admin','admin',85,92,99);
insert into CStudent values(1,'wwe','wwe',85,92,99);
insert into CStudent values(1,'hhh','hhh',85,92,99);
select * from CStudent;
create database stu;
use stu;
create table CStudent(num id,number,varchar(20),name varchar(20),math num,foLanguage num,computer num);
insert into CStudent values(1,'admin','admin',85,92,99);
insert into CStudent values(1,'wwe','wwe',85,92,99);
insert into CStudent values(1,'hhh','hhh',85,92,99);
select * from CStudent;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你是想写个java类 将数据库里面的东西查出来并且显示到web网页上吗?还是其它的意思?真的没看懂你具体想要实现的是什么!!!
我也给你写一个吧
class CStudent{
public static void main(string[] args)
{
CStudent student=new CStudent();
student.show_studentnews();
}
public Arraylist entry_studentnews()
{
Arraylist news1=null;
Arraylist news2=null;
news1.add("学号");
news1.add("姓名");
news1.add("数学成绩");
news1.add("外语成绩");
news1.add("计算机成绩");
news2.add(news1[0]);
return news2;
}
public void show_studentnews()
{
Arraylist news=entry_studentnews();
for(Arraylist i:news)
{
System.out.println(i[0]+i[1]+i[2]+i[3]+i[4]);
}
}
}
我刚刚写完 这个应该好用可能会有些中英文标点符号不同意自己修改下 (你要是能将我写的这些明白java基础就算入门了)
我也给你写一个吧
class CStudent{
public static void main(string[] args)
{
CStudent student=new CStudent();
student.show_studentnews();
}
public Arraylist entry_studentnews()
{
Arraylist news1=null;
Arraylist news2=null;
news1.add("学号");
news1.add("姓名");
news1.add("数学成绩");
news1.add("外语成绩");
news1.add("计算机成绩");
news2.add(news1[0]);
return news2;
}
public void show_studentnews()
{
Arraylist news=entry_studentnews();
for(Arraylist i:news)
{
System.out.println(i[0]+i[1]+i[2]+i[3]+i[4]);
}
}
}
我刚刚写完 这个应该好用可能会有些中英文标点符号不同意自己修改下 (你要是能将我写的这些明白java基础就算入门了)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
最简单的思路,把数据成员和输出语句写到一个类里 CStudent。然后再建一个学生个人信息类PStudent,把参数传到CStudent里的方法里,调用……
public class CStudent{
public void search(String id,String name, String shuxue,String yingyu){
System.out.println(id,name,shuxue,yingyu);
}
}
public class PStutend{
public String id;
public String name;
public String shuxue;
public String yingyu;
public void studentLi(){
id="1";
name="liming";
shuxue="100";
yingyu="101";
CStudent cs=new CStudent();
cs.search(id,name,shuxue,yingyu);
}
public void studentZhang(){
id="2";
name="ZhangHong";
shuxue="101";
yingyu="190";
CStudent cs=new CStudent();
cs.search(id,name,shuxue,yingyu);
}
public static void main(){
new PStudent().studentLi();
new PStudent().studentZhang();
}
}
虽然在设计上不是很合理,但能达到你的要求,适合初学者。
public class CStudent{
public void search(String id,String name, String shuxue,String yingyu){
System.out.println(id,name,shuxue,yingyu);
}
}
public class PStutend{
public String id;
public String name;
public String shuxue;
public String yingyu;
public void studentLi(){
id="1";
name="liming";
shuxue="100";
yingyu="101";
CStudent cs=new CStudent();
cs.search(id,name,shuxue,yingyu);
}
public void studentZhang(){
id="2";
name="ZhangHong";
shuxue="101";
yingyu="190";
CStudent cs=new CStudent();
cs.search(id,name,shuxue,yingyu);
}
public static void main(){
new PStudent().studentLi();
new PStudent().studentZhang();
}
}
虽然在设计上不是很合理,但能达到你的要求,适合初学者。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询