Question: You are required to completely implement the Java program given to convert a decimal number into binary and binary number into decimal. An Incomplete program

You are required to completely implement the Java program given to convert a decimal number
into binary and binary number into decimal.
An Incomplete program is given below;
class Stack
{
int size =5;
int[] arr = new int[size];
int top =-1;
public void push(int element)
{
if (top < size -1)
{
top++;
arr[top]= element;
System.out.println ("Element Added "+ element);
}
else
System.out.println ("Stack is Full");
}
public int pop()
{
int element=0;
if (top >=0)
{
element = arr[top];
top--;
}
else
{
System.out.println ("Stack is empty");
}
return element;
}
public static void main (String args[])
{
//You are required to write your code here
}
}
Converting Binary to Decimal and vice versa
Part I
Converting Decimal Number to Binary.
Algorithm
Step 1: Take a number in decimal
Step 2: while the number is greater than 0:
Step 2.1: Push the remainder after dividing the number by 2 into stack.
Step 2.2: set the number as number /2.
Step 3: Pop elements from stack and print the binary number
Part II
Converting Binary to Decimal
Algorithm
Step 1: Start with a binary string and a decimal value set to 0.
Step 2: Starting with the first character of the string, push each digit into the stack.
Step 3: Pop digit out of the stack, multiplying it by 2^n, n=[0,string size -1].
Step 4: Repeat step 3 until stack is empty. ...
Step 5: Print out the answer.
You are required to completely implement the Java program given to convert a decimal number
into binary and binary number into decimal.
Develop an interactive main that gives users two options.
1. Enter 1 to convert from decimal to binary
2. Enter 2 to convert from binary to decimal.
(8 marks)
Implement two methods.
boolean isempty()
(1 marks)
boolean isFull()
(1 marks)
please provide a full code based on the information given above in java

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!