7-1 把大象装进冰箱(继承) (100 分)
把大象装入冰箱(继承).docx
输入格式:
Put the 动物类名 动物名字 into the 电器类名 电器名字。例如:Put the Lion Jack into the Microvate Robert。
输出格式:
create 电器类名 电器名字 create 动物类名 动物名字 电器类名 电器名字 is open 动物类名 动物名字 is in 电器类名 电器名字 电器类名 电器名字 is close
输入样例:
在这里给出一组输入。例如:
Put the Lion Jack into the Microwave Robert
输出样例:
在这里给出相应的输出。例如:
create Microwave Robert
create Lion Jack
Microwave Robert is open
Lion Jack is in Microwave Robert
Microwave Robert is close
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class Main {
public static void main(String[] args) {
//Scannner input = new Scanner(System.in);
Scanner input = new Scanner(System.in);
String temp = input.nextLine();
String regex = "Put\\s+the\\s+(\\w+)\\s+(\\w+)\\s+into\\s+the\\s+(\\w+)\\s+(\\w+)";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(temp);
if(matcher.find()) {
String animalClass = matcher.group(1);//动物
String animalName = matcher.group(2);//动物名字
String electricClass = matcher.group(3)