北邮JAVA高级语言程序设计(选修课)第二次OJ作业

北邮JAVA高级语言程序设计(选修课)第二次OJ作业

题目描述:
定义一个StudentList类用来存储Student对象
属性有
1)Student[] list; //list存储学生对象
2)int total; //学生总人数
方法有:
1)StudentList(int length) //length是数组长度
2)boolean add(Student stu) //增加stu到数组中,成功,返回true,否则false
3)boolean remove(int no) //删除第no个数组元素,删除成功,返回true,否则false
4)boolean remove(String number) //删除学号为number的学生,删除成功,返回true,否则false
5)boolean isEmpty() //判断数组是否为空,若是,返回true,否则false
6)Student getItem(int no) //返回第no个学生
7)Student getItem(String number) //返回学号为number的学生,若该生不存在,返回null。
8) int getTotal() 返回学生总人数

编写StudentList类,并且编写一个StudentListTest类,对StudentList类进行测试。
StudentListTest类运行效果:
菜单如下,请输入 1~8代表您要执行的操作:
1.增加1个学生 2.根据学号删除学生 3.根据位置删除学生 4.判断是否为空 5.根据位置返回学生 6.根据学号返回学生 7.输出全部学生信息 8.退出程序

输入样例,每行表示一个操作,第一个元素为操作代码,之后的元素为操作需要用到的数据。具体参看样例。

添加操作,你需要输出当前所有学生信息,格式如下:
1 Students at the moment as described below:
Number:2011211301
Name:LiHang
Math:88
English:79
Science:90
Ave:85.67

查询操作,若有该学生,则输出其信息:
Student Info:
Number:2011211311
Name:WangZhe
Math:80
English:79
Science:93
Ave:84.00
否则,输出:
No such student

删除操作,若有学生,输出:
Remove successfully
1 Students at the moment as described below:
Number:2011211301
Name:LiHang
Math:88
English:79
Science:90
Ave:85.67
若不存在该学生,输出:
No such student

输入样例:

1 2011211301 LiHang 88 79 90
1 Students at the moment as described below:
Number:2011211301
Name:LiHang
Math:88
English:79
Science:90
Ave:85.67
#(input)#1 2011211311 WangZhe 80 79 93
2 Students at the moment as described below:
Number:2011211301
Name:LiHang
Math:88
English:79
Science:90
Ave:85.67
Number:2011211311
Name:WangZhe
Math:80
English:79
Science:93
Ave:84.00
#(input)#5 10
No such student
#(input)#5 2
Student Info:
Number:2011211311
Name:WangZhe
Math:80
English:79
Science:93
Ave:84.00
#(input)#3 2
Remove successfully
1 Students at the moment as described below:
Number:2011211301
Name:LiHang
Math:88
English:79
Science:90
Ave:85.67

源代码:

import java.text.DecimalFormat;
import java.util.Scanner;

public class StudentListTest {
	public static void main(String args[])
	{
		StudentList list =new StudentList(10);
		Scanner in = new Scanner(System.in);
		while(in.hasNext())
		{
			String line = in.nextLine();
			String str[] = line.split(" ");
			String s1 = str[0];
			int number = Integer.parseInt(s1);
			if(number == 1)
			{
				String StudentNumber = str[1];
				String StudentName = str[2];
				int markForMath = Integer.parseInt(str[3]);
				int markForEnglish = Integer.parseInt(str[4]);
				int markForScience = Integer.parseInt(str[5]);
				Student stu = new Student(StudentNumber,StudentName,markForMath,markForEnglish,markForScience);
				if(list.add(stu))
				{
					System.out.println(list.total+" Students at the moment as described below:");
					list.print();
				}
			}
			if(number == 2)
			{
				if(list.remove(str[1]))
				{
					System.out.println("Remove successfully");
					System.out.println(list.total+" Students at the moment as described below:");
					list.print();
				}
				else
				{
					System.out.println("No such student");

				}
			}
			if(number == 3)
			{
				int location = Integer.parseInt(str[1]);
				if(list.remove(location))
				{
					System.out.println("Remove successfully");
                    System.out.println(list.total+" Students at the moment as described below:");
                    list.print();
				}
				else
				{
					System.out.println("No such student");
				}
			}
			if(number == 4)
			{
				if(list.isEmpty())
				{
					System.out.println("空");
				}
				else
				{
					System.out.println("不空");
				}
			}
			if(number == 5)
			{
				int A = Integer.parseInt(str[1]);
				if(list.getItem(A - 1) != null)
				{
					 System.out.println("Student Info:\n"+list.list[A-1].toString());
				}
				else
				{
					System.out.println("No such student");
				}
			}
			if(number == 6)
			{
				if(list.getItem(str[1]) != null)
				{
					System.out.println("Student Info:\n"+list.getItem(str[1]).toString());
				}
				else
				{
					System.out.println("No such student");
				}
			}
			if(number == 7)
			{
				list.print();
			}
			if(number == 8)
			{
				System.exit(0);
			}
		}
	}
}

class Student
{
	String StudentNumber;
	String StudentName;
	int markForMath;
	int markForEnglish;
	int markForScience;
	double AVE;
	DecimalFormat df=new DecimalFormat("#.00");
	Student(String StudentNumber,String StudentName,int markForMath,int markForEnglish,int markForScience)
	{
		this.StudentNumber = StudentNumber ;
		this.StudentName = StudentName;
		this.markForMath = markForMath;
		this.markForEnglish = markForEnglish;
		this.markForScience = markForScience;
		AVE = (markForMath + markForEnglish + markForScience )/3.00;
	}
	public String toString()
	{
		return ("Number:"+this.StudentNumber+"\n"+"Name:"+this.StudentName+"\n"+
	            "Math:"+this.markForMath+"\n"+"English:"+this.markForEnglish+
	            "\n"+"Science:"+this.markForScience+"\n"+"Ave:"+df.format(AVE));
	}
	
}

class StudentList
{
	Student[] list;
	int total;
	
	StudentList(int length)
	{
		list = new Student[length];
	}
	boolean add(Student stu)
	{
		if(total > list.length)
		{
			return false;
		}
		else
		{
			list[total] = new Student(stu.StudentNumber,stu.StudentName,stu.markForMath,stu.markForEnglish,stu.markForScience);
			total++;
			return true;
		}
	}
	boolean remove(int no)
	{
		if(no > total)
		{
			return false;
		}
		else
		{
			for(int i = no - 1; i < total - 1; i++)
			{
				list[i] = list[i + 1];
			}
			total--;
			return true;
		}
	}
	boolean remove(String number)
	{
		if(!isEmpty())
		{
			for(int i = 0;i < total;i++)
			{
				if(list[i].StudentNumber == number)
				{
					for(int j = i;j < total - 1;j++)
					{
						list[j] = list[j + 1];
					}
				}
				total--;
				return true;
			}
		}
		return false;
	}
	boolean isEmpty()
	{
		if(list.length != 0)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	Student getItem(int no)
	{
		if(no >= total)
		{
			return null;
		}
		else
		{
			return list[no - 1];
		}
	}
	Student getItem(String number)
	{
		if(!isEmpty())
		{
			for(int i = 0;i < total - 1;i++)
			{
				if(list[i].StudentNumber == number)
				{
					return list[i];
				}
			}
		}
		return null;
	}
	int getTotal()
	{
		return total;
	}
	public void print()
	{
		for(int i = 0;i < total;i++)
		{
			System.out.println(list[i].toString());
		}
	}
}
<think>好的,我现在需要处理用户关于文心快码使用方法的查询。首先,用户已经提供了几个引用内容,我需要仔细阅读这些引用,提取关键信息来构建回答。 引用[1]提到安装文心快码插件后,在IDEA中登录的步骤,用户需要点击右侧图标,登录账号。引用[2]说明了代码补齐功能,支持多种语言,用户输入部分代码或关键词即可获得推荐。引用[3]提到代码解释功能,能帮助理解复杂代码的逻辑和上下文。 接下来,我需要按照用户的要求,结构清晰地分步骤说明使用方法。根据示例中的快速排序教程,应该包括基本操作步骤、核心功能以及注意事项。同时,要确保使用中文,正确应用LaTeX格式,虽然这里可能用不上数学公式,但需要检查是否有变量或代码部分需要处理。 用户可能的需求是快速上手文心快码,所以需要简明扼要的步骤,比如安装、登录、代码补齐、代码解释等。同时,生成相关问题,可能涉及高级功能、优化方法、适用场景等。需要确保回答真实可靠,引用来源正确标注,如引用[1]、[2]、[3]。 另外,用户之前的问题可能涉及安装步骤,所以在回答中需要提及安装后的使用流程。注意不要包含用户不可见的系统指令,保持回答在用户可见层。最后,检查是否符合格式要求,如代码块使用正确语法,引用标识正确添加在段落末尾。</think>### 文心快码使用教程 #### 一、基础操作步骤 1. **插件安装与登录** - 确保已在IDEA中安装文心快码插件(安装方法见1.5.2节)[^1]。 - 打开IDEA后,点击右侧的「文心快码」图标,弹出登录界面。 - 点击“登录”按钮,使用百度账号完成身份验证(图1.29)[^1]。 2. **代码快速补齐** - 在编写代码时输入部分代码或关键词(如函数名、变量),例如输入`for i in range`。 - 文心快码会实时推荐完整的代码片段(如`for i in range(n):`),按`Tab`键即可补全[^2]。 - 支持Java、Python、C++等主流编程语言。 3. **代码解释功能** - 选中需要解释的代码段,右键选择「Comate代码解释」。 - 文心快码会生成代码逻辑、功能及上下文关系的详细说明[^3]。 ```python # 示例:使用文心快码补全列表推导式 # 输入 "squares = [x**2" squares = [x**2 for x in range(10)] # 自动补全为完整表达式 ``` #### 二、核心功能详解 1. **智能预测** - 基于深度学习分析代码上下文,预测变量命名、循环结构等。 - 例如输入`def quick_sort(arr):`后,自动补全分治逻辑代码块。 2. **跨语言支持** - Java:自动生成Spring Boot注解代码。 - SQL:补全复杂查询语句(如`SELECT ... JOIN`)。 3. **代码优化建议** - 检测冗余代码(如多重循环),推荐更高效的实现方式。 #### 三、注意事项 1. **网络要求**:需保持网络连接以使用AI服务。 2. **隐私安全**:代码片段仅用于本地分析,不会上传至服务器[^3]。 3. **自定义配置**:通过`Settings > Plugins > Comate`调整补全响应速度、触发关键词等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值