Compare commits
No commits in common. "java" and "main" have entirely different histories.
3
01_Intellij_Java_universal_20240419/.idea/.gitignore
generated
vendored
3
01_Intellij_Java_universal_20240419/.idea/.gitignore
generated
vendored
@ -1,3 +0,0 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/01_Intellij_Java_universal_20240419.iml" filepath="$PROJECT_DIR$/01_Intellij_Java_universal_20240419.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/untitled/ch11" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/untitled/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -1 +0,0 @@
|
||||
776-6761-3633-7047-9651-3662-3256-9614-7203-1094-8468-463-6635-460-9999
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,29 +0,0 @@
|
||||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
3
01_Intellij_Java_universal_20240419/untitled/.idea/.gitignore
generated
vendored
3
01_Intellij_Java_universal_20240419/untitled/.idea/.gitignore
generated
vendored
@ -1,3 +0,0 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Application.iml" filepath="$PROJECT_DIR$/Application.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/ch11" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -1,31 +0,0 @@
|
||||
package ch11_56.test1;
|
||||
|
||||
// 泛型
|
||||
|
||||
public class App11_1 <T>{
|
||||
private T obj;
|
||||
|
||||
public static void main (String[] args){
|
||||
// 两种方式均可
|
||||
// 实例化 name 对象
|
||||
App11_1<String> name = new App11_1<>();
|
||||
/* App11_1<String> name = new App11_1<String>(); */
|
||||
|
||||
// 实例化 age 对象
|
||||
App11_1<Integer> age = new App11_1<>();
|
||||
|
||||
name.setObj("Todd");
|
||||
System.out.println("Name: " + name.getObj());
|
||||
|
||||
age.setObj(114514);
|
||||
System.out.println("Age: " + age.getObj());
|
||||
}
|
||||
|
||||
public T getObj(){
|
||||
return obj;
|
||||
}
|
||||
|
||||
public void setObj(T obj){
|
||||
this.obj = obj;
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
文件已被成功创建!又添加了一行文字!
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Function: 创建 盒子 类
|
||||
* Date: 2024 04 18
|
||||
* Code by: JRNitre
|
||||
* */
|
||||
|
||||
package javaAssignment_20240418;
|
||||
|
||||
public class box {
|
||||
private double length;
|
||||
private double width;
|
||||
private double height;
|
||||
|
||||
public void setBox_length (double l){
|
||||
this.length = l;
|
||||
}
|
||||
public void setBox_width (double w){
|
||||
this.width = w;
|
||||
}
|
||||
public void setBox_height (double h){
|
||||
this.height = h;
|
||||
}
|
||||
public void printVolume(){
|
||||
System.out.println(height * width * length);
|
||||
}
|
||||
|
||||
public static void main (String[] args){
|
||||
// 实例化 box 类
|
||||
box b_1 = new box();
|
||||
|
||||
// 赋值
|
||||
b_1.setBox_height(5);
|
||||
b_1.setBox_length(2);
|
||||
b_1.setBox_width(3);
|
||||
|
||||
// 输出体积
|
||||
b_1.printVolume();
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Function: 创建类计算两个虚数和
|
||||
* Date: 2024 04 18
|
||||
* Code by: JRNitre
|
||||
* */
|
||||
|
||||
package javaAssignment_20240418;
|
||||
public class complex {
|
||||
// 实部
|
||||
private int realPart;
|
||||
// 虚部
|
||||
private int imaginePart;
|
||||
|
||||
// 无参构造方法
|
||||
public complex() {
|
||||
this.realPart = 0;
|
||||
this.imaginePart = 0;
|
||||
}
|
||||
|
||||
// 有参构造方法
|
||||
public complex (int r, int i){
|
||||
this.realPart = r;
|
||||
this.imaginePart = i;
|
||||
}
|
||||
|
||||
// 计算两个虚数和
|
||||
public complex complexAdd (complex a){
|
||||
complex temp = new complex();
|
||||
temp.realPart = this.realPart + a.realPart;
|
||||
temp.imaginePart = this.imaginePart + a.imaginePart;
|
||||
return temp;
|
||||
}
|
||||
|
||||
// 返回计算结果 String
|
||||
public String ToString (){
|
||||
return this.realPart + " + " + this.imaginePart + "i";
|
||||
}
|
||||
|
||||
public static void main (String[] args){
|
||||
complex c_1 = new complex(1,2);
|
||||
complex c_2 = new complex(2,3);
|
||||
complex c_out = c_1.complexAdd(c_2);
|
||||
|
||||
System.out.println(c_out.ToString());
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Function: 学生类
|
||||
* Date: 2024 04 18
|
||||
* Code by: JRNitre
|
||||
* */
|
||||
|
||||
package javaAssignment_20240418;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class student {
|
||||
private int studentID;
|
||||
private String name;
|
||||
private boolean gender;
|
||||
private int age;
|
||||
private int math;
|
||||
private int english;
|
||||
private int chinese;
|
||||
|
||||
public void addStudent_ID (int id){
|
||||
this.studentID = id;
|
||||
}
|
||||
|
||||
public void addStudent_name (String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void addStudent_gender (String Uin){
|
||||
if (Objects.equals(Uin, "男")){
|
||||
this.gender = true;
|
||||
}
|
||||
if (Objects.equals(Uin, "女")){
|
||||
this.gender = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void addStudent_age (int a){
|
||||
this.age = a;
|
||||
}
|
||||
|
||||
public void addStudent_math (int a){
|
||||
this.math = a;
|
||||
}
|
||||
|
||||
public void addStudent_english (int a){
|
||||
this.english = a;
|
||||
}
|
||||
|
||||
public void addStudent_chinese (int a){
|
||||
this.chinese = a;
|
||||
}
|
||||
|
||||
public int getStudent_sum (){
|
||||
return this.math + this.english + this.chinese;
|
||||
}
|
||||
|
||||
public double getStudent_average (){
|
||||
return (double) getStudent_sum() / 3;
|
||||
}
|
||||
|
||||
public void getStudentInfo (){
|
||||
System.out.println("Student ID: " + this.studentID);
|
||||
System.out.println("Student Name: " + this.name);
|
||||
System.out.print("Student Gender: ");
|
||||
if (Objects.equals(this.gender, true)){
|
||||
System.out.println("男");
|
||||
} else{
|
||||
System.out.println("女");
|
||||
}
|
||||
System.out.println("Student Age: " + this.age);
|
||||
System.out.println("Student Sum: " + getStudent_sum());
|
||||
System.out.println("Student Average: " + getStudent_average());
|
||||
}
|
||||
|
||||
public static void main (String[] args){
|
||||
student s1 = new student();
|
||||
|
||||
s1.addStudent_ID(1234);
|
||||
s1.addStudent_name("dog meat");
|
||||
s1.addStudent_gender("男");
|
||||
s1.addStudent_age(15);
|
||||
|
||||
s1.addStudent_chinese(114);
|
||||
s1.addStudent_english(5);
|
||||
s1.addStudent_math(14);
|
||||
|
||||
s1.getStudentInfo();
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Function: 二维数组和
|
||||
* Date: 2024 04 18
|
||||
* Code by: JRNitre
|
||||
* */
|
||||
|
||||
package javaAssignment_20240418;
|
||||
|
||||
public class sumNum {
|
||||
// 行
|
||||
private int m;
|
||||
// 列
|
||||
private int n;
|
||||
// 和
|
||||
private int sum;
|
||||
|
||||
// 带参构造方法
|
||||
public sumNum(int[][] array) {
|
||||
this.m = array.length;
|
||||
this.n = array[0].length;
|
||||
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < this.n; i++){
|
||||
for (j = 0; j < this.m; j++){
|
||||
this.sum += array[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the sum value.
|
||||
*
|
||||
* @return the sum value
|
||||
*/
|
||||
public int getSum (){
|
||||
return this.sum;
|
||||
}
|
||||
|
||||
public int get_m (){
|
||||
return this.m;
|
||||
}
|
||||
|
||||
public int get_n (){
|
||||
return this.n;
|
||||
}
|
||||
|
||||
public static void main (String[] args){
|
||||
int[][] s_array = {{1,2,3},{4,5,6},{7,8,9}};
|
||||
|
||||
sumNum s1 = new sumNum(s_array);
|
||||
|
||||
System.out.println("in " + s1.get_m() + " row and " + s1.get_n() + " column sum: ");
|
||||
System.out.println(s1.getSum());
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Function: Java 多线程
|
||||
* Date: 2024 05 10
|
||||
* Code by: JRNitre
|
||||
* */
|
||||
|
||||
package javaAssignment_20240510;
|
||||
|
||||
class myThread extends Thread{
|
||||
// 成员变量
|
||||
private String who;
|
||||
// 构造方法
|
||||
public myThread(String who){
|
||||
super();
|
||||
this.who = who;
|
||||
}
|
||||
|
||||
public myThread(){
|
||||
super();
|
||||
}
|
||||
|
||||
// 覆盖 run 方法
|
||||
public void run(){
|
||||
for (int i = 0; i < 5; i++){
|
||||
try{
|
||||
sleep(1000);
|
||||
}
|
||||
catch (InterruptedException e){
|
||||
|
||||
}
|
||||
System.out.println(who + "is running");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class thread {
|
||||
public static void main(String[] args){
|
||||
// 创建线程
|
||||
myThread test01Thread = new myThread("test01_Thread");
|
||||
myThread test02Thread = new myThread("test02_Thread");
|
||||
|
||||
test01Thread.start();
|
||||
test02Thread.start();
|
||||
|
||||
System.out.println("system out");
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package javaAssignment_20240514;
|
||||
|
||||
public class bus implements charge{
|
||||
@Override
|
||||
public void charge() {
|
||||
System.out.println("publicBus: 1$/sheet, No Limit Kilometer");
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package javaAssignment_20240514;
|
||||
|
||||
public interface charge {
|
||||
public void charge();
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package javaAssignment_20240514;
|
||||
|
||||
public class cinema implements play, charge {
|
||||
@Override
|
||||
public void play() {
|
||||
System.out.println("Now Showing");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void charge() {
|
||||
System.out.println("Cinema: 30$/sheet, Student half");
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package javaAssignment_20240514;
|
||||
|
||||
public class goods {
|
||||
private String goodsName;
|
||||
|
||||
public goods(String name){
|
||||
this.goodsName = name;
|
||||
}
|
||||
|
||||
// 返回商品名
|
||||
public String getName(){
|
||||
return this.goodsName;
|
||||
}
|
||||
|
||||
// 设置商品名
|
||||
public void setName(String name){
|
||||
this.goodsName = name;
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package javaAssignment_20240514;
|
||||
|
||||
public class market {
|
||||
private String marketName;
|
||||
private String marketGoodsList;
|
||||
|
||||
public market(String name){
|
||||
this.marketName = name;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return this.marketName;
|
||||
}
|
||||
|
||||
public void setName(String name){
|
||||
this.marketName = name;
|
||||
}
|
||||
|
||||
public void getGoodsList(){
|
||||
System.out.println(this.marketGoodsList);
|
||||
}
|
||||
|
||||
public void setGoodsList(String goodlist){
|
||||
this.marketGoodsList = goodlist;
|
||||
}
|
||||
|
||||
public String sell(){
|
||||
return "yee~";
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package javaAssignment_20240514;
|
||||
|
||||
public class person {
|
||||
// 姓名
|
||||
private String personName;
|
||||
// 性别
|
||||
private String personGender;
|
||||
// 年龄
|
||||
private int personAge;
|
||||
|
||||
public person(String name, String gender, int age){
|
||||
this.personName = name;
|
||||
this.personGender = gender;
|
||||
this.personAge = age;
|
||||
}
|
||||
|
||||
public String getInfo(){
|
||||
String bunchInfo;
|
||||
bunchInfo = this.personName + "-" + this.personGender + "-" + this.personAge;
|
||||
return bunchInfo;
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +0,0 @@
|
||||
package javaAssignment_20240514;
|
||||
|
||||
public class person_no3 {
|
||||
private String personName;
|
||||
|
||||
public String getName(){
|
||||
return this.personName;
|
||||
}
|
||||
|
||||
public void setName(String name){
|
||||
this.personName = name;
|
||||
}
|
||||
|
||||
public void shopping(){
|
||||
System.out.println("rob");
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package javaAssignment_20240514;
|
||||
|
||||
public interface play {
|
||||
public void play();
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package javaAssignment_20240514;
|
||||
|
||||
public class student extends person {
|
||||
// 学号
|
||||
private int studentID;
|
||||
// 哲学成绩
|
||||
private int studentPhilosophyScore;
|
||||
// 英语成绩
|
||||
private int studentEnglishScore;
|
||||
// 计算机成绩
|
||||
private int studentComputerScore;
|
||||
|
||||
// 构造函数
|
||||
public student(String name, String gender, int age, int id, int philosophy, int english, int computer) {
|
||||
super(name, gender, age);
|
||||
this.studentID = id;
|
||||
this.studentPhilosophyScore = philosophy;
|
||||
this.studentEnglishScore = english;
|
||||
this.studentComputerScore = computer;
|
||||
}
|
||||
|
||||
// 三门课平均成绩
|
||||
public int aver(){
|
||||
return (this.studentPhilosophyScore + this.studentEnglishScore + this.studentComputerScore) / 3;
|
||||
}
|
||||
|
||||
// 最高分
|
||||
public double max(){
|
||||
return Math.max(Math.max(this.studentComputerScore, this.studentEnglishScore), this.studentPhilosophyScore);
|
||||
}
|
||||
|
||||
// 最低分
|
||||
public int min(){
|
||||
return Math.min(Math.min(this.studentComputerScore, this.studentPhilosophyScore), this.studentEnglishScore);
|
||||
}
|
||||
|
||||
public String getInfo(){
|
||||
String bunchInfo;
|
||||
bunchInfo = this.studentID + "-" + super.getInfo() + "-" + aver() + "-" + max() + "-" + min();
|
||||
return bunchInfo;
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package javaAssignment_20240514;
|
||||
|
||||
public class taxi implements play{
|
||||
@Override
|
||||
public void play() {
|
||||
System.out.println("Taxi: 1.6$/Kilometer, Starting 3 Kilometer");
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
package javaAssignment_20240514;
|
||||
|
||||
public class test{
|
||||
|
||||
/*
|
||||
* class:
|
||||
* person.java
|
||||
* student.java
|
||||
*
|
||||
public static void main (String[] args){
|
||||
student s1 = new student("test", "man", 10, 101, 80, 60, 50);
|
||||
|
||||
System.out.println(s1.getInfo());
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
* interface:
|
||||
* charge.java
|
||||
* play.java
|
||||
* class:
|
||||
* bus.java
|
||||
* taxi.java
|
||||
* cinema.java
|
||||
public static void main (String[] args){
|
||||
cinema c1 = new cinema();
|
||||
|
||||
c1.charge();
|
||||
c1.play();
|
||||
|
||||
bus b1 = new bus();
|
||||
b1.charge();
|
||||
|
||||
taxi t1 = new taxi();
|
||||
t1.play();
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
* class:
|
||||
* goods.java
|
||||
* market.java
|
||||
* person_no3.java
|
||||
public static void main (String[] args){
|
||||
goods g1 = new goods("black_man");
|
||||
|
||||
System.out.println(g1.getName());
|
||||
g1.setName("rainbow_main");
|
||||
|
||||
market m1 = new market("limit");
|
||||
|
||||
System.out.println(m1.getName());
|
||||
m1.setName("no limit");
|
||||
m1.setGoodsList("one black_man - two black_man - three black-man");
|
||||
m1.getGoodsList();
|
||||
System.out.println(m1.sell());
|
||||
|
||||
person_no3 pn1 = new person_no3();
|
||||
|
||||
System.out.println(pn1.getName());
|
||||
pn1.setName("todd");
|
||||
pn1.shopping();
|
||||
}
|
||||
*/
|
||||
}
|
@ -1,131 +0,0 @@
|
||||
/*
|
||||
* Function: Java 课程实验 四 - 第一题部分
|
||||
* Date: 2024 05 20
|
||||
* Code by: JRNitre
|
||||
* */
|
||||
|
||||
package javaAssignment_20240520;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class function_01 {
|
||||
// 私有成员: 文件名
|
||||
private String fileName;
|
||||
|
||||
// 构造函数, 接收需要创建的文件名
|
||||
public function_01(String name ){
|
||||
this.fileName = name;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: createFile
|
||||
* Description:
|
||||
* 创建文件
|
||||
*
|
||||
* Input: void
|
||||
* Return: boolean 文件是否创建成功
|
||||
* */
|
||||
public boolean createFile(){
|
||||
try {
|
||||
// 通过 File 实例化一个 file 对象用于创建文件
|
||||
File file = new File(fileName);
|
||||
// 判断是否已经存在同名文件
|
||||
if (file.createNewFile()){
|
||||
System.out.println("File : " + this.fileName + " Create Done!");
|
||||
return true;
|
||||
} else {
|
||||
System.out.println("The file already exists!");
|
||||
return false;
|
||||
}
|
||||
} catch (IOException ioe){
|
||||
System.out.println("Error");
|
||||
ioe.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: writeToFile
|
||||
* Description:
|
||||
* 覆盖写入内容
|
||||
*
|
||||
* Input: String 需要写入的字符串
|
||||
* Return: boolean 是否写入成功
|
||||
* */
|
||||
public boolean writeToFile(String text){
|
||||
try {
|
||||
// 实例化 writer 对象指定需要写入的文件
|
||||
FileWriter writer = new FileWriter(this.fileName);
|
||||
// write 方法写入字符串
|
||||
writer.write(text);
|
||||
// 写入完毕关闭文件
|
||||
writer.close();
|
||||
// 输出提示
|
||||
System.out.println("Write to File : " + this.fileName + " \"" + text + "\"");
|
||||
return true;
|
||||
} catch (IOException ioe) {
|
||||
System.out.println("Write Error!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: addToFile
|
||||
* Description:
|
||||
* 追加写入内容
|
||||
*
|
||||
* Input: String 需要写入的字符串
|
||||
* Return: boolean 是否写入成功
|
||||
*
|
||||
* Other:
|
||||
* 该方法与 writeToFile 实现原理相同
|
||||
* 构造 FileWriter 时传入的参数中 append 可以通过 boolean 控制追加写入还是覆盖写入
|
||||
* true: 追加
|
||||
* false: 覆盖
|
||||
* */
|
||||
public boolean addToFile(String text){
|
||||
try {
|
||||
FileWriter writer = new FileWriter(this.fileName, true);
|
||||
writer.write(text);
|
||||
writer.close();
|
||||
System.out.println("Add to File : " + this.fileName + " \"" + text + "\"");
|
||||
return true;
|
||||
} catch (IOException ioe){
|
||||
System.out.println("Add Error!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: getFile
|
||||
* Description:
|
||||
* 获取文件内容
|
||||
*
|
||||
* Input: void
|
||||
* Return: String 返回文件内容
|
||||
* */
|
||||
public String getFile(){
|
||||
// 实例化 content 对象用于存储文件内容
|
||||
StringBuilder content = new StringBuilder();
|
||||
try {
|
||||
// 实例化 reader 对象用于读取文件内容
|
||||
BufferedReader reader = new BufferedReader(new FileReader(this.fileName));
|
||||
// line 用于存储每一行内容
|
||||
String line;
|
||||
// while 判断行尾不为空 执行循环
|
||||
while ((line = reader.readLine()) != null) {
|
||||
// 将每一行的字符串拼合至 content 中
|
||||
content.append(line);
|
||||
// 通过 System.lineSeparator() 追加一个换行符
|
||||
content.append(System.lineSeparator());
|
||||
}
|
||||
// 关闭文件
|
||||
reader.close();
|
||||
} catch (IOException ioe) {
|
||||
System.out.println("Read File Error!");
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
// 返回读取到的字符串
|
||||
return content.toString();
|
||||
}
|
||||
}
|
@ -1,170 +0,0 @@
|
||||
/*
|
||||
* Function: Java 课程实验 四 - 第二题部分
|
||||
* Date: 2024 05 20
|
||||
* Code by: JRNitre
|
||||
* */
|
||||
|
||||
package javaAssignment_20240520;
|
||||
|
||||
import java.io.*;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
public class function_02 {
|
||||
public static final int MaxLength = 15;
|
||||
// 文件名
|
||||
private String fileName;
|
||||
// 随机数数组
|
||||
private int[] randomArray = new int[MaxLength];
|
||||
|
||||
// 构造函数, 接收需要创建的文件名
|
||||
// public function_02(String name ){
|
||||
// this.fileName = name;
|
||||
// }
|
||||
|
||||
/*
|
||||
* Function: createRandom
|
||||
* Description:
|
||||
* 生成 15 个随机整数, 并存储到数组中
|
||||
*
|
||||
* Input:
|
||||
* int min 随机数最小值
|
||||
* int max 随机数最大值
|
||||
* Return: int[] 整型数组
|
||||
* */
|
||||
public int[] createRandom(int min, int max){
|
||||
// 通过 SecureRandom (安全随机类) 实例化一个 secureRandom 对象用于生成随机数
|
||||
SecureRandom secureRandom = new SecureRandom();
|
||||
for (int i = 0; i < MaxLength; i++){
|
||||
// 先生成 0 ~ max - min + 1 之间的随机数
|
||||
// 后将生成结果 + min
|
||||
// 最后赋值到随机数数组中
|
||||
randomArray[i] = min + secureRandom.nextInt(max - min + 1);
|
||||
}
|
||||
System.out.println("Create Random Array Done!");
|
||||
// 返回生成完毕的随机数组
|
||||
return randomArray;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: createFile
|
||||
* Description:
|
||||
* 创建文件
|
||||
*
|
||||
* Input: String name 需要创建的文件名
|
||||
* Return: boolean 文件是否创建成功
|
||||
* */
|
||||
public boolean createFile(String name){
|
||||
try {
|
||||
this.fileName = name;
|
||||
// 通过 File 实例化 file 对象用于创建文件
|
||||
File file = new File(fileName);
|
||||
// 判断文件是否创建成功
|
||||
// .createNewFile 方法会检查文件是否存在, 如果不存在就创建文件并返回 true
|
||||
// 否则返回 false 即文件已存在
|
||||
if (file.createNewFile()){
|
||||
System.out.println("File: " + this.fileName + " Create Done!");
|
||||
return true;
|
||||
} else {
|
||||
System.out.println("The file already exists!");
|
||||
return false;
|
||||
}
|
||||
} catch (IOException ioe){
|
||||
System.out.println("Create File Error!");
|
||||
ioe.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: writeToFile
|
||||
* Description:
|
||||
* 向文件写入数据
|
||||
*
|
||||
* Input: String data 需要写入的数据
|
||||
* Return: boolean 是否写入成功
|
||||
* */
|
||||
public boolean writeToFile(String data){
|
||||
try {
|
||||
// 通过 BufferedWriter 实例化 writer 对象用于向文件写入
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(this.fileName));
|
||||
// .write 方法写入数据
|
||||
writer.write(data);
|
||||
// .close 方法写入完毕关闭文件
|
||||
writer.close();
|
||||
System.out.println("Write File Done!");
|
||||
return true;
|
||||
} catch (IOException ioe){
|
||||
System.out.println("Write File Error!");
|
||||
ioe.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: readFileToArray
|
||||
* Description:
|
||||
* 读取文件中的内容并返回数组
|
||||
*
|
||||
* Input: void
|
||||
* Return: int[] 返回的数组
|
||||
* */
|
||||
public int[] readFileToArray(){
|
||||
try{
|
||||
// 通过 BufferedReader 类实例化 reader 对象用于读取文件内容
|
||||
BufferedReader reader = new BufferedReader(new FileReader(this.fileName));
|
||||
// 读取文件中一行的内容
|
||||
String line = reader.readLine();
|
||||
// split 方法以 "-" 为分隔符拆分字符串并写入到字符串数组中
|
||||
String[] strArray = line.split("-");
|
||||
// 创建整型数组
|
||||
int[] intArray = new int[MaxLength];
|
||||
for (int i = 0; i < MaxLength; i++){
|
||||
// 将字符串数组转换为整型赋值给整型数组
|
||||
intArray[i] = Integer.parseInt(strArray[i]);
|
||||
}
|
||||
System.out.println("Reade File to Array Done!");
|
||||
// 返回数组
|
||||
return intArray;
|
||||
} catch (IOException ioe){
|
||||
System.out.println("Reade File to Array Error!");
|
||||
ioe.printStackTrace();
|
||||
// 发生错误时返回一个空数组
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: bubbleSort
|
||||
* Description:
|
||||
* 冒泡排序算法
|
||||
*
|
||||
* Input: void
|
||||
* Return: int[] 需要排序的数组
|
||||
* */
|
||||
public void bubbleSort(int[] array){
|
||||
// 获取输入的数组长度
|
||||
int n = array.length;
|
||||
|
||||
// 冒泡排序
|
||||
for (int i = 0; i < n; i++){
|
||||
for (int j = 0; j < n - i - 1; j++){
|
||||
if (array[j] > array[j + 1]) {
|
||||
int temp = array[j];
|
||||
array[j] = array[j + 1];
|
||||
array[j + 1] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Bubble Sort Done!");
|
||||
|
||||
// 输出排序后的数组
|
||||
for (int i = 0; i < array.length; i++){
|
||||
System.out.print(array[i]);
|
||||
// 打印分隔符
|
||||
if (i != array.length - 1){
|
||||
System.out.print("-");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Function: Java 课程实验 四
|
||||
* Date: 2024 05 20
|
||||
* Code by: JRNitre
|
||||
* */
|
||||
|
||||
package javaAssignment_20240520;
|
||||
|
||||
public class test {
|
||||
public static void main (String[] args){
|
||||
|
||||
/*
|
||||
* 1. 利用文件输入输出流创建一个文件 file1.txt
|
||||
* 2. 写入字符 “文件已被成功创建!”
|
||||
* 3. 文件输入输出流打开文件 file1.txt
|
||||
* 4. 在文件末尾追加一行字符串 “又添加了一行文字”
|
||||
* 5. 打开 file1.txt 读取内容并且显示在屏幕上
|
||||
*
|
||||
* class: function_01.java
|
||||
*
|
||||
|
||||
// 实例化第一个实验内容的对象
|
||||
function_01 f_1 = new function_01("file1.txt");
|
||||
// 创建文件
|
||||
f_1.createFile();
|
||||
// 覆盖写入字符串
|
||||
f_1.writeToFile("文件已被成功创建!");
|
||||
// 追加写入字符串
|
||||
f_1.addToFile("又添加了一行文字!");
|
||||
// 输出文件的内容
|
||||
System.out.println(f_1.getFile());
|
||||
|
||||
*/
|
||||
|
||||
/* ( つ•̀ω•́)つ :-D */
|
||||
|
||||
/*
|
||||
* 1. 产生 15 个 20~9999 之间的随机整数
|
||||
* 2. 利用 BufferedWriter 类将其写入文件 file2.txt 中
|
||||
* 3. 读取该文件中的数据并升序排序
|
||||
*
|
||||
* class: function_02.java
|
||||
*
|
||||
|
||||
// 实例化第二个实验内容的对象 f_2
|
||||
function_02 f_2 = new function_02();
|
||||
|
||||
// 创建文件
|
||||
f_2.createFile("file2.txt");
|
||||
|
||||
// 接收 createRandom 返回的随机数数组
|
||||
int[] array = f_2.createRandom(20, 9999);
|
||||
|
||||
// 使用 StringBuilder 类实例化一个 data 对象用于将
|
||||
// 整型数组转换为 字符串 + 分隔符的形式
|
||||
StringBuilder data = new StringBuilder();
|
||||
|
||||
// 将获取到的数组转换为字符串
|
||||
for (int i = 0; i < array.length; i++){
|
||||
// .append 方法将输入的字符追加到字符串末尾
|
||||
data.append(array[i]);
|
||||
// 插入分隔符
|
||||
if (i != array.length - 1){
|
||||
data.append("-");
|
||||
}
|
||||
}
|
||||
|
||||
// .toString 方法返回 data 中的字符串并将字符串数组写入文件中
|
||||
f_2.writeToFile(data.toString());
|
||||
|
||||
// 读取文件中内容并返回成数组
|
||||
int[] array_copy = f_2.readFileToArray();
|
||||
|
||||
// 调用冒泡排序算法进行排序
|
||||
f_2.bubbleSort(array_copy);
|
||||
|
||||
*/
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Function: Java 课程实验 五 - 第二题 类 二
|
||||
* Date: 2024 05 28
|
||||
* Code by: JRNitre
|
||||
* */
|
||||
|
||||
package javaAssignment_20240528;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class Bank {
|
||||
// 银行名
|
||||
private String bankName;
|
||||
// 银行余额
|
||||
private static int money = 0;
|
||||
|
||||
// 构造函数
|
||||
public Bank (String bankName){
|
||||
this.bankName = bankName;
|
||||
}
|
||||
|
||||
// 获取银行当前余额
|
||||
public int getBankBalance (){
|
||||
return money;
|
||||
}
|
||||
|
||||
// 向银行存钱
|
||||
// static 可以实现在没有实例化对象时就调用这个方法
|
||||
public static synchronized void Funds (int funds){
|
||||
money += funds;
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Function: Java 课程实验 五 - 第二题 类 一
|
||||
* Date: 2024 05 28
|
||||
* Code by: JRNitre
|
||||
* */
|
||||
|
||||
package javaAssignment_20240528;
|
||||
|
||||
public class Customer implements Runnable {
|
||||
// 用户姓名
|
||||
private String customerName;
|
||||
// 存取次数
|
||||
private int customerNum = 3;
|
||||
|
||||
// 构造函数
|
||||
// public Customer (String customerName){
|
||||
// this.customerName = customerName;
|
||||
// }
|
||||
|
||||
// 重写 run 方法
|
||||
@Override
|
||||
public void run() {
|
||||
// 重复指定次数
|
||||
for (int i = 0; i < this.customerNum; i++) {
|
||||
// 输出用户存款信息
|
||||
System.out.println("User: " + Thread.currentThread().getName() + " Deposit 100");
|
||||
// 调用存款方法
|
||||
deposit(100);
|
||||
}
|
||||
}
|
||||
|
||||
// 存款方法
|
||||
private synchronized void deposit(int amount) {
|
||||
Bank.Funds(amount);
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Function: Java 课程实验 五 - 第一题 类
|
||||
* Date: 2024 05 28
|
||||
* Code by: JRNitre
|
||||
* */
|
||||
|
||||
package javaAssignment_20240528;
|
||||
|
||||
public class FlightSystem implements Runnable{
|
||||
// 售票窗口名
|
||||
private String windowName;
|
||||
// 剩余票数
|
||||
private int tickets = 20;
|
||||
|
||||
// 构造函数
|
||||
public FlightSystem(String windowName){
|
||||
this.windowName = windowName;
|
||||
}
|
||||
|
||||
// 重写 run 方法
|
||||
@Override
|
||||
public void run (){
|
||||
while (tickets > 0){
|
||||
Tickets();
|
||||
}
|
||||
}
|
||||
|
||||
// 售票方法
|
||||
private synchronized void Tickets (){
|
||||
if (this.tickets > 0){
|
||||
--this.tickets;
|
||||
System.out.println("Window: " + this.windowName + " Tickets were sold successfully Now remainder" + this.tickets);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Function: Java 课程实验 五
|
||||
* Date: 2024 05 28
|
||||
* Code by: JRNitre
|
||||
* */
|
||||
|
||||
package javaAssignment_20240528;
|
||||
|
||||
public class test {
|
||||
public static void main (String[] args){
|
||||
/*
|
||||
* 用 Runnable 接口程序来模拟航班售票系统
|
||||
* 1. 实现3个售票窗口发售某次航班的20张机票
|
||||
* 2. 一个售票窗口用一个线程来表示。
|
||||
*
|
||||
* Class: FlightSystem
|
||||
*
|
||||
|
||||
FlightSystem window_1 = new FlightSystem("Window_alpha");
|
||||
FlightSystem window_2 = new FlightSystem("Window_bravo");
|
||||
FlightSystem window_3 = new FlightSystem("Window_charlie");
|
||||
|
||||
Thread t_1 = new Thread(window_1);
|
||||
Thread t_2 = new Thread(window_2);
|
||||
Thread t_3 = new Thread(window_3);
|
||||
|
||||
t_1.start();
|
||||
t_2.start();
|
||||
t_3.start();
|
||||
|
||||
*/
|
||||
|
||||
/* ( つ•̀ω•́)つ :-D */
|
||||
|
||||
/*
|
||||
* 1. 设某家银行可接受用户的存款,每进行一次存款,便可计算机出存款的总额。
|
||||
* 2. 现有两名顾客,每人分3次、每次存入100元。
|
||||
*
|
||||
* Class
|
||||
* 1. Bank.java
|
||||
* 2. Customer.java
|
||||
*/
|
||||
|
||||
// 通过 Bank 类实例化 b_1 对象
|
||||
Bank b_1 = new Bank("Best Nigger Bank");
|
||||
|
||||
// 通过 Customer 实例化两个用户对象
|
||||
Customer c_1 = new Customer();
|
||||
|
||||
// 通过 Thread 实例化两个线程类
|
||||
Thread t_1 = new Thread(c_1, "Todd");
|
||||
Thread t_2 = new Thread(c_1, "Todd Copy");
|
||||
|
||||
// 在开始存款前输出一次银行当前的余额
|
||||
System.out.println("Now Bank Balance: " + b_1.getBankBalance());
|
||||
|
||||
// 开始执行两个线程
|
||||
t_1.start();
|
||||
t_2.start();
|
||||
|
||||
// 等待两个线程执行完毕
|
||||
try {
|
||||
t_1.join();
|
||||
t_2.join();
|
||||
} catch (InterruptedException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// 输出当前银行余额
|
||||
System.out.println("Now Bank Balance: " + b_1.getBankBalance());
|
||||
|
||||
/**/
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Function: Java 课程实验 六 - 题目 01
|
||||
* Date: 2024 06 14
|
||||
* Code by: JRNitre
|
||||
* */
|
||||
|
||||
package javaAssignment_20240614;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class function_01 extends Frame implements ActionListener{
|
||||
|
||||
Label userLabel, passLabel;
|
||||
TextField userField;
|
||||
JPasswordField passField;
|
||||
Button loginButton;
|
||||
|
||||
public function_01() {
|
||||
// 设置窗口属性
|
||||
setTitle("User Login");
|
||||
setSize(300, 200);
|
||||
// setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setLayout(new FlowLayout());
|
||||
|
||||
// 添加组件
|
||||
userLabel = new Label("User Id:");
|
||||
add(userLabel);
|
||||
userField = new TextField(15);
|
||||
add(userField);
|
||||
|
||||
passLabel = new Label("Password:");
|
||||
add(passLabel);
|
||||
passField = new JPasswordField(15);
|
||||
add(passField);
|
||||
|
||||
loginButton = new Button("Login");
|
||||
loginButton.addActionListener(this);
|
||||
add(loginButton);
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (e.getSource() == loginButton) {
|
||||
String username = userField.getText();
|
||||
String password = new String(passField.getPassword());
|
||||
if (isValidUser(username, password)) {
|
||||
dispose(); // 关闭当前窗口
|
||||
JOptionPane.showMessageDialog(null, "Login Done!");
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "Error!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isValidUser(String username, String password) {
|
||||
return "user".equals(username) && "pass".equals(password);
|
||||
}
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Function: Java 课程实验 六 - 题目 02
|
||||
* Date: 2024 06 14
|
||||
* Code by: JRNitre
|
||||
* */
|
||||
|
||||
package javaAssignment_20240614;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.*;
|
||||
|
||||
public class function_02 extends JFrame {
|
||||
JLabel num1Label, num2Label, resultLabel;
|
||||
JTextField num1Field, num2Field, resultField;
|
||||
JComboBox<String> operationComboBox;
|
||||
JButton calculateButton;
|
||||
|
||||
public function_02() {
|
||||
super("计算器");
|
||||
|
||||
// 初始化组件
|
||||
num1Label = new JLabel("数字1:");
|
||||
num2Label = new JLabel("数字2:");
|
||||
resultLabel = new JLabel("结果:");
|
||||
num1Field = new JTextField(10);
|
||||
num2Field = new JTextField(10);
|
||||
resultField = new JTextField(10);
|
||||
resultField.setEditable(false); // 结果字段不可编辑
|
||||
operationComboBox = new JComboBox<>(new String[]{"+", "-", "*", "/"});
|
||||
calculateButton = new JButton("计算");
|
||||
|
||||
// 添加动作监听器
|
||||
calculateButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
calculate();
|
||||
}
|
||||
});
|
||||
|
||||
// 设置布局
|
||||
setLayout(new GridLayout(4, 2));
|
||||
|
||||
// 添加组件到窗口
|
||||
add(num1Label);
|
||||
add(num1Field);
|
||||
add(num2Label);
|
||||
add(num2Field);
|
||||
add(new JLabel()); // 空白占位
|
||||
add(operationComboBox);
|
||||
add(resultLabel);
|
||||
add(resultField);
|
||||
add(new JLabel()); // 空白占位
|
||||
add(calculateButton);
|
||||
|
||||
// 设置窗口属性
|
||||
setSize(300, 150);
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
setLocationRelativeTo(null); // 居中显示
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
private void calculate() {
|
||||
try {
|
||||
double num1 = Double.parseDouble(num1Field.getText());
|
||||
double num2 = Double.parseDouble(num2Field.getText());
|
||||
String operation = (String) operationComboBox.getSelectedItem();
|
||||
double result = 0;
|
||||
|
||||
switch (operation) {
|
||||
case "+":
|
||||
result = num1 + num2;
|
||||
break;
|
||||
case "-":
|
||||
result = num1 - num2;
|
||||
break;
|
||||
case "*":
|
||||
result = num1 * num2;
|
||||
break;
|
||||
case "/":
|
||||
if (num2 != 0)
|
||||
result = num1 / num2;
|
||||
else {
|
||||
JOptionPane.showMessageDialog(this, "除数不能为0!");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
resultField.setText(String.valueOf(result));
|
||||
} catch (NumberFormatException ex) {
|
||||
JOptionPane.showMessageDialog(this, "请输入有效的数字!");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Function: Java 课程实验 六 - 题目 03
|
||||
* Date: 2024 06 14
|
||||
* Code by: JRNitre
|
||||
* */
|
||||
|
||||
package javaAssignment_20240614;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
|
||||
public class function_03 {
|
||||
|
||||
public function_03(){
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
createAndShowGUI();
|
||||
});
|
||||
}
|
||||
|
||||
private static void createAndShowGUI() {
|
||||
JFrame frame = new JFrame("选项事件处理");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setLayout(new FlowLayout());
|
||||
|
||||
JTextArea textArea = new JTextArea("选顶事件ItemEvent的使用方法", 6, 20);
|
||||
textArea.setEditable(false);
|
||||
frame.add(textArea);
|
||||
|
||||
JRadioButton redButton = new JRadioButton("红色");
|
||||
JRadioButton blueButton = new JRadioButton("蓝色");
|
||||
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
group.add(redButton);
|
||||
group.add(blueButton);
|
||||
|
||||
ItemListener itemListener = new ItemListener() {
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||
Object source = e.getSource();
|
||||
|
||||
if (source == redButton) {
|
||||
textArea.setForeground(Color.RED);
|
||||
} else if (source == blueButton) {
|
||||
textArea.setForeground(Color.BLUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
redButton.addItemListener(itemListener);
|
||||
blueButton.addItemListener(itemListener);
|
||||
|
||||
frame.add(redButton);
|
||||
frame.add(blueButton);
|
||||
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Function: Java 课程实验 六
|
||||
* Date: 2024 06 14
|
||||
* Code by: JRNitre
|
||||
* */
|
||||
|
||||
package javaAssignment_20240614;
|
||||
|
||||
public class test {
|
||||
public static void main (String[] args){
|
||||
|
||||
/*
|
||||
* 设计实现一个用户登录页面,当单击登录按钮用户名密码正确跳转到计算页面。
|
||||
*
|
||||
* Class: function_01.java
|
||||
*
|
||||
|
||||
function_01 f_1 = new function_01();
|
||||
|
||||
*/
|
||||
|
||||
/* ( つ•̀ω•́)つ :-D */
|
||||
|
||||
/*
|
||||
* 设计实现一个计算页面,实现两个数的加法、减法、乘法和除法运算。
|
||||
*
|
||||
* Class: function_02.java
|
||||
*
|
||||
|
||||
function_02 f_2 = new function_02();
|
||||
|
||||
*/
|
||||
|
||||
/* ( つ•̀ω•́)つ :-D */
|
||||
|
||||
/*
|
||||
* 编写一个应用程序,标题为“选项事件处理”的窗口,窗口布局为FlowLayout。
|
||||
* 设计两个单选按钮,一个文本区。
|
||||
* 单击单选按钮时,将文本区中的文字设置成为相应颜色的字体。
|
||||
*
|
||||
* Class: function_03.java
|
||||
*
|
||||
|
||||
function_03 f_3 = new function_03();
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package javaPackage_20240514;
|
||||
|
||||
public class Bus implements Charge{
|
||||
@Override
|
||||
public void charge() {
|
||||
System.out.println("PublicBus: 1$/sheet, no limit kilometers");
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package javaPackage_20240514;
|
||||
|
||||
public interface Charge {
|
||||
public void charge();
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package javaPackage_20240514;
|
||||
|
||||
public class Cinema implements Charge, Play{
|
||||
|
||||
public void charge() {
|
||||
System.out.println("Cinema: 30$/sheet, enjoy half price with student id");
|
||||
}
|
||||
|
||||
public void play(){
|
||||
System.out.println("Showing movie");
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package javaPackage_20240514;
|
||||
|
||||
public interface Play {
|
||||
public void play();
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package javaPackage_20240514;
|
||||
|
||||
public class Taxi implements Play{
|
||||
|
||||
public void play(){
|
||||
System.out.println("Taxi: 1.6$/kilometer, Starting 3 kilometer");
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Function: 20240516 面向对象程序设计课程实验 NO.2
|
||||
* Date: 2024 05 16
|
||||
* Code by: JRNitre
|
||||
* */
|
||||
|
||||
package javaPackage_20240514;
|
||||
|
||||
public class test {
|
||||
|
||||
/*
|
||||
* 1. 创建一个收费接口 Charge, 其中有一个抽象方法 charge();
|
||||
* 2. 创建另一个收费接口 Play, 其中有一个抽象方法 play();
|
||||
*
|
||||
* 3. 声明 Bus 类来实现接口 Charge, 对于 Bus 类中的 charge(); 实现为输出:
|
||||
* "公共汽车: 1元/张, 不计公里数" PublicBus: 1 $/sheet no limit kilometers
|
||||
* 4. 声明 Taxi 类来实现接口 Charge, 对于 Taxi 中的 charge(); 实现为输出:
|
||||
* "出租车: 1.6元/公里, 起价3公里" Taxi: 1.6$/Kilometer, Starting 3 Kilometer
|
||||
* 5. 声明 Cinema 类来实现接口 Charge, 对于 Cinema 中的 charge(); 实现为输出:
|
||||
* "解放电影院: 30元/张, 凭学生证享受半价" Cinema: 30$/sheet, Enjoy half price with student ID
|
||||
* 对于 Cinema 中的 play(); 实现为输出:
|
||||
* "正在放映电影" Showing movie
|
||||
*
|
||||
* 6. 在主类中创建对象, 输出结果
|
||||
* */
|
||||
|
||||
public static void main(String[] args){
|
||||
Bus b1 = new Bus();
|
||||
Taxi t1 = new Taxi();
|
||||
Cinema c1 = new Cinema();
|
||||
|
||||
b1.charge();
|
||||
t1.play();
|
||||
|
||||
c1.charge();
|
||||
c1.play();
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
package javaPackage_20240524;
|
||||
|
||||
import java.io.*;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
public class function {
|
||||
// 数组长度
|
||||
private int ArrayMaxLength;
|
||||
|
||||
private String fileName;
|
||||
|
||||
public int[] createRandomArray(int num, int min, int max){
|
||||
this.ArrayMaxLength = num;
|
||||
int[] array = new int[this.ArrayMaxLength];
|
||||
SecureRandom secureRandom = new SecureRandom();
|
||||
for (int i = 0; i < this.ArrayMaxLength; i++){
|
||||
array[i] = min + secureRandom.nextInt(max - min + 1);
|
||||
}
|
||||
System.out.println("Create Random Array Done!");
|
||||
return array;
|
||||
}
|
||||
|
||||
public void createFile (String fileName){
|
||||
this.fileName = fileName;
|
||||
File file = new File(fileName);
|
||||
try {
|
||||
if (file.createNewFile()){
|
||||
System.out.println("Create file Done!");
|
||||
} else {
|
||||
System.out.println("Create file Error!");
|
||||
}
|
||||
} catch (IOException ioe){
|
||||
System.out.println("Create file Error!");
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void writeFile (String data){
|
||||
try {
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(this.fileName));
|
||||
writer.write(data);
|
||||
writer.close();
|
||||
System.out.println("Writer Done!");
|
||||
} catch (IOException ioe){
|
||||
System.out.println("Writer Error!");
|
||||
}
|
||||
}
|
||||
|
||||
public int[] readeFileToInt(){
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(this.fileName));
|
||||
String line = reader.readLine();
|
||||
|
||||
String[] arrayStr = line.split("-");
|
||||
|
||||
int[] arrayInt = new int[this.ArrayMaxLength];
|
||||
for (int i = 0; i < this.ArrayMaxLength; i++){
|
||||
arrayInt[i] = Integer.parseInt(arrayStr[i]);
|
||||
}
|
||||
System.out.println("Reader File Done!");
|
||||
return arrayInt;
|
||||
} catch (IOException ioe){
|
||||
System.out.println("Reader File Error!");
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
|
||||
public void bubbleSort(int[] array){
|
||||
int m = array.length;
|
||||
|
||||
for (int i = 0; i < m; i++){
|
||||
for (int j = 0; j < m - i - 1; i++){
|
||||
if (array[j] > array[j+1]){
|
||||
int temp = array[j];
|
||||
array[j] = array[j + 1];
|
||||
array[j + 1] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Sort Done!");
|
||||
|
||||
for (int k = 0; k < m; k++){
|
||||
System.out.print(array[k]);
|
||||
if (k != m - 1){
|
||||
System.out.print(" - ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package javaPackage_20240524;
|
||||
|
||||
public class test {
|
||||
public static void main (String[] args){
|
||||
/*
|
||||
* 1. 产生 15 个 20~9999 之间的随机整数
|
||||
* 2. 利用 BufferedWriter 类将其写入文件 file2.txt 中
|
||||
* 3. 读取该文件中的数据并升序排序
|
||||
*/
|
||||
function f_1 = new function();
|
||||
|
||||
int array[] = f_1.createRandomArray(15, 20, 9999);
|
||||
|
||||
f_1.createFile("file2.txt");
|
||||
StringBuilder s_1 = new StringBuilder();
|
||||
for (int i = 0; i < array.length; i++){
|
||||
s_1.append(array[i]);
|
||||
if (i != array.length - 1){
|
||||
s_1.append("-");
|
||||
}
|
||||
}
|
||||
|
||||
f_1.writeFile(s_1.toString());
|
||||
|
||||
f_1.bubbleSort(f_1.readeFileToInt());
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package javaPackage_20240531;
|
||||
|
||||
public class bank {
|
||||
private static int money;
|
||||
|
||||
private String bankNmae;
|
||||
|
||||
public bank (String name){
|
||||
this.bankNmae = name;
|
||||
}
|
||||
|
||||
public int getMoney(){
|
||||
return money;
|
||||
}
|
||||
|
||||
public static synchronized void add (int n){
|
||||
money += n;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package javaPackage_20240531;
|
||||
|
||||
public class customer implements Runnable{
|
||||
|
||||
private static final int num = 3;
|
||||
|
||||
@Override
|
||||
public void run(){
|
||||
for (int i = 0; i < num; i++){
|
||||
System.out.println("User: " + Thread.currentThread().getName() + " add 100");
|
||||
customerAdd(100);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void customerAdd(int n){
|
||||
bank.add(n);
|
||||
}
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package javaPackage_20240531;
|
||||
|
||||
public class test {
|
||||
public static void main (String[] args){
|
||||
/*
|
||||
* 1. 设某家银行可接受用户的存款,每进行一次存款,便可计算出存款的总额。
|
||||
* 2. 现有两名顾客,每人分3次、每次存入100元。
|
||||
*/
|
||||
|
||||
bank b = new bank("Bank");
|
||||
customer c = new customer();
|
||||
|
||||
Thread t_1 = new Thread(c, "todd");
|
||||
Thread t_2 = new Thread(c, "Copy todd");
|
||||
|
||||
System.out.println("Now Bank: " + b.getMoney());
|
||||
|
||||
t_1.start();
|
||||
t_2.start();
|
||||
|
||||
try {
|
||||
t_1.join();
|
||||
t_2.join();
|
||||
} catch (Exception e){}
|
||||
|
||||
System.out.println("Now Bank: " + b.getMoney());
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package learn_20240419;
|
||||
|
||||
public class Main {
|
||||
public static void main (String[] args){
|
||||
System.out.println("test");
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
3
02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/.idea/.gitignore
generated
vendored
3
02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/.idea/.gitignore
generated
vendored
@ -1,3 +0,0 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
@ -1,5 +0,0 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/ElmAdminEntry.java" charset="GBK" />
|
||||
<file url="file://$PROJECT_DIR$/src/ElmBusinessEntry.java" charset="GBK" />
|
||||
<file url="file://$PROJECT_DIR$/src/View/AdminView.java" charset="GBK" />
|
||||
<file url="file://$PROJECT_DIR$/src/View/BusinessView.java" charset="GBK" />
|
||||
<file url="file://$PROJECT_DIR$/src/View/Display.java" charset="GBK" />
|
||||
<file url="file://$PROJECT_DIR$/src/dao/AdminDaoImpl.java" charset="GBK" />
|
||||
<file url="file://$PROJECT_DIR$/src/dao/BusinessDaoImpl.java" charset="GBK" />
|
||||
<file url="file://$PROJECT_DIR$/src/jdbc/JDBC.java" charset="GBK" />
|
||||
</component>
|
||||
</project>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user