作业1:进阶:定义一个Admin类,该类存在,username、password属性,实现一个控制台版的用户注册登录案例 将注册的用户写在一个数组中。
作业2:进阶:Stack的实现
作业3:Order这道题,是一道面试题
作业4: word中的Class56.课程信息类(构造函数)
数据 存数组
创建新数组跟原来一样
返回数组
作业5:class57.MyInteger类(类与对象,构造函数)
素数
>
作业6:Class58.自定义String类(类与对象,构造函数)
package com.openlab.day11.hw;
import com.openlab.day11.hw.modifier.Test;
import com.openlab.day11.hw.modifier.User;
public class MyString {
// 字符串底层是一个字符数组
public char[] chars;
public MyString(char[] chars) {
this.chars = chars;
}
public MyString() {
chars = new char[0];
}
public char charAt(int index) {
if (index >= this.length()) {
// 如果下标越界,则抛出异常
throw new RuntimeException("对不起,下标越界了,字符串没有这个下标");
}
return chars[index];
}
public int length() {
return chars.length;
}
public MyString substring(int begin, int end) {
char[] substr = new char[end - begin];
for (int i = 0; i < substr.length; i++) {
substr[i] = chars[begin + i];
}
return new MyString(substr);
}
public MyString tolower(MyString s) {
char[] substr = new char[this.chars.length];
for (int i = 0; i < substr.length; i++) {
char temp = this.chars[i];
if (temp >= 65 && temp <= 90) {
substr[i] = (char)(this.chars[i] + 32);
} else {
substr[i] = this.chars[i];
}
}
return new MyString(substr);
}
public boolean equals(MyString s1) {
for (int i = 0; i < chars.length; i++) {
if (chars[i] != s1.charAt(i)) {
return false;
}
}
return true;
}
public static MyString valueOf(int i) {
String str = i + "";
char[] substr = new char[str.length()];
for (int j = 0; j < substr.length; j++) {
substr[j] = str.charAt(j);
}
return new MyString(substr);
};
public static void main(String[] args) {
char[] arr = {'t', 'h', 'i', 's', ' ', 'a', ' ', 'b', 'o', 'o', 'k'};
MyString myString = new MyString(arr);
// System.out.println(myString);
System.out.println(myString.charAt(0));
System.out.println(myString.charAt(5));
System.out.println(myString.length());
User u = new User();
System.out.println(u.gender);
}
}