Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question: Write a program that converts decimal to binary using a stack. Ask the user to enter a decimal number, then print the equivalent binary

Question: Write a program that converts decimal to binary using a stack. Ask the user to enter a decimal number, then print the equivalent binary number.

1) Add a method to the Stack class print() to print the contents starting with the earliest to the latest. Eg: stk.push(3); stk.push(4); stk.push(5); stk.print(); //would print 3 4 5

2) Write a method public long removeSecond (): It removes and returns the element just below the top element if the stack has at least two elements, otherwise it simply returns null without modifying the stack Eg: stk.push(3); stk.push(4); stk.push(5); stk.push(6); stk.removeSecond(); stk.print(); //would print 3 4 6

StackTest.java

class StackTest { public static void main(String[] args) { StackX theStack = new StackX(10); // make new stack theStack.push(20); // push items onto stack theStack.push(40); theStack.push(60); theStack.push(80);

theStack.print(); theStack.removeSecond(); System.out.println("After removeSecond()"); theStack.print(); } // end main() }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago