本文主要是介绍【java】兴唐第二十五节课小程序学生卡转账小系统(自己写的异常),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1、StuCard.java
public class StuCard {public static void TransMoney(int source, int money, int target) {money -= target;if(money < 0) {throw new NotEnoughMoneyException("余额不足");}System.out.println("商家的余额为:" + source);System.out.println("学生的余额为:" + money);}public static void main(String[] args) {try {TransMoney(500, 20, 21);}catch(RuntimeException e){e.printStackTrace();}}}
2、NotEoughMoneyException.java
public class NotEnoughMoneyException extends RuntimeException{public NotEnoughMoneyException() {super();// TODO Auto-generated constructor stub}public NotEnoughMoneyException(String message, Throwable cause, boolean enableSuppression,boolean writableStackTrace) {super(message, cause, enableSuppression, writableStackTrace);// TODO Auto-generated constructor stub}public NotEnoughMoneyException(String message, Throwable cause) {super(message, cause);// TODO Auto-generated constructor stub}public NotEnoughMoneyException(String message) {super(message);// TODO Auto-generated constructor stub}public NotEnoughMoneyException(Throwable cause) {super(cause);// TODO Auto-generated constructor stub}}
这篇关于【java】兴唐第二十五节课小程序学生卡转账小系统(自己写的异常)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!