PIMCMD

This assignment involves the creation of simple Personal Information Management system that can deal with 4 kinds of items: todo items, notes, appointments and contacts. Each of these kinds of items is described in more detail below. The assignment requires that you create a class for each item type, and that each class extends an abstract base class provided for you. In addition to creating the four classes, you need to create a manager class that supports some simple text-based commands for creating and managing items.

Each of your 4 item type classes will be derived from the following abstract class:

public abstract class PIMEntity {
    String Priority; // every kind of item has a priority

    // default constructor sets priority to "normal"
    PIMEntity() {
        Priority = "normal";
    }

    // priority can be established via this constructor.
    PIMEntity(String priority) {
        Priority =  priority;
    }

    // accessor method for getting the priority string
    public String getPriority() {
        return Priority;
    }
    // method that changes the priority string
    public void setPriority(String p) {
        Priority = p;
    }

    // Each PIMEntity needs to be able to set all state information
    // (fields) from a single text string.
    abstract public void fromString(String s);

    // This is actually already defined by the super class
    // Object, but redefined here as abstract to make sure
    // that derived classes actually implement it
    abstract public String toString();
}

 

 

PIMTodo

Todo items must be PIMEntites defined in a class named PIMTodo. Each todo item must have a priority (a string), a date and a string that contains the actual text of the todo item.

PIMNote

Note items must be PIMEntites defined in a class named PIMNote. Each note item must have a priority (a string), and a string that contains the actual text of the note.

PIMAppointment

Appointment items must be PIMEntites defined in a class named PIMAppointment. Each appointment must have a priority (a string), a date and a description (a string).

PIMContact

Contact items must be PIMEntites defined in a class named PIMContact. Each contact item must have a priority (a string), and strings for each of the following: first name, last name, email address.

There is one additional requirement on the implementation of the 4 item classes listed above, the 2 classes that involve a date must share an interface that you define. You must formally create this interface and have both PIMAppointment and PIMTodo implement this interface.

PIMManager

You must also create a class named PIMManager that includes a main and provides some way of creating and managing items (from the terminal). You must support the following commands (functionality):

  • List: print a list of all PIM items
  • Create: add a new item
  • Save: save the entire list of items (HW3: simple version, just print out; complex version, to a file, should be finished after I/O topic, to database, can be finished after JDBC topic, to a remote server, can (optional) be after Networking topic. )
  • Load: read a list of items from a file

When creating a new item it is expected that the user must response to a sequence of prompts to enter the appropriate information (and even to indicate what kind of item is being created). Do this any way you want, just make sure that your system provides enough information (instructions) so that we can use your systems!

There is no required format for the user interface, anything that allows users to create, list, save and load is fine. Here is what it might look like (user input shown in red):

java PIMManager

Welcome to PIM.
---Enter a command (suported commands are List Create Save Load Quit)---
List
There are 0 items.
---Enter a command (suported commands are List Create Save Load Quit)---
Create
Enter an item type ( todo, note, contact or appointment )
todo
Enter date for todo item: 
04/20/2018
Enter todo text:
Submit java homework.
Enter todo priority:
urgent
---Enter a command (suported commands are List Create Save Load Quit)---
List
There are 1 items.
Item 1: TODO urgent 04/20/2018 Submit Java homework.
---Enter a command (suported commands are List Create Save Load Quit)---
Save
Items have been saved.
---Enter a command (suported commands are List Create Save Load Quit)---
Quit

 

 

Note that there is not a required Delete command. Feel free to use any data structure you want to hold a list of items, you are allowed to use a simple array with size 100 (you are not required to support lists of more than 100 items). Handling array bound exception is required.

We will talk about the various kinds of collection objects supported by java.util (but you don't need to use them for this assignment).

import java.util.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
class PIMTodo extends PIMEntity implements DATE{
    public String Priority;
    public String text;
    public Date date;
    PIMTodo(){
        //Priority="normal";
    }
    public String getPriority() {
        return this.Priority;
    }
    public void setPriotity(String p) {
        this.Priority=p;
    }
    public void setDate(String d) {
        this.fromString(d);
    }
    public void setText(String s) {
        this.text=s;
    }
    public void fromString(String str) {
         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); 
           Date date = null; 
           try { 
            date = format.parse(str); 
           } catch (ParseException e) { 
            e.printStackTrace(); 
           } 
           this.date=date;
    }
    public String toString() {
        String str="Item "+PIMManager.counts+": TODO"+" "+this.Priority+" "+this.date+" " +this.text;
        return str;
    }
}

import java.util.Date;
public class PIMNote extends PIMEntity implements DATE{
    String priority;
    Date date;
    String text;
    PIMNote(){
        Priority="normal";
    }
    public String getPriority() {
        return this.Priority;
    }
    public void setPriotity(String p) {
        this.Priority=p;
    }
    public void setDate(String d) {
        this.fromString(d);
    }
    public void setText(String s) {
        this.text=s;
    }
    public void fromString(String str) {
        
    }
    public String toString() {
        String str="Item "+PIMManager.counts+": Note"+" "+this.Priority+" "+this.date+" " +this.text;
        return str;
    }
}
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class PIMAppointment extends PIMEntity implements DATE{
    private String priority;
    private Date date;
    private String description;
    PIMAppointment(){
        Priority="normal";
    }
    public String getPriority() {
        return this.Priority;
    }
    public void setPriotity(String p) {
        this.Priority=p;
    }
    public void setDate(String d) {
        this.fromString(d);
    }
    public void setText(String s) {
        this.description=s;
    }
    public void fromString(String str) {
         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
           Date date = null; 
           try { 
            date = format.parse(str); 
           } catch (ParseException e) { 
            e.printStackTrace(); 
           } 
           this.date=date;
    }
    public String toString() {
        String str="Item "+PIMManager.counts+": APPointmnet"+" "+this.Priority+" "+this.date+" " +this.description;
        return str;
    }
}
import java.util.Date;
public class PIMContact extends PIMEntity{
    public String priority;
    private String firstname;
    private String lastname;
    private String emailaddress;
    public PIMContact() {
        priority="normal";
    }
    public void setFirstname(String s) {
        this.firstname=s;
    }
    public void setLastname(String s) {
        this.lastname=s;
    }
    public void setAddressmail(String s) {
        this.emailaddress=s;
    }
    public void setPriotity(String s) {
        this.priority=s;
    }
    public String getPriority() {
        return this.priority;
    }
    public String getFirstname() {
        return this.firstname;
    }
    public String getLastname() {
        return this.lastname;
        
    }
    public String getEmailAddress() {
        return this.emailaddress;
    }
    public void fromString(String s) {
        
    }
    public String toString() {
        String str="Item "+PIMManager.counts+":Contact"+" "+this.Priority+" "+this.firstname+" " +this.lastname+this.emailaddress;
        return str;
    }
}

import java.util.Scanner;
import java.util.Date; 
public class PIMManager {
    static int counts=0;
    static String[] List=new String[100];
    public static void main(String[] args) {
        System.out.println("Welcome to PIM.");
        while(true) {
            System.out.println("--Enter a command(suported commands are: List Create Sava Load Quit)");
            Scanner scan=new Scanner(System.in);
            String s1=scan.nextLine();
            switch(s1) {
            case "List":{
                System.out.println("There are "+counts+" items");
                for(int i=1;i<=counts;i++) {
                    if(counts==0) break;
                    System.out.println(List[i]);
                }
                break;
                
            }
            case "Save":{
                System.out.println("Item have been saved.");
                break;
                
            }
            case "Load":{
                //
                break;
            }
            case "Create":{
                System.out.println("Enter an item type(todo,note,contact or appointment )");
                String s2=scan.nextLine();
                switch(s2) {
                case "todo":{
                    PIMTodo todo1=new PIMTodo();
                    System.out.println("Enter date for todo item: ");
                    String s3=scan.nextLine();
                    //Date d1=StrToDate(s3);
                    todo1.fromString(s3);
                    //
                    System.out.println("Enter todo text: ");
                    String s4=scan.nextLine();
                    todo1.setText(s4);
                    System.out.println("Enter todo priority:");
                    String s5=scan.nextLine();
                    todo1.setPriotity(s5);
                    //System.out.println(todo1.toString());
                    counts++;
                    String r1=todo1.toString();
                    List[counts]=r1;
                    break;
                }
                case "note":{
                    PIMNote note=new PIMNote();
                    System.out.println("Enter date for note item: ");
                    String n1=scan.nextLine();
                    note.fromString(n1);
                    System.out.println("Enter note text: ");
                    String n2=scan.nextLine();
                    note.setText(n2);
                    System.out.println("Enter todo priority:");
                    String n3=scan.nextLine();
                    note.setPriotity(n3);
                    counts++;
                    String r2=note.toString();
                    List[counts]=r2;
                    break;
                }
                case "contact":{
                    PIMContact con=new PIMContact();
                    System.out.println("Enter Firstname for contact item: ");
                    String c1=scan.nextLine();
                    con.setFirstname(c1);
                    System.out.println("Enter Lastname for contact item: ");
                    String c2=scan.nextLine();
                    con.setLastname(c2);
                    System.out.println("Enter EmailAddress for contact item: ");
                    String c3=scan.nextLine();
                    con.setAddressmail(c3);
                    System.out.println("Enter todo priority:");
                    String c4=scan.nextLine();
                    con.setPriotity(c4);
                    counts++;
                    String r3=con.toString();
                    List[counts]=r3;
                    break;
                    
                }
                case "appointment":{
                    PIMAppointment app=new PIMAppointment();
                    System.out.println("Enter date for appointment item: ");
                    String a1=scan.nextLine();
                    app.fromString(a1);
                    System.out.println("Enter appointment description: ");
                    String a2=scan.nextLine();
                    app.setText(a2);
                    System.out.println("Enter appointment priority:");
                    String a3=scan.nextLine();
                    app.setPriotity(a3);
                    counts++;
                    String r4=app.toString();
                    List[counts]=r4;
                    break;
                }
                }
            }
            case "Quit":{
                break;
            }
            }
        }
    }
}


interface DATE{

    void setDate(String d);

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值