From ca32d72cf1eb3af1d027d113523954abc5f13324 Mon Sep 17 00:00:00 2001 From: Suprabhat2810 <143078843+Suprabhat2810@users.noreply.github.com> Date: Fri, 20 Oct 2023 09:22:50 +0530 Subject: [PATCH 1/3] Update Area and Perimeter. With all the comments in a descriptive manner --- Area and Perimeter | 68 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 18 deletions(-) diff --git a/Area and Perimeter b/Area and Perimeter index 835de37..ceca27a 100644 --- a/Area and Perimeter +++ b/Area and Perimeter @@ -1,26 +1,58 @@ +// Java program to create a class to +// print the area and perimeter of a +// rectangle + import java.util.*; -class Question13 -{ - public static void main(String[] args) { - Scanner sc = new Scanner(System.in); - - System.out.println("Enetr width::"); - double width = sc.nextFloat(); - - System.out.println("Enetr height::"); - double height = sc.nextFloat(); - - double perimeter = 2*(height + width); - - double area = width * height; - - System.out.println("Perimeter is:: "+ perimeter); +// Rectangle Class File +public class Rectangle { + + // Variable of data type double + double length; + double width; + + // Area Method to calculate the area of Rectangle + void Area() + { + double area; + area = this.length * this.width; + System.out.println("Area of rectangle is : " + + area); + } + + // Perimeter Method to calculate the Perimeter of + // Rectangle + void Perimeter() + { + double perimeter; + perimeter = 2 * (this.length + this.width); + System.out.println("Perimeter of rectangle is : " + + perimeter); + } +} + +class Use_Rectangle { + + public static void main(String args[]) + { + // Object of Rectangle class is created + Rectangle rect = new Rectangle(); + + // Assigning the value in the length variable of + // Rectangle Class + rect.length = 15.854; - System.out.println("Area is:: "+ area); + // Assigning the value in the width variable of + // Rectangle Class + rect.width = 22.65; - + System.out.println("Length = " + rect.length); + System.out.println("Width = " + rect.width); + // Calling of Area method of Rectangle Class + rect.Area(); + // Calling of Perimeter method of Rectangle Class + rect.Perimeter(); } } From ff99a3823ec906c4fa41bcb979b0dbf5426c7976 Mon Sep 17 00:00:00 2001 From: Suprabhat2810 <143078843+Suprabhat2810@users.noreply.github.com> Date: Sat, 21 Oct 2023 23:52:22 +0530 Subject: [PATCH 2/3] Update Area and circumference of Circle This area and circumference using python in a user-friendly manner. --- Area and circumference of Circle | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/Area and circumference of Circle b/Area and circumference of Circle index 9129ece..2949b7f 100644 --- a/Area and circumference of Circle +++ b/Area and circumference of Circle @@ -1,17 +1,8 @@ -import java.util.*; -class Question11{ - - public static void main(String[] args) { - - Scanner sc = new Scanner(System.in); - - double pi = 3.14; - System.out.println("Enter Radius::"); - double radius = sc.nextDouble(); - - - System.out.println("Perimeter Is :: "+ 2* pi* radius ); - System.out.println("Area Is ::"+ pi*radius * radius ); - -} - } +import math as m +r=float(input("Enter the radius of the circle:")) #radius of the circle +#Area of the circle +a = m.pi* r**2 +#Circumference of the circle +c = 2 * m.pi * r +print("The area of the circle with radius {} is: {}".format(a,r)) +print("The circumference of the circle with radius {} is {}".format(c,r)) From 2bfb5af7db6cf442f11cd2e6b80a78d05874b885 Mon Sep 17 00:00:00 2001 From: Suprabhat2810 <143078843+Suprabhat2810@users.noreply.github.com> Date: Sat, 21 Oct 2023 23:55:08 +0530 Subject: [PATCH 3/3] Update Calculator using the Tkinter module. --- Calculator | 174 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 113 insertions(+), 61 deletions(-) diff --git a/Calculator b/Calculator index 9435dbc..5f87611 100644 --- a/Calculator +++ b/Calculator @@ -1,66 +1,118 @@ -import java.util.*; -class Calculator -{ - public static void main(String[] args) { - Scanner sc = new Scanner(System.in); - float a, b; //a<=50000, b<=50000 - int choice; - System.out.println("Enter two numbers:"); - a = sc.nextFloat(); - b = sc.nextFloat(); +#Step1: Importing of the modules +from tkinter import * +#Step2: GUI Interection +win=Tk() +win.geometry("500x500") +#Step3: Adding Inputs +#entry box +e=Entry(win,width=56) +e.place(x=0,y=0) - if(a<=50000 && b<=50000) +#defining the numeric-functions: +def click(num): + result=e.get() + e.delete(0,END) + e.insert(0,str(result)+str(num)) + +#defining the operators: +def add(): + n1=e.get() + global i + global a + a="addition" + i=int(n1) + e.delete(0,END) - { - System.out.println("Enter you choice"); - System.out.println("1. Addition"); - System.out.println("2. Subtraction"); - System.out.println("3. Multiplication"); - System.out.println("4. Division"); - choice = sc.nextInt(); +def sub(): + n1=e.get() + global i + global a + a="substraction" + i=int(n1) + e.delete(0,END) + +def mul(): + n1=e.get() + global i + global a + a="multiplication" + i=int(n1) + e.delete(0,END) + +def div(): + n1=e.get() + global i + global a + a="division" + i=int(n1) + e.delete(0,END) + +def empty(): + e.delete(0,END) + global i + i=9 + e.insert(0,i*0) - switch(choice) - { - case 1: - { - System.out.print(add(a, b)); - break; - } - case 2: - { - System.out.print(sub(a, b)); - break; - } - case 3: - { - System.out.print(mul(a, b)); - break; - } - case 4: - { - System.out.print(div(a, b)); - break; - } - } - } - System.out.println("\nInputs are not in range of 50000"); - } +#difining the equal to function +def eql(): + n2=e.get() + e.delete(0,END) + if a=="addition": + e.insert(0,i+int(n2)) + elif a=="substraction": + e.insert(0,i-int(n2)) + elif a=="multiplication": + e.insert(0, i*int(n2)) + elif a=="division": + e.insert(0, i/int(n2)) + elif a=="noip": + e.delete(0,END) +#Button first row +b=Button(win,text="7",width=12,command=lambda:click(7)) +b.place(x=10,y=60) +b=Button(win,text="8",width=12,command=lambda:click(8)) +b.place(x=80,y=60) +b=Button(win,text="9",width=12,command=lambda:click(9)) +b.place(x=170,y=60) +b=Button(win,text="*",width=12,activebackground="yellow",command=mul) +b.place(x=240,y=60) - static float add(float x, float y) - { - return x+y; - } - static float sub(float x, float y) - { - return x-y; - } - static float mul(float x, float y) - { - return x*y; - } - static float div(float x, float y) - { - return x/y; - } -} +#Button 2nd row +b=Button(win,text="4",width=12,command=lambda:click(4)) +b.place(x=10,y=90) +b=Button(win,text="5",width=12,command=lambda:click(5)) +b.place(x=80,y=90) +b=Button(win,text="6",width=12,command=lambda:click(6)) +b.place(x=160,y=90) +b=Button(win,text="+",width=12,activebackground="yellow",command=add) +b.place(x=240,y=90) + +#button 3rd row +b=Button(win,text="1",width=12,command=lambda:click(1)) +b.place(x=10,y=119) +b=Button(win,text="2",width=12,command=lambda:click(2)) +b.place(x=80,y=119) +b=Button(win,text="3",width=12,command=lambda:click(3)) +b.place(x=160,y=119) +b=Button(win,text="-",width=12,activebackground="yellow",command=sub) +b.place(x=240,y=119) + +#Button 4th row +b=Button(win,text="AC",width=12,activebackground="red",command=empty) +b.place(x=10,y=149) +b=Button(win,text="0",width=12,command=lambda:click(0)) +b.place(x=80,y=149) +b=Button(win,text="/",width=12,command=div) +b.place(x=160,y=149) +b=Button(win,text="=",width=12,activebackground="yellow",command=eql) +b.place(x=240,y=149) + + + + + + + + +win.mainloop()