十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
public class Course {
创新互联建站是专业的江宁网站建设公司,江宁接单;提供网站设计、成都网站设计,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行江宁网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
private String name;
private float score;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getScore() {
return score;
}
public void setScore(float score) {
this.score = score;
}
public Course(String name, float score) {
this.name = name;
this.score = score;
}
public String toString() {
return this.name + ":" + this.score;
}
}
public class Student {
private long id;
private String name;
private int age;
private boolean sex;
public String toString() {
String sex = "女";
if (this.sex == true) {
sex = "男";
}
return String.format("姓名:%s,性别:%s,联系电话:%s,课程信息:%s,课程信息:%s", this.name, sex, this.phone, this.subject.toString());
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public boolean isSex() {
return sex;
}
public void setSex(boolean sex) {
this.sex = sex;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public Course[] getSubject() {
return subject;
}
public void setSubject(Course[] subject) {
this.subject = subject;
}
private String phone;
private Course[] subject;
public Student(long i, String n, int a, boolean s, String p) {
this.id = i;
this.name = n;
this.age = a;
this.sex = s;
this.phone = p;
}
}
import java.util.ArrayList;
public class Cmanage {
private ArrayListStudent students;
//插入
public void addStudent(Student student) {
students.add(student);
}
//删除
public void delStudent(Student student) {
students.remove(student);
}
//查询
public void queryStudent() {
System.out.printf("一共有%d个学生", students.size());
for (Student student : students) {
System.out.println(student.toString());
}
}
//修改
public void updateStudent(long i, String n, int a, boolean s, String p)
{
//以姓名做为唯一标识
for(int j=0;jstudents.size();j++)
{
if (students.get(j).getName().equals(n))
{
students.get(j).setId(i);
students.get(j).setAge(a);
students.get(j).setSex(s);
students.get(j).setPhone(p);
}
}
}
}
以下方法实现了用户界面登陆
import java.awt.*;
import java.awt.event.*;
public class DengLuJieMian extends Frame implements ActionListener
{
Label username=new Label("用户名:");//使用文本创建一个用户名标签
TextField t1=new TextField();//创建一个文本框对象
Label password=new Label("密码:");//创建一个密码标签
TextField t2=new TextField();
Button b1=new Button("登陆");//创建登陆按钮
Button b2=new Button("取消");//创建取消按钮
public DengLuJieMian()
{
this.setTitle("学生信息管理系统");//设置窗口标题
this.setLayout(null);//设置窗口布局管理器
username.setBounds(50,40,60,20);//设置姓名标签的初始位置
this.add(username);// 将姓名标签组件添加到容器
t1.setBounds(120,40,80,20);// 设置文本框的初始位置
this.add(t1);// 将文本框组件添加到容器
password.setBounds(50,100,60,20);//密码标签的初始位置
this.add(password);//将密码标签组件添加到容器
t2.setBounds(120,100,80,20);//设置密码标签的初始位置
this.add(t2);//将密码标签组件添加到容器
b1.setBounds(50,150,60,20);//设置登陆按钮的初始位置
this.add(b1);//将登陆按钮组件添加到容器
b2.setBounds(120,150,60,20);//设置取消按钮的初始位置
this.add(b2);// 将取消按钮组件添加到容器
b1.addActionListener(this);//给登陆按钮添加监听器
b2.addActionListener(this);// 给取消按钮添加监听器
this.setVisible(true);//设置窗口的可见性
this.setSize(300,200);//设置窗口的大小
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});//通过内部类重写关闭窗体的方法
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)//处理登陆事件
{
String name=t1.getText();
String pass=t2.getText();
if(name!=nullpass.equals("000123"))//判断语句
{
new StudentJieMian();
}
}
}
public static void main(String args[])//主函数
{
new DengLuJieMian();
}
}
以下方法实现了学生界面设计
import java.awt.*;
import java.awt.event.*;
class StudentJieMian extends Frame implements ActionListener
{
MenuBar m=new MenuBar();//创建菜单栏
Menu m1=new Menu("信息");//创建菜单“信息”
MenuItem m11=new MenuItem("插入");//创建“插入”的菜单项
MenuItem m12=new MenuItem("查询");
Menu m2=new Menu("成绩");//创建菜单“成绩”
MenuItem m21=new MenuItem("查询");
public StudentJieMian()
{
this.setTitle("学生界面");//设置窗口标题
this.setLayout(new CardLayout());//设置窗口布局管理器
this.setMenuBar(m);//将菜单栏组件添加到容器
m.add(m1);//将信息菜单放入菜单栏
m.add(m2);
m1.add(m11);//将“插入”菜单项添加到“信息”菜单
m1.add(m12); //将“查询”菜单项添加到“信息”菜单
m2.add(m21); //将“查询”菜单项添加到“成绩”菜单
m11.addActionListener(this); //给“插入”菜单项添加监听器
m12.addActionListener(this); //给“查询”菜单项添加监听器
m21.addActionListener(this); //给“查询”菜单项添加监听器
this.setVisible(true); //设置窗口的可见性
this.setSize(300,200); //设置窗口的大小
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);//关闭窗口
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==m11) //处理“添加信息”事件
{
new AddStudent();
}
if(e.getSource()==m12) //处理“查询信息”事件
{
new SelectStudent();
}
if(e.getSource()==m21) //处理“查询成绩”事件
{
new ChengJiStudent();
}
}
public static void main(String args[])
{ new StudentJieMian(); //创建一个对象 }
lListStudent students = new ArrayListStudent();
BufferedReader br = new BufferedReader(new FileReader("D:\student.txt"));
String tmpStr = br.readLine();
while(tmpStr != null){
int firstIndex = tmpStr.indexOf(" ");
int secondIndex = tmpStr.indexOf(" ",firstIndex + 1);
int thirdIndex = tmpStr.indexOf(" ", secondIndex + 1);
int forthIndex = tmpStr.indexOf(" ", thirdIndex + 1);
Integer stuId = Integer.parseInt(tmpStr.substring(0,firstIndex));
String stuName = tmpStr.substring(firstIndex + 1,secondIndex);
Integer stuYW = Integer.parseInt(tmpStr.substring(secondIndex + 1,thirdIndex));
Integer stuSX = Integer.parseInt(tmpStr.substring(thirdIndex + 1,forthIndex));
Integer stuYY = Integer.parseInt(tmpStr.substring(forthIndex + 1));
Student student = new Student();
student.setStuId(stuId);
student.setStuName(stuName);
student.setStuYW(stuYW);
student.setStuSX(stuSX);
student.setStuYY(stuYY);
students.add(student);
tmpStr.readLine();
}
//创建一个学生实体类 封装stuId stuName stuYW stuSx stuYY 这5个属性。。。
//已经帮你把数据拆分出来 并以Student 对象的形式放入集合中了 接下来 给分吧 哇咔咔
我也是初学写的不好
public class Student {
static int[] gradesArray={87,68,94,100,83,78,85,91,76,87};
public Student(int[]gradesArray){
}
public void printAllGrade(){
for (int i = 0; i gradesArray.length; i++) {
System.out.println("学号"+(i+1)+"成绩是"+gradesArray[i]);
}
}
public void printAvarage(){
double sum = 0;
for (int i = 0; i gradesArray.length; i++) {
sum+=gradesArray[i];
}
System.out.println("\n平均成绩是"+sum/gradesArray.length);
}
public void printMax(){
int max=gradesArray[0];
for (int i = 0; i gradesArray.length; i++) {
if(gradesArray[i]max){
max=gradesArray[i];
}
}
System.out.println("\n最高分时"+max);
}
public void printMin(){
int min=gradesArray[0];
for (int i = 0; i gradesArray.length; i++) {
if (gradesArray[i]min){
min=gradesArray[i];
}
}
System.out.println("\n最低分时"+min);
}
public void printDistribution(){
int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,j=0,k=0;
for (int i = 0; i gradesArray.length; i++) {
if(gradesArray[i]10){
a++;
}else if (gradesArray[i]=10gradesArray[i]20) {
b++;
}
else if (gradesArray[i]=20gradesArray[i]30) {
c++;
}
else if (gradesArray[i]=30gradesArray[i]40) {
d++;
}
else if (gradesArray[i]=40gradesArray[i]50) {
e++;
}
else if (gradesArray[i]=50gradesArray[i]60) {
f++;
}
else if (gradesArray[i]=60gradesArray[i]70) {
g++;
}
else if (gradesArray[i]=70gradesArray[i]80) {
h++;
}
else if (gradesArray[i]=80gradesArray[i]90) {
j++;
}
else if (gradesArray[i]=90gradesArray[i]100) {
k++;
}
}
System.out.println("\n成绩分布是");
System.out.print("0-10:");
for (int i = 0; i =a; i++) {
System.out.print("*");
}
System.out.print("10-20:");
for (int i = 0; i =b; i++) {
System.out.print("*");
}
System.out.print("20-30:");
for (int i = 0; i =c; i++) {
System.out.print("*");
}
System.out.print("30-40:");
for (int i = 0; i =d; i++) {
System.out.print("*");
}
System.out.print("40-50:");
for (int i = 0; i =e; i++) {
System.out.print("*");
}
System.out.print("50-60:");
for (int i = 0; i =f; i++) {
System.out.print("*");
}
System.out.print("60-70:");
for (int i = 0; i =g; i++) {
System.out.print("*");
}
System.out.print("70-80:");
for (int i = 0; i =h; i++) {
System.out.print("*");
}
System.out.print("80-90:");
for (int i = 0; i =j;i++) {
System.out.print("*");
}
System.out.print("90-100:");
for (int i = 0; i =k; i++) {
System.out.print("*");
}
}
public static void main(String[] args) {
Student student=new Student(gradesArray);
student.printAllGrade();
student.printAvarage();
student.printMax();
student.printMin();
student.printDistribution();
}
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class Sort {
public static void main(String[] args) {
Student p1 = new Student(1001, "小明", 20);
Student p2 = new Student(1002, "小红", 21);
Student p3 = new Student(1003, "小黑", 19);
ListStudent list = new ArrayListStudent();
list.add(p1);
list.add(p2);
list.add(p3);
Collections.sort(list, new ComparatorStudent() {
/*
* int compare(Student o1, Student o2) 返回一个基本类型的整型, 返回负数表示:o1 小于o2,
* 返回0 表示:o1和o2相等, 返回正数表示:o1大于o2。
*/
public int compare(Student o1, Student o2) {
// 按照学生的学号进行升序排列
if (o1.getId() o2.getId()) {
return 1;
}
if (o1.getId() == o2.getId()) {
return 0;
}
return -1;
}
});
write(list);
System.out.println("---------------------");
Collections.sort(list, new ComparatorStudent() {
/*
* int compare(Student o1, Student o2) 返回一个基本类型的整型, 返回负数表示:o1 小于o2,
* 返回0 表示:o1和o2相等, 返回正数表示:o1大于o2。
*/
public int compare(Student o1, Student o2) {
// 按照学生的年龄进行升序排列
if (o1.getAge() o2.getAge()) {
return 1;
}
if (o1.getAge() == o2.getAge()) {
return 0;
}
return -1;
}
});
write(list);
}
public static void write(ListStudent list) {
for (Student s : list) {
System.out.println(s.getId() + "\t" + s.getName() + "\t"
+ s.getAge());
}
}
}
public class Student {
private int id ;
private String name;
private int age;
//构造方法
public Student(int id,String name,int age){
this.id = id;
this.name = name;
this.age = age;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
package student;
import java.util.Scanner;
public class teststudent {
public static void main(String args[]){
System.out.println("************************学生成绩管理系统*********************");
System.out.println("请输入要管理的学生人数:");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
studentMassage stum = new studentMassage(n);
int flag = 1;
while(flag == 1){
System.out.println("1.输入学生信息");
System.out.println("2.通过姓名查找学生信息");
System.out.println("3.显示全部学生信息");
System.out.println("4.退出系统");
int op = sc.nextInt();
switch(op){
case 1:stum.addStudent(n);
new Scanner(System.in).nextLine();
break;
case 2:
System.out.println("输入学生姓名:");
String name = sc.next();
stum.FindStudent(name);
new Scanner(System.in).nextLine();
break;
case 3:
stum.showallStudent();
new Scanner(System.in).nextLine();
break;
case 4:
flag = 0;
System.out.println("已退出系统!");
break;
default:
System.out.println("输入有误!");
new Scanner(System.in).nextLine();
}
}
}
}
class Date{
int year;
int month;
int day;
/*public Date(int year,int month,int day){
this.year = year;
this.month = month;
this.day = day;
}
public Date(){}*/
public String showDate(){
return year + "/"+ month+"/"+day;
}
}
class student{
int id;
String name;
Date date;
float score;
public student(){
id = 0;
name = null;
date = null;
score = 0f;
}
public void showStudent(){
System.out.println( id + " " + name + " "+ " " + date.showDate()+" "+score);
}
}
class studentMassage{
private student[] stu;
private int flag;
public studentMassage(int n){
flag = 0;
if(stu == null){
stu = new student[n];
for(int i =0;in;++i){
stu[i] = new student();
}
}
}
public void addStudent(int n){
flag = 1;
Scanner sc = new Scanner(System.in);
System.out.println("请输入"+n+"个学生信息");
for(int i = 0 ;istu.length;++i){
stu[i].date = new Date();
System.out.println("请输入第"+(i+1)+"个学生学号:");
stu[i].id = sc.nextInt();
System.out.println("请输入第"+(i+1)+"个学生姓名:");
stu[i].name = sc.next();
System.out.println("请输入第"+(i+1)+"个学生出生年份:");
stu[i].date.year = sc.nextInt();
System.out.println("请输入第"+(i+1)+"个学生出生月份:");
stu[i].date.month = sc.nextInt();
System.out.println("请输入第"+(i+1)+"个学生出生日期:");
stu[i].date.day = sc.nextInt();
//stu[i].date = new Date(year,month,day);
System.out.println("请输入第"+(i+1)+"个学生分数:");
stu[i].score = sc.nextFloat();
}
}
public void FindStudent(String sname){
student find = null;
if(flag != 0){
for(int i = 0;istu.length;++i){
if(sname.equals(stu[i].name))
find = stu[i];
}
if(find == null)
System.out.println("查无此人!");
else
find.showStudent();
}else
System.out.println("没有输入学生信息!");
}
public void showallStudent(){
System.out.println("所有学生的信息如下:");
System.out.println("学号 姓名 生日 分数");
for(int i = 0;istu.length;++i){
stu[i].showStudent();
}
}
}