Skip to main content

Featured

How to make a simple calculator with GUI in JAVA (using Netbeans)?

First of all create a new package , then create a simple class. Then create a new JFrame Form class. On the right side you will find every tool needed like buttons textfield radio buttons etc. We'll need the buttons and text field and a JLabel Drag and drop required buttons you want to appear on the calculator eg. 1,2,3,4,5,6,7,8,9,0,+,-,*,/,=,AC,OFF arrange them all then on double clicking any button you will enter the source code tab, for digits 0-9 you have to write this code:         String Number =answer.getText() +  one.getText();         answer.setText(Number); Here answer is the jTextFields variable name you can right click the text field and click change variable name. similarly you have to set the code for every digit then for operations you have to write the code: for "+" operation: firstnumber = Double.parseDouble(answer.getText());         jLabel1.setText(answer.getText()+"+"); ...

How to make user defined array to calculate subjects marks?

I already shared a method to calculate sum of array elements in our case we said we wanted to calculate subjects marks,we set the array size initially without the users concern ,and users were bounded to a limit of array elements,in this example
We will let the user define the array size
and by For loop we will calculate the sum.,Its more easier than typing sum=array[0]+array[1] ...

check out the screenshots and code below.






C++ code:



/*
   This is a array sum program
   which will first ask you about 
   the array size,that is number of 
   subjects.Then by implementing for loop 
   we will input values to the array
   elements.

   
*/

#include <iostream>
using namespace std;
int main()
{ 
 
 int size;
 int counter;
 float marks=0;
 int position=0;
 cout<<"\n Enter total number of subjects: ";
 cin>>size;
 
 cout<<endl;
 
 int * array;
 
 array = new int[size];
 
 for(counter = 0; counter < size; counter ++)
  {
    
  cout<<endl;
  position=counter+1;
  cout << "Enter marks of "<<counter+1;
     switch(position)
  {
  case 1:
  {cout<<"st";}
  break;
  case 2:
   {cout<<"nd";}
   break;
  case 3:
   {cout<<"rd";}
   break;
  default:
   {cout<<"th";}
   break;
  }

  cout<<" subject: ";


  cin >> array[counter];

  marks=marks+array[counter];

 }
 
 cout<<endl;

 cout<<"\n Total marks are "<<marks<<" ";
  
 cout<<endl;
 
 delete [] array;

 return 0;

}

Comments