Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Binary Calculator Design and implement a GUI based application to perform asa binary calculator which cando binary addition, subtraction, multiplication, division (forpositive numbers, negative numbers,

Binary Calculator

Design and implement a GUI based application to perform asa binary calculator which cando binary addition, subtraction, multiplication, division (forpositive numbers, negative numbers, and zero). Integer division isused, that is, division result is also an integer. Attached is aclass which provides methods to convert decimal to binary andbinary to decimal.

You calculator should be able to do continuous calculations suchas

the input is 110+10-1*10=+1=, the result should be 1111(continuous calculation just executes from left to right, nooperator precedence needs to be considered)

If your calculator cannot do continuous calculations, at leastit should be able to do calculations like this

110+10=-1=*10=+1=, the result should be 1111.

/* * To change this template, choose Tools | Templates * and open the template in the editor. *//** * * @author aic */public class BinaryDecimal {        //Convert from Binary number (String) to integer    public static int BinaryToDecimal(String bin)    {        int flag=0; //0 positive number 1 negative         flag = (bin.charAt(0) != '-' ? 0:1);        if (bin.charAt(0) == '+' || bin.charAt(0) == '-')            bin = bin.substring(1);        int decimal = 0;        int digit;        for (int i=bin.length()-1;i>=0;i--)        {            if (bin.charAt(i) == '0')                digit = 0;            else if (bin.charAt(i) == '1')                digit = 1;            else            {                System.out.println("Invalid input");                return -1;            }            decimal += digit*Math.pow(2.0,bin.length()-1-i);        }        if (flag == 1)            return -decimal;        return decimal;    }        //Convert from integer to Binary number    public static String DecimalToBinary(int decimal)    {        String bin = "";        String result = "";        if (decimal<0)        {            result += "-";            decimal = 0-decimal;        }        if (decimal == 0)        {            result = "0";            return result;        }        while (decimal/2 != 0)        {            bin += (decimal%2==1)? "1":"0";            decimal /= 2;        }        bin += "1";               for (int i=bin.length()-1;i>=0;i--)            result += bin.charAt(i);        return result;    }}

Step by Step Solution

3.44 Rating (151 Votes )

There are 3 Steps involved in it

Step: 1

To design and implement a GUI based binary calculator application that can perform binary addition s... 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

Process Dynamics And Control

Authors: Dale E. Seborg, Thomas F. Edgar, Duncan A. Mellich

2nd Edition

471000779, 978-0471000778

More Books

Students also viewed these Electrical Engineering questions

Question

Design and implement a class for B-trees.

Answered: 1 week ago

Question

23. What are the effects of cannabinoids on neuronspg105

Answered: 1 week ago

Question

26. Name at least two ways a gene could influence alcoholism.

Answered: 1 week ago