Skip to content

第四次作业-文件夹hash值 #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
78 changes: 78 additions & 0 deletions 1105/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*9.7 (账 户类 Account)设计一个名为 Account 的类,它包括: — 个名为 id的 int 类型私有数据域(默认值为 0)。 — 个名为 balance 的 double 类型
私有数据域(默认值为 0>。 — 个 名 为 annuallnterestRate 的 double 类型私有数据域存储当前利率(默认值为 0)。假
设所有的篆户都有相同的利率。 — 个 名 为 的 Date 类型的私有数据域,存储账户的开户日期。 — 个用于创建默认账户的无参构造方法。一个用于创建带特定
id 和初始余额的账户的构造方法。
id、balance 和 annuallnterstRate 的访问器和修改器。
dateCreated 的访问器。
一个名为 getMonthlyInterestRate()的方法,返回月利率。 — 个名为 withDraw 的方法,从账户提取特定数额。 — 个名为 deposit 的方法向账户存储特定数额。*/
package 第三次java作业;

import java.util.Date;
import java.util.Scanner;

public class Account {
private int id = 0;
private double balance = 0;
private double annuallnterestRate = 0;
private Date date = new Date();

public int createAccount() {
System.out.println("您的账户名为" + id);
System.out.println("您的账户余额为" + balance);
return id;
}

public void createyourAccount() {
System.out.println("请输入账户名称");
Scanner input1 = new Scanner(System.in);
String idYours = input1.nextLine();
System.out.println("您的账户余额为" + balance);
Scanner input2 = new Scanner(System.in);
String balanceYours = input2.nextLine();
}

public int getId() {
return id;
}

public void setId() {
this.id = id;
}

public double getBalance() {
return balance;
}

public void setBalance() {
this.balance = balance;
}

public double getAnnuallnterestRate() {
return annuallnterestRate;
}

public void setAnnuallnterestRate() {
this.annuallnterestRate = annuallnterestRate;
}

public double getMonthlyInterestRate() {
double MonthlyInterestRate = annuallnterestRate / 12;
return MonthlyInterestRate;
}

public double withdraw() {
System.out.println("请输入您想提取的金额数量");
Scanner input3 = new Scanner(System.in);
double withdraw = input3.nextDouble();
balance = balance - withdraw;
return balance;
}

public double deposit() {
System.out.println("请输入您想提取的金额数量");
Scanner input3 = new Scanner(System.in);
double deposit = input3.nextDouble();
balance = balance + deposit;
return balance;
}
}
66 changes: 66 additions & 0 deletions 1105/Course.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*13.13 (使得 Course 类可复制)重写程序淸单丨0-6中的 Course 类,增加一个 clone 方法,执行
students 域上的深度复制。*/

package 第三次java作业;

//在10-6的基础上,使用Cloneable接口
public class Course implements Cloneable {//以下的数据域和方法来自10-6的要求
private String courseName;
private String[] students = new String[100];
private int numberOfStudents;

public Course(String courseName) {
this.courseName = courseName;
}

//从这门课添加一个学生
public void addStudent(String student) {
students[numberOfStudents] = student;
numberOfStudents++;//学生总数增加
}

//返回这门课的学生
public String[] getStudents() {
return students;
}

//返回这门课的学生人数
public int getNumberOfStudents() {
return numberOfStudents;
}

//返回课程名
public String getCourseName() {
return courseName;
}

//从这门课程中删除一个学生
public void dropStudent(String student) {//根据名字,遍历找出要drop的学生
if (student == null) {
System.out.println("请输入删除的学生姓名");
}
;
for (int i = 0; i < numberOfStudents; i++) {
if (students[i] == student) {//如果找到
for (int j = i + 1; j < numberOfStudents; i++, j++) {//将该学生后面的
students[i] = students[j];
}
}
numberOfStudents--;//学生总数减少一个
}
}

@Override
public Object clone() throws CloneNotSupportedException {
try {
Course course1 = (Course) super.clone();
course1.students = new String[100];
System.arraycopy(students, 0, course1.students, 0, 100);
course1.courseName = courseName;
course1.numberOfStudents = numberOfStudents;
return course1;
} catch (CloneNotSupportedException ex) {
return null;
}
}
}
46 changes: 46 additions & 0 deletions 1105/arrayList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*13.3 (排 序 ArrayList ) 编写以下方法,对 ArrayList 里面保存的数字进行排序。
public static void sort(ArrayList<Number> list)*/

package 第三次java作业;
import java.util.ArrayList;
import java.util.Arrays;

public class arrayList {
public static void main(String[] args) {
Integer[] number = {1, 2, 5, 9, 20, 15, 17};
ArrayList<Number> list = new ArrayList<>(Arrays.asList(number));//创建arrayList

System.out.println("最初的ArrayList:" + list);
sort(list);
System.out.println("升序排列的ArrayList:" + list);//打印原来的和排序后的动态数组

//测试
list.add(100);
list.add(18);//list加入两个新的整数
System.out.println("加入新元素的ArrayList:" + list);//打印新的list
sort(list);
System.out.println("升序排列的ArrayList:" + list);//对list进行排序
}

public static void sort(ArrayList<Number> list) {
Number temp = list.get(0);

if (list.isEmpty() || list.size() == 0) {//ArrayList为空,程序结束
System.out.println("Arraylist为空");
return;
}

if(list.size()==1) System.out.println(list);//Arraylist只有一个元素,不用排序


for (int i = 0; i < list.size(); i++) {//进行冒泡排序
for (int j = 0; j < list.size()-i-1; j++) {
if (list.get(j).doubleValue() > list.get(j + 1).doubleValue()) {//如果下标j的值>j+1的,两者交换,否则不变
temp = list.get(j);
list.set(j, list.get(j + 1));
var set = list.set(j + 1, temp);
}
}
}
}
}
28 changes: 28 additions & 0 deletions 1105/getnewDate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*9.3 (使用曰期类 Date) 编写程序创建一个 Date 对象,设置它的流逝时间分别为 10000、100000、
1000000、10000000、100000000、1000000000、10000000000、100000000000, 然后使用
toStringO 方法分别显示上述日期。*/
import java.util.Date;

public class getnewDate {
//用于显示日期
public static void printDate(long l, Date date) {
System.out.println("流逝时间为"+l + ": " +","+","+"则日期为");
System.out.println(date.toString());
}
public static void main(String[] args) {
long l = 10000;//用于记录最新的流逝时间

Date date = new Date(l);//新建一个data
printDate(l, date);//调用printData函数输出时间流流逝的日期
l *= 10;//流逝时间变为10000

//通过for循环让l不断增加,循环输出新的时间
for(int i = 0; i < 7; i++) {
date.setTime(l);//setTime重新设定流失时间
printDate(l, date);
l *= 10;
}
}

}

4 changes: 4 additions & 0 deletions 1105/main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package 第三次java作业;

public class main {
}
23 changes: 0 additions & 23 deletions 6.4.java

This file was deleted.

43 changes: 0 additions & 43 deletions scratch.java

This file was deleted.