StudentShare
Contact Us
Sign In / Sign Up for FREE
Search
Go to advanced search...
Free

Program Description: Calculator - Essay Example

Cite this document
Summary
"Program Description: Calculator" paper describes and analyzes the calculator designed using JAVA. Swing is the concept that has been employed in it. The author has used many features of JAVA in designing the calculator. From lines 5 to 26 he has used the inbuilt packages in the JAVA library…
Download full paper File format: .doc, available for editing
GRAB THE BEST PAPER91.5% of users find it useful
Program Description: Calculator
Read Text Preview

Extract of sample "Program Description: Calculator"

Section Program I have designed the calculator using JAVA. Swing is the concept that has been employed in it. I have used many features of JAVA in designing the calculator. From the line no 5 to 26 I have used the inbuilt packages in JAVA library and used the concept of inheritance to import the required files using the import statement. In the line no 28, I have defined a class which is the basis of encapsulation in JAVA. Encapsulation is the mechanism that binds together code and the data it manipulates, and keeps both safe from outside interference and misuse. As we look at the line no 28 we find the syntax of the class as public class Calculator extends JFrame implements ActionListener. Here we have used the access specifier as public which tells us that the class can be accessed anywhere in the program. In the same line we have used the concept of Inheritance, which is the process by which one object acquires the properties of another object. By the use of extends keyword we inherit all the functionality provided in the class JFrame, which is used to create a frame using Swings. Further we implement the interface ActionListener using the implements keyword. By interface we mean that we can specify what a class must do, but now how it does it. Here we have implemented the ActionListener interface and so we have to define it. The purpose of ActionListener interface is to receive the Action Events. When the action event occurs, that object's action Performed method is invoked. Moving into the class body, we have declared variables with final keyword so that their value retains constant throughout the program. Then from line no 41 onwards we have created the objects of classes that will be used in the program and are defined with access specified private so that only the code inside this class can manipulate them. At line no 56 we see the constructor, which initializes an object immediately upon creation. It has the same name as the class in which it resides. The constructor is automatically called after the object is created. From the line no 63 onwards we have referenced the various objects and then called their respective methods to do the job. The new operation instantiates an object of a particular class, and returns a reference to it. At line no 126, I have used the syntax Container contentPane = getContentPane(); Here the method get ContentPane returns the contentPane object for this frame. And further we add components to the frame. From line no 138 I have created the buttons for the calculator using grid layout. The GridLayout class is a layout manager that lays out a container's components in a rectangular grid. The container is divided into equal-sized rectangles, and one component is placed in each rectangle. Then using the predefined class JButton we have created the buttons for the sign +, -, * and so on. At line no 192 we have set panel layout manager for a 4 by 5 grid. Then from line no 198 we add buttons to keypad panel starting at top left. We set the layout of masterpanel as border layout at the line no 239 masterPanel.setLayout(new BorderLayout()); and then we add the components in west, east and south direction. At line 246 we use request focus which requests that this Component gets the input focus. From line no 251 we have used addActionListener method to register the events. At line 260 we used the method addWindowListener which adds the specified window listener to receive window events from this window. It is used for closing frame and ending program. As we mentioned above whenever an action is performed the function Public void actionPerformed(ActionEvent e) is automatically called. This method is invoked when an action occurs. From the line no 299 we have used an important feature of JAVA called the switch-case. The switch statement in Java provides a convenient method for branching a program based on a number of conditionals. From line no 499 we have used various methods like setDisplayString(), getDisplayString (), addDigit(int digit), addDecimalPoint(), processSignChange() and so on to perform their respective function whenever they are called upon. A method is a group of instructions that is given a name and can be called up at any point in a program simply by quoting that name. At line no 552 we see that we have put a try catch block. We use try catch blocks in JAVA for handling the exceptions generated by some methods. The try{}Catch{} structure should be used when it is possible that your method will fail. Many input and output methods throw exceptions and these exceptions need to be caught in a try catch format. Although the default exception handler provided by the Java run-time system is useful for debugging, you will usually want to handle an exception yourself. Doing so provides two benefits. First, it allows you to fix the error. Second, it prevents the program from automatically terminating. We get confused (to say the least) if our program stopped running and printed a stack trace whenever an error occurred! Fortunately, it is quite easy to prevent this as used in the program. At the line no 603 we have declared a method whose syntax is double processLastOperator() throws DivideByZeroException. Here we have used the throws clause. If a method is capable of causing an exception that it does not handle, it must specify this behavior so that callers of the method can guard themselves against the exception. We do this by including a throws clause in the method's declaration as used in the program. From this syntax upto line no 644 we have used the methods which do their task whenever they are called. But, at the line no 644 we see the following code public static void main(String args[]) public is access specifier it means the Method(Function) can be accessed from any where static is the type of storage class, it implies that the memory allocated to main, will remain on completion of main method too.. void means empty main is the main function() String args is an instance which is of type string passed to main() The running of a program starts from the main method and follows the order. Here first the constructor will be called and then after the layout the respective functions will be called. At line no 657 the class named as calculator finishes and then we create the other two classes named class DivideByZeroException extends Exception class CustomDialog extends JDialog implements ActionListener At line no 663 we see that we have used a keyword super(); The super keyword is used to invoke the constructor of parent class. i.e. If our method overrides one of its superclass's methods, we can invoke the overridden method through the use of the keyword super. We can also use super to refer to a hidden field. The class CustomDialog implements and extends the interface and class respectively as was the class Calculator. Section 2:- An evaluation as to whether the system was easier to build in Java language or VB.Net I think the application Window Calculator was much easier to build in Java than in Visual Basic. My perception would have been different, had it been a simple calculator because of the simple reason that Visual Basic provides all the basic tools to create a Standard calculator including all the buttons and a text box for display. But, the windows calculator needed much more functionality than the one stated above. It required the advance functionalities like on clicking 'Scientific' in the View Tab, it had to display the extended Calculator and moreover on selection of any of the initial radio buttons in the left hand sides (Hex, Dec, Oct or Bin), the corresponding radio buttons on the right hand side to change which can be very well and easily incorporated in Java with the help of catching action Listener for the corresponding events. For the same code in Visual Basic, multiple forms had to be created for catering to the selections of the radio buttons over the left hand side with each form being loaded on either the selection of the radio button or on the click of the mouse for corresponding item in the View Tab. Moreover, Java is inherently is an Object Oriented language and uses the different concepts of Object Oriented programming like inheritance, polymorphism etc with much ease as compared to Visual Basic. With the concept of reusability in classes, there was no need for a repeat code as the code for Standard calculator was also getting used in the scientific which could have been utilized very thoroughly in Visual Basic as multiple forms had to be used there. Although it could have been easier to create an application to calculate in VB rather than in Java because of the reason that VB directly supports creation of buttons and text box therefore designing the similar code could have been much easier than in Java in which we had to import many of the classes and then provide action Listeners to perform the similar functionality but the stability and efficiency of the code is much better in Java as compared to a similar code in Visual Basic because of the inherent features of Java being an Object Oriented Language. Moreover Java technologies are supported by multiple vendors allowing mix and match and best of breed solutions. Considering the above mentioned reasons and some other I found JAVA an appropriate language to build the calculator. Personal Reflection: The above assignment was really a good knowledge addition and was kind of an independent small project in itself. This assignment covered most of the part of the software programming where initially the systematic design included all the classes to be identified and had to apply the various concepts of Object Oriented Programming like inheritance, encapsulation etc. After this all the logic involved in the design phase had to be actually coded in the program which gave me an opportunity to learn the nitty-gritty of various methods in the different classes provide by Sun Developers as well. After the coding phase, I also got some idea on the testing phase while doing some testing on the code that I developed. At the end of the assignment when the built was already done in Java, I could compare that with the build of some other programming language such as VB and thus learned a few important concepts about programming methodology in Visual Basic as well. Finally, the process of documentation helped me to realize that how important this process of documentation is for any future modification or enhancement if needed for any product even if it being as simple as a calculator. Work Cited: Schildt, Herbert. "Java: The Complete Reference". Tata McGraw-Hill Publishing Co. Ltd, New Delhi: Tata McGraw, 2007. Read More
Cite this document
  • APA
  • MLA
  • CHICAGO
(“Java Programming Essay Example | Topics and Well Written Essays - 1500 words”, n.d.)
Retrieved from https://studentshare.org/technology/1531938-java-programming
(Java Programming Essay Example | Topics and Well Written Essays - 1500 Words)
https://studentshare.org/technology/1531938-java-programming.
“Java Programming Essay Example | Topics and Well Written Essays - 1500 Words”, n.d. https://studentshare.org/technology/1531938-java-programming.
  • Cited: 1 times

CHECK THESE SAMPLES OF Program Description: Calculator

Critical Evaluation of QALY and DALY

Generally in most sectors of the economy, other than the healthcare section efficiency of any program is evaluated based on the benefits that the program offers or based on value for money.... Given a particular budget constraint, it is possible to maximize QALY busingincreasing individuals' utility and the total number of individuals that would come under the purview of a specific healthcare program....
14 Pages (3500 words) Essay

System and signal processing

he new MATLAB command used in this program is ‘conv(x,y);'.... n previous program we had been using ‘find' command.... If only marker type is specified, but not a line style, MATLAB draws only the marker. ... ... sing this command the MATLAB will draw the graph....
8 Pages (2000 words) Essay

Alternative Approaches and Practical Guidelines

This is captured along the description of both the program and him services it intends to extends to the procurer.... The following paper entitled 'Alternative Approaches and Practical Guidelines' is focused on the concept of establishing the cost-effectiveness as well as the possible benefits which accredited to a program involves the elucidation of the associated procurement expenses.... Kee propose the Cost-effectiveness analysis as the elemental phase upon which the process of identifying the expense associated with a program may be detected....
1 Pages (250 words) Essay

Systems Modelling

First, the given constants for the MSD system are declared and initialised so that the program recognises them during execution.... he program begins with the definition of variables to be used i.... The program then illustrates the response of the system to initial conditions.... Gain is usually multiplied by the numerator of the transfer function, therefore the program will prompt the user to enter a value for the gain then the program computes the stability....
4 Pages (1000 words) Lab Report

Brief Scenario: A Confidence Interval

ttached is a Confidence Interval Tutorial & calculator.... This assignment "Brief Scenario: A Confidence Interval" discusses a narrow Confidence Interval.... The assignment analyses the increase or decreases of the confidence level to decrease the Confidence Interval.... The assignment focuses on three factors that must be specified to calculate the sample size....
8 Pages (2000 words) Assignment

Comparison Between Energy Modeling Soft wares for Sustainable Building Design

This paper stresses that there is an increase in the trend to use energy simulation tools to analyze the energy performance.... There have been lots of energy programs and software developed during the last fifty years.... Majority of the energy modeling soft wares contain an engine.... ... ... ... As the paper highlights, the software used in the building energy field is actually the full-fledged energy software....
5 Pages (1250 words) Article

Portfolio Php and Html Codes for 6 EX

In this chapter, we will discuss the program that calculates and displays the total sum of pennies after the lapse of 30 days period.... The program starts from a penny on day one and then keeps on doubling the number of pennies from next day onwards until the lapse of the 30th day.... he program that we will discuss in this chapter is actually an improvement of the same program that we have discussed in the previous chapter....
30 Pages (7500 words) Case Study
sponsored ads
We use cookies to create the best experience for you. Keep on browsing if you are OK with that, or find out how to manage cookies.
Contact Us