Lab 1 Get familiar with NetBeans IDE and definitions of clas

Lab 1. Get familiar with NetBeans IDE and definitions of classes. due today 11:59pm. use NetBeans to create a new project named Lab_l. When you create the project, a class called Lab_1 will be created with a main method. add a new java file: a java class to your project named Calculation.java In this class. Define a constructor four functions: add. subtract, multiply, and divide, (do NOT define these methods as static methods) Optional requirement: keep two decimals for the division result. In the main method at Lab_1 class, ask users from input and calculate the addition, subtraction, multiplication, and division of these numbers, and your program should not allow division by zero. Submission: submit the source code of all your .java files in a .zip format (find your project location and right click it, select send to compressed folder) and a screenshot of the results (use snipping tool for screenshot).

Solution

import java.awt.*; import java.awt.event.*; import java.applet.*; /* */ public class Cal extends Applet implements ActionListener { String msg=\" \"; int v1,v2,result; TextField t1; Button b[]=new Button[10]; Button add,sub,mul,div,clear,mod,EQ; char OP; public void init() { Color k=new Color(120,89,90); setBackground(k); t1=new TextField(10); GridLayout gl=new GridLayout(4,5); setLayout(gl); for(int i=0;i<10;i++) { b[i]=new Button(\"\"+i); } add=new Button(\"add\"); sub=new Button(\"sub\"); mul=new Button(\"mul\"); div=new Button(\"div\"); mod=new Button(\"mod\"); clear=new Button(\"clear\"); EQ=new Button(\"EQ\"); t1.addActionListener(this); add(t1); for(int i=0;i<10;i++) { add(b[i]); } add(add); add(sub); add(mul); add(div); add(mod); add(clear); add(EQ); for(int i=0;i<10;i++) { b[i].addActionListener(this); } add.addActionListener(this); sub.addActionListener(this); mul.addActionListener(this); div.addActionListener(this); mod.addActionListener(this); clear.addActionListener(this); EQ.addActionListener(this); } public void actionPerformed(ActionEvent ae) { String str=ae.getActionCommand(); char ch=str.charAt(0); if ( Character.isDigit(ch)) t1.setText(t1.getText()+str); else if(str.equals(\"add\")) { v1=Integer.parseInt(t1.getText()); OP=\'+\'; t1.setText(\"\"); } else if(str.equals(\"sub\")) { v1=Integer.parseInt(t1.getText()); OP=\'-\'; t1.setText(\"\"); } else if(str.equals(\"mul\")) { v1=Integer.parseInt(t1.getText()); OP=\'*\'; t1.setText(\"\"); } else if(str.equals(\"div\")) { v1=Integer.parseInt(t1.getText()); OP=\'/\'; t1.setText(\"\"); } else if(str.equals(\"mod\")) { v1=Integer.parseInt(t1.getText()); OP=\'%\'; t1.setText(\"\"); } if(str.equals(\"EQ\")) { v2=Integer.parseInt(t1.getText()); if(OP==\'+\') result=v1+v2; else if(OP==\'-\') result=v1-v2; else if(OP==\'*\') result=v1*v2; else if(OP==\'/\') result=v1/v2; else if(OP==\'%\') result=v1%v2; t1.setText(\"\"+result); } if(str.equals(\"clear\")) { t1.setText(\"\"); } } }
 Lab 1. Get familiar with NetBeans IDE and definitions of classes. due today 11:59pm. use NetBeans to create a new project named Lab_l. When you create the proj

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site