Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Message {
- // the properties of a message
- private String sender;
- private String receiver;
- private String subject;
- private String body;
- // all property values are known at creation of the message; so initialize
- public Message (String s, String r, String sub, String b)
- {
- sender = s;
- receiver = r;
- subject = sub;
- body = b;
- }
- // any nice format of printing the names and the values of the properties will do
- public void printMsg()
- {
- System.out.println("Sender: " + sender);
- System.out.println("Receiver: " + receiver);
- System.out.println("Subject: " + subject);
- System.out.println("Message: " + body);
- }
- // what follows are basic getter methods
- public String getSender()
- {
- return sender;
- }
- public String getReceiver()
- {
- return receiver;
- }
- public String getSubject()
- {
- return subject;
- }
- public String getBody()
- {
- return body;
- }
- }
- import java.util.ArrayList;
- public class Userlist
- {
- private ArrayList<User> users;
- private int numUsers;
- public Userlist()
- {
- users = new ArrayList<User>();
- }
- public User findUser(String username)
- {
- for (User i : users)
- {
- if (i.userName.equals(username))
- return i;
- }
- return null;
- }
- public void addUser(User u)
- {
- if (findUser(u.userName) != null)
- System.out.println("User already exists");
- else
- {
- users.add(u);
- numUsers++;
- }
- }
- public int getNumUsers()
- {
- return this.numUsers;
- }
- public User getUser(int i)
- {
- if (i>=users.length)
- return null;
- else
- return users.get(i-1);
- }
- }
- public class UserList implements Serializable
- {
- }
- public class Message implements Serializable
- {
- }
- FileOutputStream fos = new FileOutputStream(filename);
- ObjectOutputStream out = new ObjectOutputStream(fos);
- UserList userList ; // assume this is the object to be serialized
- out.writeObject(userList); // serializes the object
- FileInputStream fis = new FileInputStream(filename);
- ObjectInputStream in = new ObjectInputStream(fis);
- userList = (UserList) in.readObject();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement