Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8376939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:32:52+00:00 2026-06-09T15:32:52+00:00

package michael.week.pkg5; class Employee { String Fname ; String Lname; String PhoneNum; String Address;

  • 0
package michael.week.pkg5;

class Employee {
String Fname ;
        String Lname;
        String PhoneNum;
        String Address;
         void setFirst(String First){
             Fname = First ;
         }
         void setlast(String Last){
             Lname  = Last ;
         }
          void setAddress (String address){
             Address = address ;
         }
         void setPhone (String Phone){
             PhoneNum  = Phone ;
         }          
         void display (){
             System.out.println ("the Fist name is :"+ Fname + "  , the last name is :        " + Lname  + "  ,the address is : "+ Address+ "  ,the phone is : "+ PhoneNum);
         }
         }

    package michael.week.pkg5;

     import java.io.BufferedReader;
     import java.io.IOException;
      import java.io.InputStreamReader;





   public class MichaelWeek5 {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) throws IOException {
    class Stck {
    Employee stck [] = new Employee[10];
    int x ;
     void stck (){
        x= -1 ;
    }
    Employee push (Employee item){
        if (x == 9){
            System.out.println ("Stack is full");
        }else stck[++x] = item ;
        return stck[x];
    }
        Employee pop (){
        if (x <0){
            System.out.println (" Stack underflow");
           return stck [x];
        }else 
            return stck[x++];
    }
    }
    InputStreamReader inp = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(inp);
    String info2 = null ;
    Stck obj = new Stck();
    Employee obj2 = new Employee ();
    int w = -1 ;
    for (int r=1 ;r>0; ){
   System.out.println("please enter add  to add new employee");
   System.out.println("please enter pop to pop the last added employee");
   System.out.println("please enter exit to exit");
   String choice = br.readLine();
   if(choice.equals("add")){
       System.out.println(w);
       if (w >= 9){
           System.out.println("you reached the maxmum number !");
           continue  ;
       } 
       else {
           w++;
           obj.stck ();
       String info  ;
       System.out.println ("please enter Employee first name :");
       info = br.readLine();

       System.out.println ("please enter Employee last name name :");
       info = br.readLine();

       System.out.println ("please enter Employee address :");
       info = br.readLine();

       System.out.println ("please enter Employee phone number :");
       info = br.readLine();
       }
   } else if(choice.equals("pop")){
           obj.pop();
           w--;
   }else if(choice.equals("exit"))
           break ;
       else {System.out.println (choice + " is wrong choice !") ;
   }
    }

    } 

   }

Greetings,
i am new to java and i am working on this program……. i need to know how can i push the data to the stck ?
note : the push’s parameter is type employee, and Employee contains First , Last, Phone , and address. how i can push each of them ?
here is what i did , and my instructor refused it

package week.pkg5;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Week5 {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) throws IOException {
      class Employee {


     String [] Fname = new String [10];
        String[] Lname= new String [10];
        String[] PhoneNum= new String [10];
        String[] Address = new String [10];
        int x= -1 ;
         void increment(){
           x++;

        }
         void PushFirst(String First){
             Fname[x] = First ;
         }
         void Pushlast(String Last){
             Lname [x] = Last ;
         }
         void PushPhone (String Phone){
             PhoneNum [x] = Phone ;
             System.out.println ("the Fist name is :"+ Fname [x]+ "  , the last name is : " + Lname [x] + "  ,the address is : "+ Address[x] + "  ,the phone is : "+ PhoneNum[x]);
         }
         void PushAddress (String address){
             Address [x] = address ;
         }
         void pop (){
             if (x < 0){
                 System.out.println (" No Empolyee !");
             }
             else {

        System.out.println ("the Fist name is :"+ Fname [x]+ "  , the last name is : " + Lname [x] + "  ,the address is : "+ Address[x] + "  ,the phone is : "+ PhoneNum[x]);
        x--;
        }
}
 void display (){
    if (x < 0){
        System.out.println (" No Empolyee !");
    }
    else {
        for (int q = 0 ; q <=x ; q++){
        System.out.println ((q+1)+"- "+"the First name is :"+ Fname [q]+ "  , the last name is : " + Lname [q] + "  ,the address is : "+ Address[q] + "  ,the phone is : "+ PhoneNum[q]);
        }
    }
}
 }
 InputStreamReader inp = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(inp);
    Employee obj = new Employee();
    int w = -1 ;
    for (int r=1 ;r>0; ){
   System.out.println("please enter add  to add new employee");
   System.out.println("please enter display  to display all employees list");
   System.out.println("please enter pop to pop the last added employee");
   System.out.println("please enter exit to exit");
   String choice = br.readLine();

   if(choice.equals("add")){


       System.out.println(w);
       if (w >= 9){
           System.out.println("you reached the maxmum number !");
           continue  ;
       } 
       else {
           w++;
           obj.increment();
       String info  ;
       System.out.println ("please enter Employee first name :");
       info = br.readLine();
       obj.PushFirst(info);
       System.out.println ("please enter Employee last name name :");
       info = br.readLine();
       obj.Pushlast(info);
       System.out.println ("please enter Employee address :");
       info = br.readLine();
       obj.PushAddress(info);
       System.out.println ("please enter Employee phone number :");
       info = br.readLine();
       obj.PushPhone(info);}
   }  else if(choice.equals("display")){
           obj.display();
   } else if(choice.equals("pop")){
           obj.pop();
           w--;
   }else if(choice.equals("exit"))
           break ;
       else {System.out.println (choice + " is wrong choice !") ;
   }
    }

} 
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:32:53+00:00Added an answer on June 9, 2026 at 3:32 pm

    You would need to create a stack of employees and then you can push the whole employee object on to the stack.

    import java.util.Stack;
    ...
    Employee emp = new Employee();
    Stack<Employee> stack = new Stack<Employee>();
    stack.push(emp);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

package pack; public class sample{ public static void main(String input[]) { NumberFormat numberFormat =
package org.study.algos; public class Study { public static void main(String[] args) { A a
package GC; import java.util.Scanner; public class main { public static void main(String args[]) {
package com.test01; public class test01 { public static void main(String[] args) { System.out.println(hi); }
package matlab; import com.mathworks.toolbox.javabuilder.*; import com.eigenface.Eigenface; public class Test { public static void main(String[]
package gui; public class Solver { void solveIt(){ CubeGui.moveThat(); } } I am trying
package com.valami; public class Ferrari { private int v = 0; private void alam()
package abc; class DependencyDataCollection { private int sNo; private String sessionID; private int noOfDependency;
package employee; import employee.nidhin.staples; import java.util.*; import java.io.*; public class Employee { public static
package src; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Command { public static

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.