20165303实验一 Java开发环境的熟悉
-
实验一简单的java程序编译及运行,文件夹的创建
1.添加文件夹: 命令mkdir+文件夹名称
2.编译,运行Java程序 :javac 主类名.java
java 主类名
3.带包(package)编译:javac -d . 目标文件夹/主类名.java
运行:java 包名.类
代码
public class shiyan2{
public static void main(String args[]){
System.out.println("shiyan");
}
}
- 实验二IDEA的使用及调试
打开IDEA并创建一个project,然后再创建一个class
输入代码,
public class exp1 {
public static void main(String[] args) {
int i=1;
int j=2;
for(i=1;i<=100;i++){
if(j<50)
j=j+1;
else
j=j-2;
}
System.out.println(i);
System.out.println(j);
System.out.println(i);
}
}
并且运行结果如下
设置断点,并单步向下运行
单步执行循环操作,其中i,j的值在不断的改变
循环内执行特定变量调试
特定变量调试结果如下
调试一次执行
-
学生成绩管理系统
代码如下
import java.util.*;
public class Main {
public static void main(String[] args) {
Student head = new Student();
boolean flag = true;
int i = 0;
int ch;
while (true) {
System.out.println("Please input your choice:");
Scanner in = new Scanner(System.in);
System.out.println("1.Add a new student");
System.out.println("2.Delete an existing student");
System.out.println("3.Revise an existing student");
System.out.println("4.Sort");
System.out.println("5.Refer");
System.out.println("0.Exit");
ch = in.nextInt();
switch (ch) {
case 1:{
flag = Add(head,flag);
Print(head);
break;
}
case 2:{
Delete(head);
Print(head);
break;
}
case 3:{
Revise(head);
Print(head);
break;
}
case 4:{
head = Sort(head);
Print(head);
break;
}
case 5:{
Refer(head);
break;
}
case 0:{
System.exit(0);
break;
}
}
}}
static boolean Add(Student head,boolean flag){
Student p = head;
boolean f = flag;
Scanner in = new Scanner(System.in);
if (f) {
f = false;
}
else {
while (p.nextstu != null) p = p.nextstu;
p.nextstu = new Student();
p = p.nextstu;
}
System.out.println("Please input your name:");
p.setName(in.next());
System.out.println("Please input your ID number:");
p.setNum(in.nextInt());
System.out.println("Please input your score:");
p.setScore(in.nextInt());
return f;
}
static void Delete(Student head){
Student p = head;
Scanner in = new Scanner(System.in);
System.out.println("Please input the ID of the student(Delete)😊;
int id = in.nextInt();
while (true) {
if (p == null) {
System.out.println("Not found!");
return;
}
if (p.nextstu.getNum()!=id) p = p.nextstu;
else break;
}
p.nextstu = p.nextstu.nextstu;
return;
}
static void Revise(Student head){
Student p = head;
Scanner in = new Scanner(System.in);
System.out.println("Please input the ID of the student(Revise)😊;
int id = in.nextInt();
while (true) {
if (pnull) {
System.out.println("Not found!");
return;
}
if (p.getNum()!=id) p = p.nextstu;
else break;
}
System.out.println("Please input your name(Revise)😊;
p.setName(in.next());
System.out.println("Please input your ID number(Revise)😊;
p.setNum(in.nextInt());
System.out.println("Please input your score(Revise)😊;
p.setScore(in.nextInt());
return;
}
static void Refer(Student head) {
Student p = head;
Scanner in = new Scanner(System.in);
System.out.println("Please input the ID of the student(Revise)😊;
int id = in.nextInt();
while (true) {
if (pnull) {
System.out.println("Not found!");
return;
}
if (p.getNum()!=id) p = p.nextstu;
else break;
}
System.out.println("Name:"+p.getName() + " Num:" + p.getNum() + " Score:" + p.getScore());
return;
}
static Student Sort(Student head) {
Student p = head;
Student p1 = p;
Student p2;
Student p3 = p;
Student d = head;
while (p3!=null) {
while (p3 != null) {
if (p1.nextstu.getScore() < p3.getScore()) {
p1 = p3;
}
p3 = p3.nextstu;
}
}
return d;
}
static void Print(Student head){
Student p = head;
while (p!=null) {
System.out.println("Name:"+p.getName() + " Num:" + p.getNum() + " Score:" + p.getScore());
p = p.nextstu;
}
}
}
public class Student {
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
private String name;
private int num;
private int score;
Student nextstu = null;
}
增加
删除
修改
排序
查找
在编写程序的时候,首先遇到的问题就是整个程序的骨架应该怎么写,回想C语言当时的C语言程序管理系统,运用主函数和分函数来写,
再有就是排序的编写比较费劲。
header 1 | header 2 | header3 |
---|---|---|
步骤 | 耗时 | 百分比 |
需求分析 | 30分钟 | 11% |
设计 | 120分钟 | 47% |
代码实现 | 60分钟 | 23% |
测试 | 15分钟 | 5% |
分析总结 | 30分钟 | 11% |