Sunteți pe pagina 1din 14

package lab11.simple.calculator.gui.

tan;
import javax.swing.*;
public class SimpleCalculator extends JFrame{
//declare the components
private JLabel lblNum1=new JLabel("First No. : ");
private JLabel lblNum2=new JLabel("Second No. : ");
private JLabel lblNum3=new JLabel("Result : ");
private JTextField txtNum1=new JTextField();
private JTextField txtNum2=new JTextField();
private JButton btnAdd=new JButton("ADD");
private JButton btnSub=new JButton("SUBTRACT");
private JButton btnMul=new JButton("MULTIPLY");
private JButton btnDiv=new JButton("DIVIDE");
private JButton btnRes=new JButton("RESET");
private JButton btnEx=new JButton("EXIT");
private JPanel panel=new JPanel();
public SimpleCalculator () {
//define the frame
super("Simple Calculator GUI");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(400,300);
this.setLocation(100,50);
this.setVisible(true);
//define the components
this.lblNum1.setSize(150,20);
this.lblNum1.setLocation(50,20);
this.lblNum2.setSize(150,20);
this.lblNum2.setLocation(50,50);
this.lblNum3.setSize(150,20);
this.lblNum3.setLocation(50,80);
this.txtNum1.setSize(150,20);
this.txtNum1.setLocation(200,20);
this.txtNum2.setSize(150,20);
this.txtNum2.setLocation(200,50);

this.btnAdd.setSize(100,20);
this.btnAdd.setLocation(150,110);
this.btnSub.setSize(100,20);
this.btnSub.setLocation(250,110);
this.btnMul.setSize(100,20);
this.btnMul.setLocation(150,150);
this.btnDiv.setSize(100,20);
this.btnDiv.setLocation(250,150);
this.btnRes.setSize(100,20);
this.btnRes.setLocation(150,190);
this.btnEx.setSize(100,20);
this.btnEx.setLocation(250,190);

//define the panel


this.panel.setLayout(null);

this.setContentPane(panel);
//add components to the frame
this.getContentPane().add(lblNum1);
this.getContentPane().add(lblNum2);
this.getContentPane().add(lblNum3);
this.getContentPane().add(txtNum1);
this.getContentPane().add(txtNum2);
this.getContentPane().add(btnAdd);
this.getContentPane().add(btnSub);
this.getContentPane().add(btnMul);
this.getContentPane().add(btnDiv);
this.getContentPane().add(btnRes);
this.getContentPane().add(btnEx);

}
}
----------------------------------------------

package lab11.simple.calculator.gui.tan;
public class Student {

public static void main(String[] args) {


SimpleCalculator scg=new SimpleCalculator();
}
}

package lab3.payslip.version2.tan;
import java.io.*;
import java.text.*;

public class PaySlipVer2 {

public static void main(String[] args) throws Exception {


BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
DecimalFormat df=new DecimalFormat("Php #,##0.00");
DecimalFormat ddf=new DecimalFormat("#,##0.00");
DecimalFormat ddff=new DecimalFormat("#,##0.0");

double gross,otpay,netpay,withtax,taxrate;
String paygrade = " ";
System.out.print("Employee name : ");
String name=br.readLine();
System.out.print("Basic salary : ");
float salary=Float.parseFloat(br.readLine());
System.out.print("No. of OT hours : ");
double hours=Double.parseDouble(br.readLine());
if (salary>=10000 && salary<15000){
paygrade = "A";
taxrate=0.10;}
else if (salary>=15000 && salary<20000) {
paygrade = "B";
taxrate= 0.10;}
else if (salary>=20000 && salary<25000) {
paygrade = "A";
taxrate=0.15;}
else if (salary>=25000 && salary<30000) {
paygrade = "B";
taxrate=0.15;}
else if (salary>=30000 && salary<35000) {
paygrade = "A";
taxrate=0.20;}
else if (salary>=35000 && salary<40000) {
paygrade = "B";
taxrate=0.20;}
else if (salary>=40000 && salary<45000) {
paygrade = "A";
taxrate=0.25;}
else if (salary>=45000 && salary<50000) {
paygrade = "B";
taxrate=0.25;}
else if (salary>=50000 && salary<55000) {
paygrade = "A";
taxrate=0.30;}
else {
paygrade = "B";
taxrate=0.30;}
otpay=hours*(0.01*salary);
gross=salary + otpay;
withtax= gross*taxrate;
netpay= gross-withtax;
System.out.println("Employee Name : " + name);
System.out.println("Basic Salary : " + df.format(salary));
System.out.println("Pay Grade : " + paygrade);
System.out.println("No. of OT Hours : " + ddff.format(hours));
System.out.println("OT Pay : " + df.format(otpay));
System.out.println("Gross Salary : " + df.format(gross));
System.out.println("Withholding tax : " + ddf.format(withtax));
System.out.println("Net Pay : " + df.format(netpay));
}

package lab8.my.first.pkgclass.with.polymorphism.and.inheritance.tan;
import java.io.*;

public class Watcher {


public static void main(String[] args) throws Exception{
BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
TV watch=new TV();
System.out.println("These are the initial values:");
System.out.println("Brand Name = "+watch.getbrandName());
System.out.println("Size = "+watch.getSize());
System.out.println("Type= "+watch.getType());
watch.setBrandName("JVC");
watch.setSize(21.5);
watch.setType("LCD");
System.out.println("\nAfter assigning the values:");
System.out.println("Brand Name = "+watch.getBrandName());
System.out.println("Size = "+watch.getSize());
System.out.println("Grade= "+watch.getType());
watch.transmits();
System.out.print("\nEnter brand name --> ");
String brandName=br.readLine();
System.out.print("Enter size --> ");
double size=Double.parseDouble(br.readLine());
System.out.print("Enter type --> ");
String type=br.readLine();
watch.setBrandName(brandName);
watch.setSize(size);
watch.setType(type);
System.out.println("\nAfter the input of the values:");
System.out.println("Brand Name = "+watch.getBrandName());
System.out.println("Size = "+watch.getSize());
System.out.println("Type= "+watch.getType());
watch.transmits();
watch.transmits("radioactive");
System.out.println();
watch.operates();
watch.consumes();
TV watch2=new TV("Panasonic",25.5,"Flat Screen");
System.out.println("\nDetails for the second TV object:");
System.out.println("Brand Name = "+watch2.getBrandName());
System.out.println("Size = "+watch2.getSize());
System.out.println("type= "+watch2.getType());

}
}
--------------------------------

public class TV extends ElectronicDevice{


//attributes
private String brandName;
private double size;
private String type;
//constructor
public TV(){
this.brandName="";
this.size=0.00;
this.type="";
}
public TV(String brandName,double size,String type){
this.brandName=brandName;
this.size=size;
this.type=type;
}
//setters or mutators
public void setBrandName(String brandName){
this.brandName=brandName;
}
public void setSize(double size){
this.size=size;
}
public void setType(String type){
this.type=type;
}
//getters
public String getBrandName(){
return this.brandName;
}
public double getSize(){
return this.size;
}
public String getType(){
return this.type;
}
//custom method
public void transmits(){
System.out.println(this.brandName + " TV transmits a signal!");
}
public void transmits(String signaltype){
System.out.println(this.brandName+" TV transmits a "+signaltype+" signal.");
}
public void operates(){
System.out.println(this.brandName+" operates via electricity.");
}
}
---------------------------------

package lab8.my.first.pkgclass.with.polymorphism.and.inheritance.tan;

public class ElectronicDevice {


protected String type;
protected double price;

public ElectronicDevice(){
this.type="";
this.price=0.00;
}

public String getType() {


return type;
}

public void setType(String type) {


this.type = type;
}

public double getPrice() {


return price;
}

public void setPrice(double price) {


this.price = price;
}

public void consumes(){


System.out.println("An electronic device consumes energy.");
}
public void operates(){
System.out.println("An electronic device operates via electricity.");
}
}

package fraction2;
import java.io.*;
public class FractionMain {
public static void main(String[] args) throws Exception{
BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
Fraction2 solve=new Fraction2();
/*System.out.println("Numerator : " + solve.getNum());
System.out.println("Denominator : " + solve.getDen());*/

System.out.println();
System.out.println("Enter numerator: ");
int num =Integer.parseInt(br.readLine());
System.out.println("Enter denominator: ");
int den =Integer.parseInt(br.readLine());
solve.setNum(num);
solve.setDen(den);
/*System.out.println();
System.out.println("Brand Name : " + watch.getBrandName());
System.out.println("Size : " + watch.getSize());
System.out.println("Type: " + watch.getType());
watch.transmits();*/
/*solve.num=num;
solve.den=den;*/
solve.shownum();
solve.showden();
solve.showfrac();
solve.lowest();
solve.divide();
solve.type();

}
}

package fraction2;
public class Fraction2 {

int num;
int den;

//constructor
public Fraction2(){
this.num=0;
this.den=0;
}
//setters
public void setNum(int num){
this.num=num;
}
public void setDen(int den){
this.den=den;
}

//getters
public int getNum(){
return this.num;
}
public int getDen(){
return this.den;
}
//custom methods
public void shownum (){
System.out.println("Numerator:" + num);
}
public void showfrac (){
System.out.println("Fraction Form:" + num + "/" + den);
}

public void showden (){


System.out.println("Denominator:" + den);
}

public void divide(){


double quo=num * 1.0/den;
System.out.println("Decimal Equivalent: " +quo);

}
public void lowest(){
int n = num;
int d = den;

while (d!=0) {
int temp = d;
d = n%d;
n = temp;
}
int great = n;

num /= great;
den /= great;
System.out.println("Lowest Term: " + this.num + "/" + this.den);
}
public void type(){
double rem =0.00;
rem=num%den;
if (num>den) {
if (rem==0)
System.out.println("Fraction Type: Whole Number");
else
System.out.println("Fraction Type: Improper Fraction");
}
else if(den>num) {
System.out.println("Fraction Type: Proper Fraction"); }
else {
System.out.println("Invalid"); }
}
}

package fraction2;
public class Fraction2 {

int num;
int den;
double quo = 0.00;

//constructor
public Fraction2(){
this.num=0;
this.den=0;
}
//setters
public void setNum(int num){
this.num=num;
}
public void setDen(int den){
this.den=den;
}

//getters
public int getNum(){
return this.num;
}
public int getDen(){
return this.den;
}
//custom methods

public void lowest(){


int n = num;
int d = den;

while (d!=0) {
int temp = d;
d = n%d;
n = temp;
}
int great = n;

num /= great;
den /= great;

System.out.println("The lowest term is: " + this.num + "/" + this.den);


}
public void type(){
if (num>den)
System.out.println("This is an improper fraction!");
else if(den>num)
System.out.println("This is a proper fraction!");
else if(den==num)
System.out.println("This is equal to 1!");
else
System.out.println("Invalid");
}
public void divide(){
quo=num/den;
System.out.println("The decimal form is: " +quo);

}
}

package fraction2;
import java.io.*;
public class FractionMain {
public static void main(String[] args) throws Exception{
BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
Fraction2 solve=new Fraction2();
/*System.out.println("Numerator : " + solve.getNum());
System.out.println("Denominator : " + solve.getDen());*/

System.out.println();
System.out.println("Enter numerator: ");
int num =Integer.parseInt(br.readLine());
System.out.println("Enter denominator: ");
int den =Integer.parseInt(br.readLine());
solve.setNum(num);
solve.setDen(den);
/*System.out.println();
System.out.println("Brand Name : " + watch.getBrandName());
System.out.println("Size : " + watch.getSize());
System.out.println("Type: " + watch.getType());
watch.transmits();*/
/*solve.num=num;
solve.den=den;*/
solve.lowest();

}
}

package lab5.seat.reservation.tan;
import java.io.*;
public class SeatReservation {

public static void main(String[] args) throws IOException {


BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int aryseat[][]= new int[5][7];
int i,j,x=1,n1=0,n2=0,h=0;
for(i=0;i<aryseat.length;i++) {
for(j=0;j<aryseat[i].length;j++) {
aryseat[i][j] = x++;
}

}
for (int k=0;k<100;k++) {
for(i=0;i<aryseat.length;i++) {
for(j=0;j<aryseat[i].length;j++) {
System.out.print("\t" + aryseat[i][j] + " ");
}
System.out.println("");
}

System.out.print("Enter seat number to reserve: ");


int num = Integer.parseInt(br.readLine());
if (num<1 || num>35)
{
System.out.println("\nInvalid seat number! Please try again. ");
}
else {
for(i=0;i<5;i++) {
for(j=0;j<7;j++) {
if (aryseat[i][j]== num) {
h=1;
n1=i;
n2=j;
}
}
}
if (h==1)
{
aryseat[n1][n2]=0;
h=0;
}
else if (h==0) {
System.out.println("The seat is already reserved. Please choose another one.");

}
}

S-ar putea să vă placă și