2019.12.17 object-oriented exercises

/**
* TimeTraveler.java
* com.DuiXiang
*
* Function: TODO
*
* ver date author
* ──────────────────────────────────
* 2019年12月17日 17671
*
* Copyright (c) 2019, TNT All Rights Reserved.
*/

package com.DuiXiang;

/**
* ClassName:TimeTraveler Function: TODO ADD FUNCTION Reason: TODO ADD REASON
*
* @author 17671
* @version
* @since Ver 1.1
* @Date 2019年12月17日 下午4:25:49
*
* @see
*/
public class TimeTraveler {
public String[][] times = new String[5][2];

// 添加事件
public void add(String time, String event) {
boolean full = false;
for (int i = 0; i < times.length; i++) {
if (times[i][0] == null) {
times[i][0] = time;
times[i][1] = event;
full = false;
break;
}
}
if (full) {
System.out.println("数组已满");
} else {
System.out.println("添加成功!");
}
}

// modify events
public void Update (Time String, String Event) {
Boolean = Find to false;
for (int I = 0; I <times.length; I ++) {
IF (! Times [I] [0] = null) {
IF (Times [I] [0] .equals (Time)) {
Times [I] [. 1] = Event;
Find = to true;
System.out.println ( "modified successfully");
}
}
}
IF (Find!) {
System.out.println ( "no data to find the location!");
}
}

// 展示事件
public void show() {
for (int i = 0; i < times.length - 1; i++) {
for (int j = 0; j < times.length - i - 1; j++) {
if (times[j][0] != null && times[j + 1][0] != null) {
if (Integer.parseInt(times[j][0]) > Integer.parseInt(times[j + 1][0])) {
String[] temp = times[j];
times[j] = times[j + 1];
times[j + 1] = temp;
}
}
}
}
System.out.println("时间\t\t\t 事件");
for (int i = 0; i < times.length; i++) {

IF (Times [I] [0] == null) {
System.out.println ( "no data the position");
} {the else
of System.out.print (Times [I] [0] + "\ T \ T "+ times [i] [1 ]);

}
System.out.println();
}
System.out.println("**********************************");
}
}

************************************************************************************************************************************************************************************************************

/**
* Test12.java
* com.DuiXiang
*
* Function: TODO
*
* ver date author
* ──────────────────────────────────
* 2019年12月17日 17671
*
* Copyright (c) 2019, TNT All Rights Reserved.
*/

package com.DuiXiang;

import java.util.Scanner;

/ **
* ClassName: TEST12
* Function: TODO the ADD FUNCTION
* Reason: TODO the ADD REASON
*
* @author 17671
* @version
* @Since Ver 1.1
* 2019 Nian 12 @date 4:49:17 afternoon of May 17
*
* @ See
* /
public class TEST12 {
public static new new TimeTraveler TimeTraveler T1 = ();
public static Scanner Scanner Scanner new new = (the System.in);
public static void main (String [] args) {
MENU ();
}
public static void MENU () {
Boolean = In Flag to true;
the while (In Flag) {
System.out.println ( "add time and events. 1.");
System.out.println ( "2 modification time and events.");
System.out.println ( "3 shows time and event");
System.out.println (. "4 exit");
System.out.println ( "Please choose:");
String = scanner.nextLine Choice ();

Switch (Choice) {
Case ". 1":
// System.out.println ( "Please input time:");
// Time = scanner.nextLine String ();
// System.out.println ( "Please enter the event:");
// String = scanner.nextLine event ();
// t1.add (Time, event);
System.out .println ( "follow the format time (20,191,217); event input data:");
String data scanner.nextLine = ();
String [] = data.split TEMP ( ";");
t1.add (TEMP [0] , TEMP [. 1]);
BREAK;
Case "2":
System.out.println ( "Please enter an update time:");
String scanner.nextLine TIME1 = ();
System.out.println ( "Please enter modified event: ");
String EVENT1 = scanner.nextLine ();
T1.update(time1, event1);
break;
Case "3":
t1.show ();
BREAK;
Case "4":
Flag = false;
System.out.println ( "Welcome to next time through!");
BREAK;

default:
System.out.println ( "! invalid command, please re-enter");
BREAK;
}
}
}

}

Guess you like

Origin www.cnblogs.com/aojie/p/12055838.html