在Java中如何跟踪会议管理项目的管理时间? [英] How to track time with management of items for conference management in java?

查看:150
本文介绍了在Java中如何跟踪会议管理项目的管理时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个从文件中提取信息的程序,我需要跟踪这个问题的时间,并为相同的



代码设置会议日程:

  package org.example; 

import java.io. *;
import java.util。*;

public class Test {
public static void main(String [] args){
try {
//打开第一个命令行参数
FileInputStream fstream = new FileInputStream(C:\\test.txt);

//获取DataInputStream的对象
DataInputStream in = new DataInputStream(fstream);

BufferedReader br = new BufferedReader(new InputStreamReader(in));
字符串定时器,strLine;
StringBuffer inputText = new StringBuffer();
StringBuffer timeFrames = new StringBuffer();
映射< String,String> mapper = new LinkedHashMap< String,String>();

//读取文件行按行
while((strLine = br.readLine())!= null){
inputText.append(strLine +\\\
) ;
if(lightning.equalsIgnoreCase(strLine.substring(strLine.lastIndexOf()+1))){
timeFrames.append(5min\\\
);
timer =5min;
} else {
timeFrames.append(strLine.substring(strLine.lastIndexOf()+1)+\\\
);
timer = strLine.substring(strLine.lastIndexOf()+1);
}
mapper.put(strLine,timer);
}

System.out.println(Input Text:);
System.out.println(inputText);

System.out.println(Time Frames);
System.out.println(timeFrames);

for(Map.Entry< String,String> entry:mapper.entrySet()){
System.out.println(entry.getValue()++ entry.getKey ));
}

//关闭输入流
in.close();
} catch(Exception e){//如果有任何
Catch exception System.err.println(Error:+ e.getMessage());
}
}

}

txt:

 编写针对企业路径的快速测试60分钟
在Python中超过45分钟
Lua for the Masses 30分钟
不匹配的宝石版本的Ruby错误45分钟
普通的Ruby错误45分钟
Python开发人员闪电
沟通超过60分钟
会计驱动开发45分钟
Woah 30分钟
坐下来写30分钟
配对编程vs噪音45分钟
Rails魔术60分钟
Ruby on Rails:为什么我们应该在60分钟内移动
Clojure Ate Scala我的项目)45分钟
西雅图Boondocks的编程30分钟
Ruby与Clojure的后端开发30分钟
Ruby on Rails旧版应用程序维护60分钟
没有HackerNews的世界30分钟
用户界面Rails中的CSS应用程序30分钟

我需要执行计算并设置此项目的时间表,创造一个完美的confe



会议始于09:00AN - 01-00;午餐时间 - 01:00 - 02:00,下半场是02:00 -05:00



任何想法都非常感谢,并提前感谢

加油!

解决方案

以下是我的会议跟踪管理程序的代码。我保持GUI代码远离逻辑。他们都在不同的班级。程序所做的唯一假设是,您提供一些适当的输入,可以按照提供的规则将其隔离到适当的轨道。

  import java.awt.BorderLayout; 
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;

public abstract class CommonInterface {
protected CommonInterface(final String title){
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run(){
makeGUI(title);
showGUI();
}
});
}

保护JFrame框架;
protected JTextArea textArea;
保护JButton按钮
保护JLabel标签;

protected String originalInputText,inputText,outputText =;

protected void makeGUI(final String title){
frame = new JFrame(title +:By Aman Agnihotri);
textArea = new JTextArea(30,40);
button = new JButton(Compute);
label = new JLabel(Test Input:);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setBorder(new EmptyBorder(5,5,2,5));
panel.add(label,BorderLayout.WEST);
panel.add(button,BorderLayout.EAST);

JScrollPane scrollPane = new JScrollPane(textArea);
scrollPane.setBorder(new EmptyBorder(2,5,5,5));

frame.add(panel,BorderLayout.NORTH);
frame.add(scrollPane,BorderLayout.CENTER);

frame.pack();
。frame.setMinimumSize(frame.getSize());
frame.setLocationRelativeTo(null);

button.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
if(button.getText()。equals计算)){
refresh();
computeOutput();
button.setText(Back);
label.setText(Test Output:);
textArea.setText(outputText);
} else {
button.setText(Compute);
label.setText(Test Input:);
textArea .setText(originalInputText);
}
}
});
}

protected abstract void refresh();

protected abstract void computeOutput();

protected void showGUI(){
frame.setVisible(true);
}
}

public class ConferenceTrackManagement extends CommonInterface {

private String [] eventArray;
private int [] timeArray;

private boolean isOutputInvalid;

private final int MAX_TRACK_TIME = 420; // 1 Track Max Time = 420 minutes。

public ConferenceTrackManagement(){
super(会议轨道管理);
}

@Override
protected void refresh(){
isOutputInvalid = false;
outputText =;
}

@Override
protected void computeOutput(){
originalInputText = textArea.getText();
inputText = originalInputText;

computeEventAndTimeArray();

if(!isOutputInvalid){
computeTracks();
}
}

private int startIndex = -1,endIndex = -1,time;

private void computeTracks(){
int totalTime = getTotalTime();
int requiredTracks = totalTime / MAX_TRACK_TIME + 1;
sortEventAndTimeArray(); (int i = 1; i< = requiredTracks; i ++){
boolean found = exactSubArraySum(timeArray,180);

//上午时间

if(found){
time = 9 * 60; //从上午9点开始[9 * 60以分钟为单位]
outputText + =Track+ i +:\\\
\\\
;
for(int j = startIndex; j< = endIndex; j ++){
outputText + = timeStamp(time,AM)++ eventArray [j]
+ \\ n;
time + = timeArray [j];
}

deleteProperElements();
outputText + =12:00 PM Lunch\\\
;

boolean relativeFound = relativeSubArraySum(timeArray,180,240);

if(relativeFound){
time = 60; //从下午1点开始[1 * 60以分钟为单位]
outputText + =\\\
;
for(int j = startIndex; j< = endIndex; j ++){
outputText + = timeStamp(time,PM)+
+ eventArray [j] + \\ n;
time + = timeArray [j];
}

deleteProperElements();
outputText + = timeStamp(time,PM)+Networking Event
+\\\
;
outputText + =\\\
\\\
;
}
} else
outputText =找不到正确的解决方案。
}
}

private String timeStamp(int time,String mode){
String timeStamp =;

int hours = time / 60;
int minutes = time%60;

String hourHint =,minuteHint =;
if(hours< 10)
hourHint =0;
if(minutes< 10)
minuteHint =0;
timeStamp = hourHint +小时+:+分钟提示+分钟+模式;

return timeStamp;
}

private void deleteProperElements(){
String [] tempEventArray = new String [eventArray.length
- (endIndex - startIndex) - 1];
int [] tempTimeArray = new int [tempEventArray.length];

int index = 0; (int j = 0; j< startIndex; j ++)
{
tempEventArray [index] = eventArray [j];
tempTimeArray [index] = timeArray [j];
index ++;
}
for(int j = endIndex + 1; j< eventArray.length; j ++){
tempEventArray [index] = eventArray [j];
tempTimeArray [index] = timeArray [j];
index ++;
}

timeArray = tempTimeArray;
eventArray = tempEventArray;
}

private boolean exactSubArraySum(int array [],int sum){
if(!(array.length> = 1))
return false;
int currentSum = array [0],start = 0; (int i = 1; i <= array.length; i ++){
while(currentSum> sum&& start< i - 1){
currentSum - = array [start];
start ++;
}

if(currentSum == sum){
startIndex = start;
endIndex = i - 1;
返回true;
}

if(i< array.length)
currentSum + = array [i];
}

return false; //找不到子数组。
}

private boolean relativeSubArraySum(int array [],int minimumSum,
int maximumSum){
if(!(array.length> = 1))
返回false;
int currentSum = array [0],start = 0; (int i = 1; i <= array.length; i ++){
while(currentSum> maximumSum&& start< i - 1){
currentSum - = array [start];
start ++;
}

if(currentSum> = minimumSum&& currentSum< = maximumSum){
startIndex = start;
endIndex = i - 1;
返回true;
}

if(i< array.length)
currentSum + = array [i];
}

return false; //找不到子数组。
}

private void sortEventAndTimeArray(){
for(int i = 1; i< timeArray.length; i ++){
for(int j = 0 ; j< timeArray.length - i; j ++){
if(timeArray [j]> timeArray [j + 1]){
int tempTime = timeArray [j];
timeArray [j] = timeArray [j + 1];
timeArray [j + 1] = tempTime;

String tempEvent = eventArray [j];
eventArray [j] = eventArray [j + 1];
eventArray [j + 1] = tempEvent;
}
}
}
}

private int getTotalTime(){
int timeSum = 0; (int i = 0; i< timeArray.length; i ++)
timeSum + = timeArray [i];

return timeSum;
}

private void computeEventAndTimeArray(){
String lines [] = inputText.split([\\\\\\\]

eventArray = new String [lines.length];
timeArray = new int [lines.length]; (int i = 0; i< lines.length; i ++){
String line = lines [i];


line = line.trim();

int lastIndexOfSpace = line.lastIndexOf('');

eventArray [i] = line.substring(0,lastIndexOfSpace);
String currentTime = line.substring(lastIndexOfSpace + 1);

currentTime = currentTime.toLowerCase();
if(currentTime.endsWith(lightning))
setEventAndTimeFor(i,currentTime,lightning,5);
else if(currentTime.endsWith(min))
setEventAndTimeFor(i,currentTime,min,1);
else {
setOutputAsInvalid(i);
}
}
}

private void setEventAndTimeFor(int i,String currentTime,String type,
int scale){
String timeValue = currentTime.substring(0,currentTime.indexOf(type));

if(timeValue.equals())
timeArray [i] = scale;
else {
try {
timeArray [i] = Integer.parseInt(timeValue)* scale;
} catch(Exception e){
setOutputAsInvalid(i);
}
}
}

private void setOutputAsInvalid(int lineNumber){
outputText + =Invalid Time Entry in line+(lineNumber + 1 )+\\\
;
isOutputInvalid = true;
}

public static void main(String args []){
new ConferenceTrackManagement();
}
}


I had written a program for extracting information from a file and i need to track up time in this problem and set up a conference schedule for the same

Code:

package org.example;

import java.io.*;
import java.util.*;

public class Test {
    public static void main(String[] args) {
        try{
              // Open the file that is the first command line parameter
              FileInputStream fstream = new FileInputStream("C:\\test.txt");

              // Get the object of DataInputStream
              DataInputStream in = new DataInputStream(fstream);

              BufferedReader br = new BufferedReader(new InputStreamReader(in));
              String timer, strLine;
              StringBuffer inputText = new StringBuffer();
              StringBuffer timeFrames = new StringBuffer();
              Map<String, String> mapper = new LinkedHashMap<String, String>();

              //Read File Line By Line
              while ((strLine = br.readLine()) != null)   {
                  inputText.append(strLine+"\n");  
                  if("lightning".equalsIgnoreCase(strLine.substring(strLine.lastIndexOf(" ")+1))){
                      timeFrames.append("5min\n");
                      timer = "5min";
                  }else{
                      timeFrames.append(strLine.substring(strLine.lastIndexOf(" ")+1)+"\n");
                      timer = strLine.substring(strLine.lastIndexOf(" ")+1);
                  }
                  mapper.put(strLine, timer);
              }

              System.out.println("Input Text:");
              System.out.println(inputText);

              System.out.println("Time Frames");
              System.out.println(timeFrames);

              for (Map.Entry<String, String> entry : mapper.entrySet()) {
                    System.out.println(entry.getValue()+" "+entry.getKey());
              }

              //Close the input stream
              in.close();
                }catch (Exception e){//Catch exception if any
              System.err.println("Error: " + e.getMessage());
              }
    }

}

test.txt:

Writing Fast Tests Against Enterprise Rails 60min
Overdoing it in Python 45min
Lua for the Masses 30min
Ruby Errors from Mismatched Gem Versions 45min
Common Ruby Errors 45min
Rails for Python Developers lightning
Communicating Over Distance 60min
Accounting-Driven Development 45min
Woah 30min
Sit Down and Write 30min
Pair Programming vs Noise 45min
Rails Magic 60min
Ruby on Rails: Why We Should Move On 60min
Clojure Ate Scala (on my project) 45min
Programming in the Boondocks of Seattle 30min
Ruby vs. Clojure for Back-End Development 30min
Ruby on Rails Legacy App Maintenance 60min
A World Without HackerNews 30min
User Interface CSS in Rails Apps 30min

I need to perform calculations and set this items on track of a schedule to create a perfect conference.

The conference is starting from 09:00AN - 01-00; Lunch time - 01:00 - 02:00, second half is from 02:00 -05:00

Any ideas is well appreciated and thanks in advance

Cheers!!!

解决方案

So following is my code for the ConferenceTrackManagement program. I kept the GUI code away from the logic. They both are in different classes. The only assumption my program makes is that you provide it with some proper input which can be segregated into proper tracks while following the rules which are provided.

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;

public abstract class CommonInterface {
    protected CommonInterface(final String title) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                makeGUI(title);
                showGUI();
            }
        });
    }

    protected JFrame frame;
    protected JTextArea textArea;
    protected JButton button;
    protected JLabel label;

    protected String originalInputText, inputText, outputText = "";

    protected void makeGUI(final String title) {
        frame = new JFrame(title + " : By Aman Agnihotri");
        textArea = new JTextArea(30, 40);
        button = new JButton("Compute");
        label = new JLabel("Test Input:");

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        panel.setBorder(new EmptyBorder(5, 5, 2, 5));
        panel.add(label, BorderLayout.WEST);
        panel.add(button, BorderLayout.EAST);

        JScrollPane scrollPane = new JScrollPane(textArea);
        scrollPane.setBorder(new EmptyBorder(2, 5, 5, 5));

        frame.add(panel, BorderLayout.NORTH);
        frame.add(scrollPane, BorderLayout.CENTER);

        frame.pack();
        frame.setMinimumSize(frame.getSize());
        frame.setLocationRelativeTo(null);

        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (button.getText().equals("Compute")) {
                    refresh();
                    computeOutput();
                    button.setText("Back");
                    label.setText("Test Output:");
                    textArea.setText(outputText);
                } else {
                    button.setText("Compute");
                    label.setText("Test Input:");
                    textArea.setText(originalInputText);
                }
            }
        });
    }

    protected abstract void refresh();

    protected abstract void computeOutput();

    protected void showGUI() {
        frame.setVisible(true);
    }
}

public class ConferenceTrackManagement extends CommonInterface {

private String[] eventArray;
private int[] timeArray;

private boolean isOutputInvalid;

private final int MAX_TRACK_TIME = 420; // 1 Track Max Time = 420 minutes.

public ConferenceTrackManagement() {
    super("Conference Track Management");
}

@Override
protected void refresh() {
    isOutputInvalid = false;
    outputText = "";
}

@Override
protected void computeOutput() {
    originalInputText = textArea.getText();
    inputText = originalInputText;

    computeEventAndTimeArray();

    if (!isOutputInvalid) {
        computeTracks();
    }
}

private int startIndex = -1, endIndex = -1, time;

private void computeTracks() {
    int totalTime = getTotalTime();
    int requiredTracks = totalTime / MAX_TRACK_TIME + 1;
    sortEventAndTimeArray();

    for (int i = 1; i <= requiredTracks; i++) {
        boolean found = exactSubArraySum(timeArray, 180); // morning time

        if (found) {
            time = 9 * 60; // starts at 9 am [9 * 60 is in minutes]
            outputText += "Track " + i + ":\n\n";
            for (int j = startIndex; j <= endIndex; j++) {
                outputText += timeStamp(time, "AM") + " " + eventArray[j]
                        + "\n";
                time += timeArray[j];
            }

            deleteProperElements();
            outputText += "12:00PM Lunch\n";

            boolean relativeFound = relativeSubArraySum(timeArray, 180, 240);

            if (relativeFound) {
                time = 60; // starts at 1 pm [1 * 60 is in minutes]
                outputText += "\n";
                for (int j = startIndex; j <= endIndex; j++) {
                    outputText += timeStamp(time, "PM") + " "
                            + eventArray[j] + "\n";
                    time += timeArray[j];
                }

                deleteProperElements();
                outputText += timeStamp(time, "PM") + " Networking Event"
                        + "\n";
                outputText += "\n\n";
            }
        } else
            outputText = "No proper solution found.";
    }
}

private String timeStamp(int time, String mode) {
    String timeStamp = "";

    int hours = time / 60;
    int minutes = time % 60;

    String hourHint = "", minuteHint = "";
    if (hours < 10)
        hourHint = "0";
    if (minutes < 10)
        minuteHint = "0";
    timeStamp = hourHint + hours + ":" + minuteHint + minutes + mode;

    return timeStamp;
}

private void deleteProperElements() {
    String[] tempEventArray = new String[eventArray.length
            - (endIndex - startIndex) - 1];
    int[] tempTimeArray = new int[tempEventArray.length];

    int index = 0;
    for (int j = 0; j < startIndex; j++) {
        tempEventArray[index] = eventArray[j];
        tempTimeArray[index] = timeArray[j];
        index++;
    }
    for (int j = endIndex + 1; j < eventArray.length; j++) {
        tempEventArray[index] = eventArray[j];
        tempTimeArray[index] = timeArray[j];
        index++;
    }

    timeArray = tempTimeArray;
    eventArray = tempEventArray;
}

private boolean exactSubArraySum(int array[], int sum) {
    if (!(array.length >= 1))
        return false;
    int currentSum = array[0], start = 0;

    for (int i = 1; i <= array.length; i++) {
        while (currentSum > sum && start < i - 1) {
            currentSum -= array[start];
            start++;
        }

        if (currentSum == sum) {
            startIndex = start;
            endIndex = i - 1;
            return true;
        }

        if (i < array.length)
            currentSum += array[i];
    }

    return false; // No sub array found.
}

private boolean relativeSubArraySum(int array[], int minimumSum,
        int maximumSum) {
    if (!(array.length >= 1))
        return false;
    int currentSum = array[0], start = 0;

    for (int i = 1; i <= array.length; i++) {
        while (currentSum > maximumSum && start < i - 1) {
            currentSum -= array[start];
            start++;
        }

        if (currentSum >= minimumSum && currentSum <= maximumSum) {
            startIndex = start;
            endIndex = i - 1;
            return true;
        }

        if (i < array.length)
            currentSum += array[i];
    }

    return false; // No sub array found.
}

private void sortEventAndTimeArray() {
    for (int i = 1; i < timeArray.length; i++) {
        for (int j = 0; j < timeArray.length - i; j++) {
            if (timeArray[j] > timeArray[j + 1]) {
                int tempTime = timeArray[j];
                timeArray[j] = timeArray[j + 1];
                timeArray[j + 1] = tempTime;

                String tempEvent = eventArray[j];
                eventArray[j] = eventArray[j + 1];
                eventArray[j + 1] = tempEvent;
            }
        }
    }
}

private int getTotalTime() {
    int timeSum = 0;
    for (int i = 0; i < timeArray.length; i++)
        timeSum += timeArray[i];
    return timeSum;
}

private void computeEventAndTimeArray() {
    String lines[] = inputText.split("[\\r\\n]+");

    eventArray = new String[lines.length];
    timeArray = new int[lines.length];

    for (int i = 0; i < lines.length; i++) {
        String line = lines[i];
        line = line.trim();

        int lastIndexOfSpace = line.lastIndexOf(' ');

        eventArray[i] = line.substring(0, lastIndexOfSpace);
        String currentTime = line.substring(lastIndexOfSpace + 1);

        currentTime = currentTime.toLowerCase();
        if (currentTime.endsWith("lightning"))
            setEventAndTimeFor(i, currentTime, "lightning", 5);
        else if (currentTime.endsWith("min"))
            setEventAndTimeFor(i, currentTime, "min", 1);
        else {
            setOutputAsInvalid(i);
        }
    }
}

private void setEventAndTimeFor(int i, String currentTime, String type,
        int scale) {
    String timeValue = currentTime.substring(0, currentTime.indexOf(type));

    if (timeValue.equals(""))
        timeArray[i] = scale;
    else {
        try {
            timeArray[i] = Integer.parseInt(timeValue) * scale;
        } catch (Exception e) {
            setOutputAsInvalid(i);
        }
    }
}

private void setOutputAsInvalid(int lineNumber) {
    outputText += "Invalid Time Entry in line " + (lineNumber + 1) + "\n";
    isOutputInvalid = true;
}

public static void main(String args[]) {
    new ConferenceTrackManagement();
}
}

这篇关于在Java中如何跟踪会议管理项目的管理时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆