Devoloping Java applications using the JCF(Java Collections Framework) Design a
ID: 3548559 • Letter: D
Question
Devoloping Java applications using the JCF(Java Collections Framework)
Design a java application that maintains the data fo a simple social network. Each person in the network should have a profile that contains at least the persons name, current status, and a list of friends. Your application should allow a user to join the network, leave the network, create a profile, modify the profile, search for other profiles, and add friends.
Please note that the social network and the list of friends for each person are to be collections from the JCF, and that the entire application is to be written in a single .java file. Testing should show at least 6 people joining the network, and demonstrate each of the user options above.
Explanation / Answer
//Social NetWork
class Stack
{
private char[] list; //array to store the stack items
private int size; //size of the array
private int n; //number of items in the stack
// Creates an empty stack with an array size of 100.
public Stack()
{
size = 100;
list = new char[size];
n = 0;
}
// Creates an empty stack using the array size passed as a parameter.
public Stack(int s)
{
size = s;
list = new char[size];
n = 0;
}
// Adds an element c to the top of the stack.
public void push(char c)
{
if (n < size)
{
list[n] = c;
n++;
}
else
{
System.out.println("Error push");
}
}
// Removes and discards the element at the top of the stack.
public void pop()
{
if(n > 0)
{
n--;
}
else
{
System.out.println("Error pop");
}
}
// Returns the element at the top of the stack, but does not remove it.
public char peek()
{
if(n > 0)
{
return list[n - 1];
}
else
{
System.out.println("Error peek");
return ' ';
}
}
// Determines whether the stack is empty.
public boolean isEmpty()
{
return n == 0;
}
// Clears the stack
public void clear()
{
n = 0;
}
}
public class Lab3A
{
// Demo Program for class Stack
public static void main(String[] args)
{
Stack s = new Stack();
// Create new stack to store items and display in the same order
Stack t = new Stack();
System.out.println("Insertion of 10 characters in s");
for (int i = 0; i < 10; i++)
{
int x = 32 + (int) (Math.random() * 95);
System.out.println(x + " --> " + (char) x);
s.push((char) x);
}
System.out.println(" Displaying and deleting elements");
for (int i = 0; i < 10; i++)
{
System.out.println("Item at the top: " + s.peek());
t.push(s.peek());
s.pop();
}
System.out.println(" ");
for (int i = 0; i < 10; i++)
{
System.out.println("Display Original Order:" + t.peek());
s.push(t.peek());
t.pop();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.