JAVA学习笔记——JAVA阶段项目三:开发团队调度软件(B站尚硅谷JAVA基础学习)

本文记录了跟随尚硅谷网课开发JAVA基础阶段的团队调度软件过程。项目涉及键盘访问、Equipment接口与Employee类设计、TeamService类及自定义异常处理,通过这个简单项目,复习了JAVA的多态、封装、继承等基础知识,以及异常处理和数组应用。虽然项目简单,但对于巩固基础非常有帮助。
摘要由CSDN通过智能技术生成

https://www.bilibili.com/video/BV1Kb411W75N

跟着尚硅谷网课做阶段小项目~

比较简单的一个小项目,主要是回顾下两周JAVA基础的学习 

 

 

 

第一步——创建项目基本组件

键盘访问的实现

 

package kx.view;

import java.util.*;
/**
 * 
 * @Description 项目中提供了TSUtility.java类,可用来方便地实现键盘访问。
 * @author shkstart  Email:shkstart@126.com
 * @version 
 * @date 2019年2月12日上午12:02:58
 *
 */
public class TSUtility {
    private static Scanner scanner = new Scanner(System.in);
    /**
     * 
     * @Description 该方法读取键盘,如果用户键入’1’-’4’中的任意字符,则方法返回。返回值为用户键入字符。
     * @author shkstart
     * @date 2019年2月12日上午12:03:30
     * @return
     */
	public static char readMenuSelection() {
        char c;
        for (; ; ) {
            String str = readKeyBoard(1, false);
            c = str.charAt(0);
            if (c != '1' && c != '2' &&
                c != '3' && c != '4') {
                System.out.print("选择错误,请重新输入:");
            } else break;
        }
        return c;
    }
	/**
	 * 
	 * @Description 该方法提示并等待,直到用户按回车键后返回。
	 * @author shkstart
	 * @date 2019年2月12日上午12:03:50
	 */
    public static void readReturn() {
        System.out.print("按回车键继续...");
        readKeyBoard(100, true);
    }
    /**
     * 
     * @Description 该方法从键盘读取一个长度不超过2位的整数,并将其作为方法的返回值。
     * @author shkstart
     * @date 2019年2月12日上午12:04:04
     * @return
     */
    public static int readInt() {
        int n;
        for (; ; ) {
            String str = readKeyBoard(2, false);
            try {
                n = Integer.parseInt(str);
                break;
            } catch (NumberFormatException e) {
                System.out.print("数字输入错误,请重新输入:");
            }
        }
        return n;
    }
    /**
     * 
     * @Description 从键盘读取‘Y’或’N’,并将其作为方法的返回值。
     * @author shkstart
     * @date 2019年2月12日上午12:04:45
     * @return
     */
    public static char readConfirmSelection() {
        char c;
        for (; ; ) {
            String str = readKeyBoard(1, false).toUpperCase();
            c = str.charAt(0);
            if (c == 'Y' || c == 'N') {
                break;
            } else {
                System.out.print("选择错误,请重新输入:");
            }
        }
        return c;
    }

    private static String readKeyBoard(int limit, boolean blankReturn) {
        String line = "";

        while (scanner.hasNextLine()) {
            line = scanner.nextLine();
            if (line.length() == 0) {
                if (blankReturn) return line;
                else continue;
            }

            if (line.length() < 1 || line.length() > limit) {
                System.out.print("输入长度(不大于" + limit + ")错误,请重新输入:");
                continue;
            }
            break;
        }

        return line;
    }
}

Euqipment接口及其实现子类的设计

package kx.domain;
/** 
* @Description 
* @author 作者 KX
* @version 
* @date 创建时间:2020年10月27日 下午2:00:50 

*/
public interface Equipment {
	public String getDescription();
}

 

package kx.domain;
/** 
* @Description 
* @author 作者 KX
* @version 
* @date 创建时间:2020年10月27日 下午2:03:06 

*/
public class NoteBook implements Equipment{
	private String model;
	private double price;
	public String getModel() {
		return model;
	}
	public void setModel(String model) {
		this.model = model;
	}
	public double getPrice() {
		return price;
	}
	public void setPrice(double price) {
		this.price = price;
	}
	public NoteBook(String model, double price) {
		super();
		this.model = model;
		this.price = price;
	}
	public NoteBook() {
		super();
	}
	@Override
	public String getDescription() {
		return model + "(" + price + ")";
	}
	
	
}
package kx.domain;
/** 
* @Description String model,display;
* @author 作者 KX
* @version 
* @date 创建时间:2020年10月27日 下午2:10:17 

*/
public class PC implements Equipment{
	private String model,display;

	public String getModel() {
		return model;
	}

	public void setModel(String model) {
		this.model = model;
	}

	public String getDisplay() {
		return display;
	}

	public void setDisplay(String display) {
		this.display = display;
	}

	public PC() {
		super();
	}

	public PC(String model, String display) {
		super();
		this.model = model;
		this.display = display;
	}

	@Override
	public String getDescription() {
		return model + "(" + display + ")";
	}
	
}
package kx.domain;
/** 
* @Description 
* @author 作者 KX
* @version 
* @date 创建时间:2020年10月27日 下午2:08:03 

*/
public class Printer implements Equipment{
	private String name,type;
	
	public Printer() {
		super();
	}

	public Printer(String name, String type) {
		super();
		this.name = name;
		this.type = type;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getType() {
		return 
  • 32
    点赞
  • 87
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值