朋友的题,用java语言编写程序的!感激不尽!

img


img

img


题目如图片所示翻译用金山词霸的,对照着看下吧.(此处省略10000000000000000000000000000000000000000000000000000个字)

img


package com.example.taptap;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Description:
 * @Author: 郑涛
 * @Date: 2022-05-27 10:11
 */
public class LockTest {
    public static void main(String[] args) {
        System.out.println("***** 这是一个菜单 ******");
        System.out.println("1. 设置锁定组合");
        System.out.println("2. 闭锁");
        System.out.println("3. 检查状态");
        System.out.println("4. 尝试打开锁定");
        System.out.println("5. 检查拨号盘当前指向的位置");
        System.out.println("6. 退出程序");

        Scanner scanner = new Scanner(System.in);
        Lock lock = new Lock();
        while (true){
            String key = scanner.next();
            switch (key){
                case "1" :
                    System.out.println("请输入3个数字,且三个数字不大于40,三个数字分别对应 x, y, z");
                    int x = scanner.nextInt();
                    int y = scanner.nextInt();
                    int z = scanner.nextInt();
                    lock = new Lock(x, y, z);
                    System.out.println("锁设置完毕,解锁序列为 -> x: " + lock.getX() + " y:" + lock.getY() + " z:" + lock.getZ());
                    break;
                case "2":
                    lock.closeLock();
                    System.out.println("锁已经关闭");
                    break;
                case "3":
                    System.out.println(lock.lookLock() ? "锁已经打开" : "锁当前关闭,可以尝试打开锁");;
                    break;
                case "4":
                    lock.tryOpenLock();
                    break;
                case "5":
                    System.out.println(Arrays.toString(lock.nowLockStatus()));
                    break;
                case "6":
                    System.out.println("推出程序,欢迎下次访问!");
                    return;
                default:
                    System.out.println("请输入正确的菜单号码");
            }
        }
    }
}

class Lock{
    private int x;
    private int y;
    private int z;
    /**
     * 锁定状态
     */
    private boolean close = false;


    /**
     * 默认构造函数
     */
    public Lock(){

    }

    /**
     * 重载构造函数
     */
    public Lock(int x, int y, int z){
        if (x > 40 || y >40 || z > 40){
            System.out.println("锁的可选范围不能大于40哦");
            return;
        }
        this.x = x;
        this.y = y;
        this.z = z;
    }

    /**
     * 转动锁, 每次只转动一下
     */
    public void alter(String key){
        System.out.println("\n当前转动" + key + "值为:");
        for (int i = 0; i <= 40; i++) {
            System.out.print(i);
            if (key.equals("x") && i == this.x){
                return;
            } else if (key.equals("y") && i == this.y){
                return;
            } else if (key.equals("z") && i == this.z){
                return;
            }
            System.out.print(", ");
        }
    }

    /**
     * 关闭锁
     */
    public boolean closeLock(){
        this.close = false;
        return false;
    }

    /**
     * 查询
     */
    public boolean lookLock(){
        return this.close;
    }

    /**
     * 当前
     */
    public int[] nowLockStatus(){
        int[] res = {this.x, this.y, this.z};
        return res;
    }

    public void tryOpenLock(){
        alter("x");
        alter("y");
        alter("z");
        this.close = true;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getZ() {
        return z;
    }

    public void setZ(int z) {
        this.z = z;
    }

    public boolean isClose() {
        return close;
    }

    public void setClose(boolean close) {
        this.close = close;
    }
}

英文题目没人看啊,你就不能翻译一下?

你好,这是一个翻译题,英语翻译汉语,汉语翻译翻译java
难度在哪?需要写答案吗