java实验总结(java实验报告实验过程和步骤怎么写)

本文目录
java实验报告实验过程和步骤怎么写
public interface Auth {
public void check(String name,String pwd,AuthResult result);
}
class AuthResult{
public String msg;// 结果信息
public boolean success;// 验证结果
public boolean isSuccess(){
return success;
}
public String getMsg(){
return msg;
}
}
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
public class Auth1 implements Auth {
Map《String, String》 data = new HashMap《String, String》();
@Override
public void check(String name,String pwd,AuthResult result) {
try {
// 加载用户名和密码
InputStream in = getClass().getResourceAsStream("Auth1.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String temp = null;
while((temp = br.readLine()) != null){
data.put(temp.split(":"));
}
if(data.get(name) == null){
result.success = false;
result.msg = "用户名错误";
return;
}
if(!pwd.equals(data.get(name))){
result.success = false;
result.msg = "密码错误";
return;
}
result.success = true;
result.msg = "auth success!";
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class Auth3 implements Auth {
Map《String, String》 data = new HashMap《String, String》();
@Override
public void check(String name,String pwd,AuthResult result) {
try {
// 加载用户名和密码
InputStream in = getClass().getResourceAsStream("Auth3.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String temp = null;
int i = 1;
String temp1 = null;
while((temp = br.readLine()) != null){
if(i % 2 == 0){
data.put(temp1, temp);
} else {
temp1 = temp;
}
i++;
}
if(data.get(name) == null){
result.success = false;
result.msg = "用户名错误";
return;
}
if(!pwd.equals(data.get(name))){
result.success = false;
result.msg = "密码错误";
return;
}
result.success = true;
result.msg = "auth success!";
} catch (Exception e) {
e.printStackTrace();
}
}
}
import java.util.Scanner;
public class Test {
public static void main(String args) {
Auth1 a1 = new Auth1();
Auth3 a2 = new Auth3();
Scanner sc = new Scanner(System.in);
String name = null;
String pwd = null;
System.out.println("enter name:");
name = sc.nextLine();
System.out.println("enter pwd:");
pwd = sc.nextLine();
AuthResult result = new AuthResult();
System.out.println("---Auth1---check");
a1.check(name,pwd,result);
if(result.isSuccess()){
System.out.println("auth success!");
} else {
System.out.println("auth fail! because " + result.getMsg());
}
System.out.println("---Auth3---check");
a2.check(name,pwd,result = new AuthResult());
if(result.isSuccess()){
System.out.println("auth success!");
} else {
System.out.println("auth fail! because " + result.getMsg());
}
}
}
文件与这些类同包下应该就能读到
Auth1.txt
name1:pwd1
name2:pwd2
Auth3.txt
name3
pwd3
name4
pwd4
java课程设计(证件照应用,包括人脸识别,裁剪,压缩等的)求实验总结
public BufferedImage replaceWithWhiteColor(BufferedImage bi) {
int;
int width = bi.getWidth();
int height = bi.getHeight();
int minx = bi.getMinX();
int miny = bi.getMinY();
/**
* 遍历图片的像素,为处理图片上的杂色,所以要把指定像素上的颜色换成目标白色 用二层循环遍历长和宽上的每个像素
*/
int hitCount = 0;
for (int i = minx; i 《 width-1; i++) {
for (int j = miny; j 《 height; j++) {
/**
* 得到指定像素(i,j)上的RGB值,
*/
int pixel = bi.getRGB(i, j);
int pixelNext = bi.getRGB(i+1, j);
/**
* 分别进行位操作得到 r g b上的值
*/
rgb = (pixel & 0xff0000) 》》 16;
rgb = (pixel & 0xff00) 》》 8;
rgb = (pixel & 0xff);
/**
* 进行换色操作,我这里是要换成白底,那么就判断图片中rgb值是否在范围内的像素
*/
//经过不断尝试,RGB数值相互间相差15以内的都基本上是灰色,
//对以身份证来说特别是介于73到78之间,还有大于100的部分RGB值都是干扰色,将它们一次性转变成白色
if ((Math.abs(rgb) 《 15)
&& (Math.abs(rgb) 《 15)
&& (Math.abs(rgb) 《 15) &&
(((rgb 》 100))) {
//进行换色操作,0xffffff是白色
bi.setRGB(i, j, 0xffffff);
}
}
}

更多文章:
中文自动翻译成英语的输入法(有没有一种输入法能将打出来的中文自动变成英文)
2026年11月7日 02:10
equals to(为什么有些英文句子要用的是“equals to that of” 这个that和of之间还可以加名词吗)
2026年11月7日 01:50
default values(电脑开机后出现all settings was reset to default values.)
2026年11月7日 01:20
structured reviewing翻译(软件测试的英文翻译)
2026年11月7日 00:50
dos命令清屏(Windows DOS内部命令详解04——del、ren、cls、ver、date、time)
2026年11月6日 15:40






