用java编写自己的姓名和学号(怎样用JAVA设计学生类Student,包含“学号、班级、姓名、年龄、成员”)

本文目录
- 怎样用JAVA设计学生类Student,包含“学号、班级、姓名、年龄、成员”
- Java:学生信息姓名、学号、成绩定义一个类,并定义相关的构造函数和方法来设置和获取相关的学生信息
- 用java编写一个学生类,学生有学号,姓名,专业,年龄,性别等属性,
- 怎么编写一个简单Java应用程序,输出自己的姓名和学号
- 使用Java语言,造100条大学生的基本信息(学校,专业,姓名,学号)
- 编写java程序实现以下功能:从键盘输入学生姓名、学号、成绩,并保存到文本文件中,重复进行直到遇到空格符
- 编写一个java程序,要求输入自己的学号姓名
- java编写一个学生类,描述学生的学号,姓名,成绩.学号用整型,成绩用浮点型,姓名用Str
- 用java创建一个学生类,包括学号,姓名,成绩,然后构造方法,初始化,输出学生的基本信息
- 怎么用java编写一个打印三角乘法表的程序,程序名为A1,并打印输出自己的学号和名字
怎样用JAVA设计学生类Student,包含“学号、班级、姓名、年龄、成员”
这个很简单呀,要自己试着去写。\r\npublic class Students {\r\n\tprivate String ID; //学号\r\n private String classId; //班级\r\n private String name; //姓名\r\n\tprivate int age; //年龄\r\n public Students(String ID,String classId,String name,int age){//构造函数\r\n this.ID=ID;\r\n this.classId=classId;\t\r\n this.name=name;\r\n this.age= age; \r\n }\r\n\tpublic String getiID() {//获得学号\r\n\t\treturn this.ID;\t\r\n }\r\n\tpublic String getClassId() {//获得班级\r\n\t\treturn this.classId;\r\n\t}\r\n\tpublic String getName() {//获得姓名\r\n\t\treturn this.name;\r\n\t}\r\n\tpublic int getAge() {//获得年龄\r\n\t\treturn this.age;\r\n\t}\r\n\t\r\n\tpublic void setAge(int age){//修改年龄\r\n\t\tthis.age=age;\r\n\t}\t\r\n\tpublic static void main(String args){\r\n\t\tStudents st=new Students("111101","一班","张三","20");\r\n\t\tSystem.out.println(st.getAge());\r\n\t\tst.setAge(30);\r\n\t\tSystem.out.println(st.getAge());\r\n\t}\r\n} \r\n如果在完整一些,可以在加一个toString()函数,用来返回要输出的字符串。
Java:学生信息姓名、学号、成绩定义一个类,并定义相关的构造函数和方法来设置和获取相关的学生信息
1、代码如下:
Main类
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* Main 主方法
* @author bufei
*
*/
public class Main {
public static void main(String args) {
stuGrad();
}
public static void stuGrad() {
int stuNum = 1;
Student;
double;
Map《Double, Integer》 map = new HashMap《》(stuNum);
for (int i = 0; i 《 stuNum; i++) {
System.out.println("请输入第 " + (i + 1) + " 个学生信息:");
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("姓名:");
String name = reader.readLine();
System.out.println("学号:");
int id = Integer.parseInt(reader.readLine());
System.out.print("语文:");
double literature = Double.parseDouble(reader.readLine());
System.out.print("数学:");
double math = Double.parseDouble(reader.readLine());
System.out.print("英语:");
double english = Double.parseDouble(reader.readLine());
stu = new Student(name, id, literature, math, english);
totals.getTotal();
map.put(stu.getTotal(), i);
} catch (Exception e) {
//TODO: handle exception
e.printStackTrace();
}
}
Arrays.sort(totals);
for (int j = stuNum - 1; j 》= 0; j--) {
int i = map.get(totals);
System.out.println(stu.toString());
}
}
}
2、Student类
public class Student {
private String name;
private int stuId;
//总分
private double total;
private double english;
//数学
private double mathematical;
//文学
private double literature;
public String getName(){
return name;
}
public void SetName(String name) {
this.name = name;
}
public int getStuId() {
return stuId;
}
public void setStuId(int stuId) {
this.stuId = stuId;
}
public int getGrade() {
return grade;
}
public void setGrade(int grade) {
this.grade = grade;
}
public Student() {
}
public double getTotal() {
return this.english + this.literature + this.mathematical;
}
public double getEnglish() {
return english;
}
public void setEnglish(double english) {
this.english = english;
}
public double getMathematical() {
return mathematical;
}
public void setMathematical(double mathematical) {
this.mathematical = mathematical;
}
public double getLiterature() {
return literature;
}
public void setLiterature(double literature) {
this.literature = literature;
}
public Student(int stuId, double total, double english, double mathematical, double literature) {
this.stuId = stuId;
this.total = total;
this.english = english;
this.mathematical = mathematical;
this.literature = literature;
}
public Student(String name, int stuId, double english, double mathematical, double literature) {
this.name=name;
this.stuId = stuId;
this.english = english;
this.mathematical = mathematical;
this.literature = literature;
}
@Override
public String toString() {
return "学生 " + name + ",学号 " + stuId + ",总分 =" + getTotal() + " [英语=" + english + ", 语文="
+ literature + ", 数学=" + mathematical + "]";
}
}
3、运行效果
用java编写一个学生类,学生有学号,姓名,专业,年龄,性别等属性,
public class Student {
String xuehao;
String xingming;
String zhuanye;
int nianling;
String xingbie;
void xuexi() {
System.out.println("学习");
}
void chifan() {
System.out.println("吃饭");
}
}
怎么编写一个简单Java应用程序,输出自己的姓名和学号
下面是一个java 小程序实现的\x0d\x0aimport java.awt.*;//引入包\x0d\x0aimport java.applet.Applet;//引入包\x0d\x0apublic class Output extends Applet//定义类\x0d\x0a{\x0d\x0a //定义变量\x0d\x0a private String name;\x0d\x0a private int num;\x0d\x0a //初始化\x0d\x0a public void init()\x0d\x0a {\x0d\x0a name = getParameter("vname");\x0d\x0a num = Integer.parseInt(getParameter("vnum"));\x0d\x0a }\x0d\x0a //输出\x0d\x0a public void paint(Graphics g)\x0d\x0a {\x0d\x0a g.drawString ("姓名:"+name+";学号:"+num,20,30);\x0d\x0a }\x0d\x0a}\x0d\x0a\x0d\x0a相应的html文件\x0d\x0a\x0d\x0a\x0d\x0a
\x0d\x0a
\x0d\x0a\x0d\x0a
使用Java语言,造100条大学生的基本信息(学校,专业,姓名,学号)
import java.util.Random;
public class D1 {
public static void main(String args) {
String name = "";
String zy = "";
for (int i = 0; i 《 100; i++) {
name = getXS();
zy = getJob();
System.out.println("学校:xxxx大学 姓名:"+name+" 专业:"+zy+" 学号:"+(i+1001));
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static String getJob() {
String arr = {"软件工程","多媒体","计算机科学与技术","网络工程"};
Random r = new Random();
return arr;
}
public static String getXS() {
Random random=new Random(System.currentTimeMillis());
/* 598 百家姓 */
String Surname= {"赵","钱","孙","李","周","吴","郑","王","冯","陈","褚","卫","蒋","沈","韩","杨","朱","秦","尤","许",
"何","吕","施","张","孔","曹","严","华","金","魏","陶","姜","戚","谢","邹","喻","柏","水","窦","章","云","苏","潘","葛","奚","范","彭","郎",
"鲁","韦","昌","马","苗","凤","花","方","俞","任","袁","柳","酆","鲍","史","唐","费","廉","岑","薛","雷","贺","倪","汤","滕","殷",
"罗","毕","郝","邬","安","常","乐","于","时","傅","皮","卞","齐","康","伍","余","元","卜","顾","孟","平","黄","和",
"穆","萧","尹","姚","邵","湛","汪","祁","毛","禹","狄","米","贝","明","臧","计","伏","成","戴","谈","宋","茅","庞","熊","纪","舒",
"屈","项","祝","董","梁","杜","阮","蓝","闵","席","季","麻","强","贾","路","娄","危","江","童","颜","郭","梅","盛","林","刁","钟",
"徐","邱","骆","高","夏","蔡","田","樊","胡","凌","霍","虞","万","支","柯","昝","管","卢","莫","经","房","裘","缪","干","解","应",
"宗","丁","宣","贲","邓","郁","单","杭","洪","包","诸","左","石","崔","吉","钮","龚","程","嵇","邢","滑","裴","陆","荣","翁","荀",
"羊","于","惠","甄","曲","家","封","芮","羿","储","靳","汲","邴","糜","松","井","段","富","巫","乌","焦","巴","弓","牧","隗","山",
"谷","车","侯","宓","蓬","全","郗","班","仰","秋","仲","伊","宫","宁","仇","栾","暴","甘","钭","厉","戎","祖","武","符","刘","景",
"詹","束","龙","叶","幸","司","韶","郜","黎","蓟","溥","印","宿","白","怀","蒲","邰","从","鄂","索","咸","籍","赖","卓","蔺","屠",
"蒙","池","乔","阴","郁","胥","能","苍","双","闻","莘","党","翟","谭","贡","劳","逄","姬","申","扶","堵","冉","宰","郦","雍","却",
"璩","桑","桂","濮","牛","寿","通","边","扈","燕","冀","浦","尚","农","温","别","庄","晏","柴","瞿","阎","充","慕","连","茹","习",
"宦","艾","鱼","容","向","古","易","慎","戈","廖","庾","终","暨","居","衡","步","都","耿","满","弘","匡","国","文","寇","广","禄",
"阙","东","欧","殳","沃","利","蔚","越","夔","隆","师","巩","厍","聂","晁","勾","敖","融","冷","訾","辛","阚","那","简","饶","空",
"曾","毋","沙","乜","养","鞠","须","丰","巢","关","蒯","相","查","后","荆","红","游","郏","竺","权","逯","盖","益","桓","公","仉",
"督","岳","帅","缑","亢","况","郈","有","琴","归","海","晋","楚","闫","法","汝","鄢","涂","钦","商","牟","佘","佴","伯","赏","墨",
"哈","谯","篁","年","爱","阳","佟","言","福","南","火","铁","迟","漆","官","冼","真","展","繁","檀","祭","密","敬","揭","舜","楼",
"疏","冒","浑","挚","胶","随","高","皋","原","种","练","弥","仓","眭","蹇","覃","阿","门","恽","来","綦","召","仪","风","介","巨",
"木","京","狐","郇","虎","枚","抗","达","杞","苌","折","麦","庆","过","竹","端","鲜","皇","亓","老","是","秘","畅","邝","还","宾",
"闾","辜","纵","侴","万俟","司马","上官","欧阳","夏侯","诸葛","闻人","东方","赫连","皇甫","羊舌","尉迟","公羊","澹台","公冶","宗正",
"濮阳","淳于","单于","太叔","申屠","公孙","仲孙","轩辕","令狐","钟离","宇文","长孙","慕容","鲜于","闾丘","司徒","司空","兀官","司寇",
"南门","呼延","子车","颛孙","端木","巫马","公西","漆雕","车正","壤驷","公良","拓跋","夹谷","宰父","谷梁","段干","百里","东郭","微生",
"梁丘","左丘","东门","西门","南宫","第五","公仪","公乘","太史","仲长","叔孙","屈突","尔朱","东乡","相里","胡母","司城","张廖","雍门",
"毋丘","贺兰","綦毋","屋庐","独孤","南郭","北宫","王孙"};
int index=random.nextInt(Surname.length-1);
String name = Surname; //获得一个随机的姓氏
/* 从常用字中选取一个或两个字作为名 */
if(random.nextBoolean()){
name+=getChinese()+getChinese();
}else {
name+=getChinese();
}
return name;
}
public static String getChinese() {
String str = null;
int highPos, lowPos;
Random random = new Random();
highPos = (176 + Math.abs(random.nextInt(71)));//区码,0xA0打头,从第16区开始,即0xB0=11*16=176,16~55一级汉字,56~87二级汉字
random=new Random();
lowPos = 161 + Math.abs(random.nextInt(94));//位码,0xA0打头,范围第1~94列
byte;
bArr = (new Integer(highPos)).byteValue();
bArr = (new Integer(lowPos)).byteValue();
try {
str = new String(bArr, "GB2312");//区位码组合成汉字
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
}
编写java程序实现以下功能:从键盘输入学生姓名、学号、成绩,并保存到文本文件中,重复进行直到遇到空格符
public class test3{
public static void main(String args) {
String FilePath="d:\\javaTest\\output.txt";
writeAll(FilePath);
}
private static void writeAll(String filePath) {
File output = new File(filePath);
String outputStr = "";
Scanner sc = new Scanner(System.in);
System.out.println("请输入信息:");
while (true) {
String str = sc.nextLine();
if (str == null || "".equals(str)) {
System.err.println("退出\n\n");
break;
}
outputStr += str + "\r\n";
}
FileWriter fw = null;
BufferedWriter bw = null;
try {
fw = new FileWriter(output, true);
bw = new BufferedWriter(fw);
bw.write(outputStr);
System.out.println("您输入的信息(姓名,学号,成绩):\n" + outputStr + "\n已写入:" + filePath);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
bw.flush();
fw.flush();
bw.close();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
编写一个java程序,要求输入自己的学号姓名
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Test222 {
public static void main(String args) throws IOException {
int i, j;
String a;
BufferedReader str = new BufferedReader(
new InputStreamReader(System.in));
System.out.println("请输入学号:");
a = str.readLine();
System.out.println("学号为:" + a);
str = new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入姓名:");
a = str.readLine();
System.out.println("姓名为:" + a);
}
}
望采纳~~
java编写一个学生类,描述学生的学号,姓名,成绩.学号用整型,成绩用浮点型,姓名用Str
class Student {
private String name;
private int stuId;
private float score;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getStuId() {
return stuId;
}
public void setStuId(int stuId) {
this.stuId = stuId;
}
public float getScore() {
return score;
}
public void setScore(float score) {
this.score = score;
}
public void showInfo() {
System.out.println("Student ");
}
}
用java创建一个学生类,包括学号,姓名,成绩,然后构造方法,初始化,输出学生的基本信息
public class Student {
private String name;
private String number;
private int score;
public Student() {
}
public Student(String name, String number, int score) {
super();
this.name = name;
this.number = number;
this.score = score;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public String toString() {
return "Name: " + name
+ ",Number: " + number
+ ",Score : " + score;
}
//调用方法
public static void main(String args) {
Student s = new Student("Jack","123456",98);
System.out.println(s.toString());
}
}
运行结果:
Name: Jack,Number: 123456,Score : 98
怎么用java编写一个打印三角乘法表的程序,程序名为A1,并打印输出自己的学号和名字
public static void main(String args)
{
String studentNumber = "你的学号";
String studentName = "你的名字";
System.out.println("学号:" + studentNumber + ",姓名:" + studentName);
for (int i = 1; i 《= 9; i++)
{
for (int j = 1; j 《 i + 1; j++)
{
System.out.print(j + "*" + i + "=" + i * j + "\t");
}
System.out.println();
}
}
你把学号和名字改成你自己的就可以了。
希望可以帮到你,望采纳~

更多文章:
nginx是什么网站(我用手机打开网页出现nginx,,是啥意思Nginx防火墙)
2026年10月15日 06:10
php+ mysql教程(怎样通过PHP连接MYSQL数据库、创建数据库、创建表_PHP教程)
2026年10月15日 03:50
candidate是什么意思(candidate中文是什么意思请详细说一下谢谢!)
2026年10月14日 23:10








