object oriented analysis and design I need a functional code in java including m
ID: 3792908 • Letter: O
Question
object oriented analysis and design
I need a functional code in java including main just to compile and run
Thanks
Find a plate with name Rose from a stack of ten plates Private stack plates;
Class ind_plate { string mark; …
}
Int i; While (i <= 10) Do {
i++; Ind_plate iplate; Iplate= pop (plates);
If (iplate.mark == “Rose”)
System.outr.println(“plate”+ i + has “Rose as its mark”, /n);
}
After finding the plate/s with “Rose” add a plate with “Mary” as the mark below the Rose Plate. And add a plate with “Ms” as the mark above the Rose Plate.
Explanation / Answer
public class ind_plate
{
private int maxSize;
private String[] stackPlate;
private int top;
//class constructor to load intial parameters
public ind_plate(int s)
{
maxSize = s;
stackPlate = new String[maxSize];
top = -1;
}
public void push(String j) {
stackPlate[++top] = j;
}
public void find(String k)
{
int match=0,shift2;
/////////////////////////code to place "Marry" after Rose plate/////////////////////////////////
for(int i=0;i<=top;i++)
{
if(stackPlate[i]=="Rose")
{
match=i;
for(int shift=top;shift>=match;shift--)
{
shift2=shift;
shift2++;
stackPlate[shift2]=stackPlate[shift];
}
break;
}
}
top++;
stackPlate[match]="Mary";
//////////////////////////////// code to place "Ms" befroe Rose plate//////////////////////////////////////////////
for(int i=0;i<=top;i++)
{
if(stackPlate[i]=="Rose")
{
match=i;
for(int shift=top;shift>match;shift--)
{
shift2=shift;
shift2++;
stackPlate[shift2]=stackPlate[shift];
}
break;
}
}
top++;
stackPlate[++match]="Ms";
/////////////////////////////////////////////////////////
}
//pop function to remove plate form stack
public String pop() {
return stackPlate[top--];
}
public String peek() {
return stackPlate[top];
}
//check stack is empty or not
public boolean isEmpty() {
return (top == -1);
}
//check stack is full or not
public boolean isFull() {
return (top == maxSize - 1);
}
public static void main(String[] args) {
ind_plate theStack = new ind_plate(10);
//push operation 3 times to insert data into stack
theStack.push("Lilly");
theStack.push("Rose");
theStack.push("Mandar");
//find function to find Rose in stack and place plates before ,after the Rose plate
theStack.find("Rose");
while (!theStack.isEmpty()) {
String value = theStack.pop();
System.out.print(value);
System.out.print(" ");
}
System.out.println("");
}
}
Output :
Mandar Ms Rose Mary Lilly
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.