check whether triangle is equilateral, scalene or isosceles
Menu-driven Calculator
Menu-driven Calculator
program to read marks of three subjects and show the division
PatternPrinting-3
Pattern3
Write a Program to determine eligibility of an applicant for teacher interview using the criteria shown in table below. The program should ask the name and gender of the applicant and display the results as “Congratulation Mr. or Ms. XXX, you are eligible for the interview” or “Sorry Mr. or Ms. XXX, you are not eligible for the interview”. Mr. or Ms. is displayed according to the gender provided by the user and XXX is the name entered from user keyboard
WAP in Java Using all the concepts of OOP, Exception handling and Packages -II
Aim:To make a simple java project for shoe shop using all the concept of OPPS,Exception handling and packages
Background:HI-TECH SHOE SHOP is a project made to help people buy shoes. This project was done to enhance my java programming skills and develop further knownledge on the concepts of OOPS,Exception Handling and pacakges
This project has been divided in 2 packages, the default package which contains one class(Welcome),and the other user defined package which contains 3 classes and 1 interface
Default Package: Welcome Class
import java.util.Scanner;
import assignment.Display;
public class Welcome {
static Scanner input = new Scanner(System.in);
static int y;
public static void main(String[] args)
{
pattern();
Display s = new Display();
s.Check();
pattern();
s.GetChoice(s.C);
s.GetChoice();
pattern();
s.printRecipe(s.sum);
confirmation(s.sum);
if( y==1)
{
s.printRecipe(s.name, s.itembrought, s.sum);
}
pattern();
thankyou();
}
private static void thankyou()
{
if(y==1)
{
System.out.println("\nTHANKYOU FOR CHOOSING HI-TECH SK SHOE STORE");
}
System.out.println("\nVisit us Again");
}
private static void confirmation(int x)
{
try
{
y=input.nextInt();
if( y==1)
{
pattern();
System.out.println("\nGenerating Recipt");
System.out.println("Payed Nu: " + x + " To Tazi Shoe Store on " + java.time.LocalDate.now() );
}
}
catch(Exception e)
{
pattern();
}
}
static void pattern()
{
for(int i =0; i <100;i++)
{
System.out.print("+");
}
}
}
Assignment Package: Display class
package assignment;
import java.util.InputMismatchException;
public class Display extends ItemDetails implements printingSystem
{
public int sum;
public int itembrought = 0;
int cardno;
public void GetChoice()
{
System.out.println("Enter serial Number of the item you want to buy:");
System.out.println("Press 0 to see the Total");
boolean t =true;
int x ;
while(t==true)
{
try
{
x = in.nextInt();
if(x==1 || x==5 ||x==6)
{
sum += 500;
itembrought++;
System.out.println("!!!!!!!!Added to the Cart!!!!!");
}
else if(x==2 || x==7 || x==10)
{
sum +=750;
itembrought++;
System.out.println("!!!!!!!!Added to the Cart!!!!!");
}
else if(x==3 || x==4 || x==8)
{
sum +=900;
itembrought++;
System.out.println("!!!!!!!!Added to the Cart!!!!!");
}
else if(x==9)
{
sum += 5000;
itembrought++;
System.out.println("!!!!!!!!Added to the Cart!!!!!");
}
else if(x==0)
{
t=false;
}
else
{
throw new Numberlargerexception();
}
}
catch (Numberlargerexception e)
{
System.out.print("Invalid Choice!! Please enter valid choice\n");
GetChoice();
}
catch(InputMismatchException e)
{
System.out.print("Invalid Choice!! Please enter valid choice\n");
GetChoice();
}
}
}
@Override
public void printRecipe(String nam, int iB, int Sn)
{
System.out.println("\nCustomer'sName: " + nam + "\nTotal Items Brought: " + iB + "\nTotal Nu: " + Sn + "\nDate Of Payment: " + java.time.LocalDate.now() );
}
@Override
public void printRecipe(int Sn)
{
System.out.println("\nTotal is Nu:" + Sn);
System.out.print("press 1.check out");
System.out.print("\npress any key on the board to to cancel\n");
}
}
Items details class
package assignment;
import java.util.Scanner;
public class ItemDetails
{
Scanner in = new Scanner(System.in);
public int C;
public String name;
ItemDetails()
{
System.out.print("\nPlease Enter Your name ");
checkname();
System.out.print("WELCOME " + name + " TO HI-TECH SK SHOE SHOP");
System.out.println("\nPress 1 for Men shoes\nPress 2 for Women Shoes");
}
public void GetChoice(int x)
{
if(x == 1)
menshoe();
if(x==2)
Womenshoe();
}
private void Womenshoe()
{
System.out.println("\nDisplaying Women's shoes:");
System.out.println("1.SANDAL --------------------MRP:500");
System.out.println("2.HIGH HEEL------- ----------MRP:750");
System.out.println("3.LOW HEEL-------------------MRP:900");
System.out.println("4.CASUAL OFFICE SHOES------- MRP:900");
System.out.println("5.JUMPER PINK SHOES ---------MRP:500");
System.out.println("6.MOMOS SHOES ---------------MRP:500");
System.out.println("7.PLASTIC OFFICE SHOES ------MRP:750");
System.out.println("8.PARTY SHOES ---------------MRP:900");
System.out.println("9.BOOT --------------------- MRP:5000");
System.out.println("10.FLAT SLIPPERS ------------ MRP:750");
}
private void menshoe()
{
System.out.println("\nDisplaying Men's shoes:");
System.out.println("1.NIKE BASKETBALL SHOES --------MRP:500");
System.out.println("2.PUMA BASKETBALL SHOES ------- MRP:750");
System.out.println("3.ADDIDAS BASKETBALL SHOES------MRP:900");
System.out.println("4.NIKE FOOTBALL SHOES --------- MRP:900");
System.out.println("5.PUMA FOOTBALL SHOES ----------MRP:500");
System.out.println("6.ADDIDAS FOOTBALL SHOES ------MRP:500");
System.out.println("7.GOLD TOE OFFICE SHOES -------MRP:750");
System.out.println("8.HOME SLIPPERS --------------- MRP:900");
System.out.println("9.BOOT ----------------------- MRP:5000");
System.out.println("10.VANS SHOES ---------------- MRP:750");
}
private void checkname()
{
name = in.nextLine();
try
{
char name0[]=name.toCharArray();
for(char a : name0)
{
if(Character.isDigit(a))
throw new Numberlargerexception();
}
}
catch (Numberlargerexception e)
{
System.out.print("Your name contains digit\nRe-Enter Name:");
checkname();
}
}
public void Check()
{
boolean ny = true;
while(ny == true)
{
String c = in.nextLine();
try
{
C = Integer.parseInt(c);
if(C>3 || C<1)
throw new Numberlargerexception();
ny=false;
}
catch(NumberFormatException e)
{
System.out.print("Invalid Choice!! Please enter valid choice\n");
}
catch (Numberlargerexception e)
{
System.out.print("Invalid Choice!! Please enter valid choice\n");
}
}
}
}
Numberlargerexception Class
package assignment;
public class Numberlargerexception extends Exception {
Numberlargerexception()
{
super("Error");
}
}
interface printingSystem
package assignment;
public interface printingSystem
{
void printRecipe(String nam, int iB, int Sn);
void printRecipe(int Sn);
}
output 1:
Output 2:
Write a program to do the following task:
A. Asks a student if he/she is full-time or part-time.
B. If the student is full-time, the program will ask for the student's major and print the input for major followed by "is a good major" to the screen. If the student is not full-time, the program will ask the student how many credits he/she is taking. If the student is taking more than 6 credits, the program will print "That is a lot for a part-time student" to the screen. If the student is taking 6 or less credits, the program will print "That is nice" to the screen.
Structure in C-1
Question: Write a program in C using struct for displaying results in order for 3 students.The program used include name,marks in 6 subjects,total and average. it should print result in table form
#include <stdio.h>
#include <stdlib.h>
struct
{
char fn[12],ln[8];
int sn,cpl,che,mat,egp,phy,acs,t;
float per;
}student[2];
int main()
{
int i=0,tmp,j=0;
for(i=0;i<3;i++)
{
printf("Enter student %d first name:",i+1);
scanf("%s",student[i].fn);
printf("Enter student %d second name:",i+1);
scanf("%s",student[i].ln);
printf("Enter student number:");
scanf("%d",&student[i].sn);
printf("Enter CPL101 marks:");
scanf("%d",&student[i].cpl);
printf("Enter CHE101 marks:");
scanf("%d",&student[i].che);
printf("Enter MAT101 marks:");
scanf("%d",&student[i].mat);
printf("Enter EGP101 marks:");
scanf("%d",&student[i].egp);
printf("Enter PHY101 marks:");
scanf("%d",&student[i].phy);
printf("Enter ACS101 marks :");
scanf("%d",&student[i].acs);
student[i].t = student[i].acs+student[i].phy+student[i].mat+student[i].che+student[i].egp+student[i].cpl;
student[i].per=student[i].t/6;
}
for(i=0; i<3; i++)
{
for(j=i+1; j<=3; j++)
{
if(student[i].per <student[j].per)
{
tmp = student[i].per;
student[i].per = student[j].per;
student[j].per = tmp;
}
}
}
printf("\nstd.no name cpl che mat egp phy acs total per\n");
for(i=0; i<3; i++)
{
printf("%d\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%f\n",student[i].sn,student[i].fn,student[i].ln,student[i].cpl,student[i].che,student[i].mat,student[i].egp,student[i].phy,student[i].acs,student[i].t,student[i].per);
}
}
Output
WAP in Java Using all the concepts of OOP,Exception handling and Packages -I
Aim: To create a program to allow people to register for credit management system and print their information and prompt user to register for the program.
Background:
Credit management system program is made to help people register for a system and hence it can be
implement as a backend code for many programs be it bank system, blood donation systems, school
admission system and many more other systems. The codes contains complete information and also the
password is set to private to ensure security. Almost all the parameters have exception handling and hence
it ensures all the information given by the user is correct up to some level.
Objective:
To allows users to register for a system and print their details and ask for confirmation for registration
Code Explaination: There are 2 packages default package and register package
mainBody Class
it contains 3 methods and the main method is present here
import java.util.Scanner;
import register.ShopRegis;
import register.StudentRegister;
public class mainBody {
static Scanner s = new Scanner(System.in);
public static void main(String[] args)
{
Intro obj = new Intro();
String x = s.nextLine();
obj.choose(x);
if(obj.y==1)
{
StudentRegister s1 = new StudentRegister();
s1.getname();
s1.getSname();
s1.Studentno();
s1.Collegename();
s1.emailadress();
s1.setPassword(null);
for(int i =0;i<50;i++)
{
if(i==25)
System.out.print("Showing Details");
else
System.out.print("*");
}
obj.showDetails(s1.name,s1.Sname,s1.snum, s1.strnum, s1.email,s1.getPassword());
Sure();
}
else if(obj.y==2)
{
ShopRegis s1 = new ShopRegis();
s1.getname();
s1.getSname();
s1.phonenum();
s1.Lis();
s1.Location();
s1.setPassword(null);
for(int i =0;i<50;i++)
{
if(i==25)
System.out.print("Showing Details");
else
System.out.print("*");
}
obj.showDetails(s1.name,s1.Sname,s1.p, s1.Lnum,s1.phone,s1.getPassword());
Sure();
}
else
{
finalmessage();
}
}
private static void Sure()
{
for(int i =0;i <50;i++)
{
if(i==25)
System.out.print("Are you Sure you want to register");
else
System.out.print("*");
}
System.out.println("\n press 1 to register else press anybutton");
String co = s.nextLine();
try
{
int x =Integer.parseInt(co);
if(x==1)
{
for(int i =0;i <50;i++)
{
if(i==25)
System.out.print("Registered");
else
System.out.print("*");
}
}
else
{
for(int i =0;i <50;i++)
{
if(i==25)
System.out.print("Not-Registered");
else
System.out.print("*");
}
}
finalmessage();
}
catch(NumberFormatException e)
{
for(int i =0;i <50;i++)
{
if(i==25)
System.out.print("Not-Registered");
else
System.out.print("*");
}
finalmessage();
}
}
private static void finalmessage()
{
System.out.print("\n");
for(int i =0; i <55; i++)
{
if(i == 20)
System.out.print("Thankyou For Using Our Service");
else
System.out.print("*");
}
}
}
invalidinputException
it contain a constructor and whenever an custom made Exception is catched in the default package the program comes to this method
public class invalidinputException extends Exception {
invalidinputException()
{
super("Invalid Input");
}
}
Intro Class
This class contains 3 methods and 1 constructor, it implements an interface
import java.util.Scanner;
public class Intro implements Details {
String name,em,Pa;
int Stdno;
int y = 0;
Intro()
{
for(int i = 0; i <50;i++)
{
if(i==20)
System.out.print("Welcome to Credit management System");
else
System.out.print("*");
}
System.out.println("\nPress 1. for student Registration \nPress 2. for customer Registration \npress 0. to cancel Registration");
}
public int choose( String x)
{
Scanner s = new Scanner(System.in);
{
try
{
y = Integer.parseInt(x);
if(y!=1 && y!=2 && y!=0)
throw new invalidinputException();
return y;
}
catch(invalidinputException e)
{
System.out.print("Invalid input");
String X = s.nextLine();
choose(X);
}
catch(NumberFormatException e)
{
System.out.println("Invalid Input");
String X = s.nextLine();
choose(X);
}
}
return y;
}
@Override
public void showDetails(String fn, String sn, String snum, int Sn, String em, String pas) {
name = fn + sn;
System.out.println("\n1.Name:" + name + "\n2.Student Number:" + Sn + "\n3.College name:" + snum + "\n4.EmailAdress:" + em + "\n5.password:" + pas );
}
public void showDetails(String fn, String sn, String Loc, int Ln, int pn, String pas)
{
name = fn + sn;
System.out.println("\n1.Name:" + name + "\n2.Liscence No:" + Ln + "\n3.Adress:" + Loc + "\n4Phone Number:"+ pn + "\n5.password:" + pas );
}
}
Interface Details
This interface contains two methods
public interface Details {
void showDetails(String fn, String sn, String Loc, int Ln, int pn, String pas);
void showDetails(String fn, String sn, String snum, int Sn, String em, String pas);
}
Under the register package there are 4 classes
1 class contains common registration parameter other 2 contains parameters different for student and canteen owners and the clas class implements the exception
Common_Registration
package register;
import java.util.Scanner;
public class Common_Register
{
Scanner s = new Scanner(System.in);
public String name;
public String Sname;
private String Password;
public void getname()
{
System.out.print("Enter Your First Name:");
name = s.nextLine();
try
{
for(int i =0; i <name.length(); i++)
{
for(char j =0; j <65 ; j++ )
{
if(name.charAt(i) == j)
{
throw new ErrorException();
}
}
}
}
catch (ErrorException e)
{
System.out.println("Please enter name Correctly");
getname();
}
}
public void getSname()
{
System.out.print("Enter Your Second Name:");
Sname = s.nextLine();
try
{
for(int i =0; i <Sname.length(); i++)
{
for(char j =0; j <65 ; j++ )
{
if(Sname.charAt(i) == j)
{
throw new ErrorException();
}
}
}
}
catch (ErrorException e)
{
System.out.println("Please enter name Correctly");
getSname();
}
catch(Exception e)
{
System.out.println("Please enter name Correctly");
getSname();
}
}
public String getPassword() {
return Password;
}
public void setPassword(String password)
{
String np = null;
{
while(password == null)
{
System.out.print("Enter Password:");
password = s.nextLine();
if(password.length() <8 )
{
System.out.println("Password is too weak");
setPassword(null);
}
else
{
System.out.print("Re-Enter Password:");
np = s.nextLine();
checkpassword(password,np);
}
}
}
}
private void checkpassword(String password2, String np)
{
if(password2.matches(np))
{
this.Password = password2;
}
else
{
System.out.print("PASSWORD MISMATCH\n");
setPassword(null);
}
}
}
ShopRegis class
package register;
public class ShopRegis extends Common_Register
{
public String p;
public int phone;
public int Lnum;
public void phonenum()
{
boolean choice =true;
while(choice == true)
{
System.out.print("Enter your Phone number:");
p = s.nextLine();
try
{
phone = Integer.parseInt(p);
if(phone/100000000 > 1 || phone/10000000!=1 && phone/10000000!=7 || phone/1000000!=17 && phone/1000000 !=77 )
{
throw new ErrorException();
}
else
choice = false;
}
catch(NumberFormatException e)
{
System.out.println("Invalid phone number");
}
catch(ErrorException e)
{
System.out.println("Invalid phone number");
}
}
}
public void Lis()
{
boolean choice =true;
while(choice == true)
{
System.out.print("Enter your Liscence number:");
p = s.nextLine();
try
{
Lnum= Integer.parseInt(p);
choice = false;
}
catch(NumberFormatException e)
{
System.out.println("Invalid Liscence number");
}
}
}
public void Location()
{
System.out.print("Enter your Canteen Location:");
p=s.nextLine();
}
}
StudentRegister Class
package register;
public class StudentRegister extends Common_Register
{
public String snum;
public int strnum;
public String email;
boolean check = false;
public void Studentno()
{
while(check == false)
{
System.out.print("Enter Student Number:");
snum = s.nextLine();
try
{
strnum = Integer.parseInt(snum);
check = true;
}
catch(Exception e)
{
System.out.println("Student number should be an integer value!!");
}
}
}
public void Collegename()
{
System.out.print("Enter Your college's Abbreviation:");
snum = s.nextLine();
try
{
for(int i =0;i <snum.length();i++)
{
for(char j =0; j <65 ; j++)
if(snum.charAt(i) == j)
{
throw new ErrorException();
}
}
}
catch(ErrorException e)
{
System.out.println("Invalid College Name");
Collegename();
}
}
public void emailadress()
{
while(check == true)
{
System.out.print("Enter Your Email Adress:");
email = s.nextLine();
for(int i =0;i <email.length();i++) {
if(email.charAt(i) == '@')
{
check = false;
}
}
if(check == true)
{
System.out.println("Email adress should contain @");
emailadress();
}
}
}
}
ErrorException
package register;
public class ErrorException extends Exception
{
public ErrorException()
{
super("Error");
}
}
OUTPUTS:
Print Hello World! without semicolon
Printing Helloworld!
Print total odd numbers from 1 to n
Print total odd numbers from 1 to n
Teachers Day card in java
"As each child grows older, he/she needs to learn in order to survive; teachers are the ones to instill knowledge (DeRoy)." Therefore i have made a simple java program using Swings to wish all the teachers a very happy teachers Day.
Code Explaination
In this code there are 3 classes:
1.teacher class
2.Registration
3.WiishCard classes
The teacher class contains the main method, Registration class contain codes that allows user to register and the wiish class contains the wish for the teacher
Teacher Class
public class teacher
{
public static void main(String[] args)
{
Registration R1 = new Registration();
R1.Details();
}
}
Registration class
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
public class Registration extends JFrame
{
private static final long serialVersionUID = -7614034343348966109L;
Registration()
{
setVisible(true);
setTitle("Register");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 570, 430);
}
JPanel cP;
JLabel l1,L2,L3,L4;
public JRadioButton r1,r2;
JTextField t1,t2;
JButton jb1;
public void Details()
{
cP = new JPanel();
cP.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(cP);
cP.setLayout(null);
l1 = new JLabel("REGISTER");
l1.setForeground(Color.BLUE);
l1.setFont(new Font("Times New Roman", Font.PLAIN, 30));
l1.setBounds(170, 11, 170, 44);
cP.add(l1);
L2 = new JLabel("Tutor Name:");
L2.setForeground(Color.BLUE);
L2.setFont(new Font("Times New Roman", Font.PLAIN, 20));
L2.setBounds(10, 152, 163, 44);
cP.add(L2);
L3 = new JLabel("Tutor Gender:");
L3.setForeground(Color.BLUE);
L3.setFont(new Font("Times New Roman", Font.PLAIN, 20));
L3.setBounds(10, 207, 163, 44);
cP.add(L3);
L4 = new JLabel("Student Name:");
L4.setForeground(Color.BLUE);
L4.setFont(new Font("Times New Roman", Font.PLAIN, 20));
L4.setBounds(10, 262, 163, 44);
cP.add(L4);
r1 = new JRadioButton("Male");
r1.setFont(new Font("Times New Roman", Font.PLAIN, 20));
r1.setBounds(153, 220, 109, 23);
cP.add(r1);
r2 = new JRadioButton("Female");
r2.setFont(new Font("Times New Roman", Font.PLAIN, 20));
r2.setBounds(296, 218, 109, 23);
cP.add(r2);
t1 = new JTextField();
t1.setBounds(153, 166, 219, 20);
cP.add(t1);
t1.setColumns(10);
ButtonGroup bg = new ButtonGroup();
bg.add(r1);
bg.add(r2);
jb1 = new JButton("WISH");
jb1.setFont(new Font("Times New Roman", Font.PLAIN, 15));
jb1.setBounds(193, 336, 109, 31);
cP.add(jb1);
jb1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
wish();
WiishCards n1 = new WiishCards();
String a,b;
if(r1.isSelected())
{
a= t1.getText();
a = "Sir " + a;
}
else
{
a=t1.getText();
a = "Madam " + a;
}
b = t2.getText();
n1.wish(a,b);
}
private void wish()
{
setVisible(false);
}
});
t2 = new JTextField();
t2.setColumns(10);
t2.setBounds(153, 276, 219, 20);
cP.add(t2);
}
}
WiishCard class
import java.awt.Color;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class WiishCards extends JFrame
{
public WiishCards()
{
setVisible(true);
setTitle("Wishing Cards");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 570, 430);
}
public void wish(String a, String b )
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 570, 430);
getContentPane().setLayout(null);
JLabel l2= new JLabel("HAPPY TEACHERS DAY ");
l2.setFont(new Font("MV Boli", Font.PLAIN, 35));
l2.setForeground(Color.BLUE);
l2.setBounds(39, 24, 478, 47);
getContentPane().add(l2);
JLabel l1 = new JLabel();
l1.setText(a);
l1.setFont(new Font("Tempus Sans ITC", Font.BOLD | Font.ITALIC, 30));
l1.setForeground(Color.BLUE);
l1.setBounds(39, 82, 478, 38);
getContentPane().add(l1);
JLabel L3 = new JLabel("THANKYOU ");
L3.setForeground(Color.GREEN);
L3.setFont(new Font("Viner Hand ITC", Font.PLAIN, 26));
L3.setBounds(177, 131, 166, 55);
getContentPane().add(L3);
JLabel l4= new JLabel("For teaching us efficiently even during hard times)");
l4.setForeground(Color.MAGENTA);
l4.setFont(new Font("Viner Hand ITC", Font.PLAIN, 17));
l4.setBounds(20, 189, 434, 70);
getContentPane().add(l4);
JLabel l5 = new JLabel("it has been an honor to get to learn so many things from you");
l5.setForeground(Color.MAGENTA);
l5.setFont(new Font("Viner Hand ITC", Font.PLAIN, 17));
l5.setBounds(26, 231, 505, 75);
getContentPane().add(l5);
JLabel l6 = new JLabel();
l6.setText("Wish From: " + b);
l6.setForeground(Color.GREEN);
l6.setFont(new Font("Times New Roman", Font.PLAIN, 15));
l6.setBounds(53, 317, 434, 63);
getContentPane().add(l6);
}
}
output
PatternPrinting-2
Pattern2
PatternPrinting-1
Pattern1
Why We Should Let Youths Use Social Media
Social media is a very vital thing in this 21st century for many people. Facebook, WhatsApp, Messenger, WeChat, and Instagram are just some of the common social networking sites used by many people. Although some people say that social media is a boon in this digital era, still few consider it as a curse.
It is said that using too much social media can lead to breakup in their family, social media can bring a good deal of fake news if we don’t check the sources from where the news are being shared. However, one cannot deny the fact that social media is very helpful in today’s scenario. It helps us get news faster, make new friends and also useful for learning new things. Indeed, social media is a boon rather than a curse.
Research show that people who use social media frequently are more intelligent than those who don’t use social media frequently because social media is the fastest way of getting any information. Studies have also proven that social media and fake news are related, and reports indicate that approximately 35% of the information in social media is fake. Due to this fake news it usually creates chaos among the people. Although, the information in social media spreads like wildfire, one cannot deny the fact that about 65% of the information in social media are true. People argue that the 35% of the fake news will not affect the people but instead the 65% true news will help people learn new things explore the whole world and its culture, history, geographic conditions, via social media and hence increase knowledge.
So why not we let the youths use social media, as social media is not a curse but a boon in this digital era.
Make Registration form using only AWT
Java AWT (Abstract Window Toolkit) is an API to develop GUI in java.
it has many components like button, label, checkbox, etc. used as objects inside a Java Program.Java AWT components are platform-dependent which implies that they are displayed according to the view of the operating system. It is also heavyweight . java. awt package provides classes for AWT api.
In this program i have made a simple registration form with Awt as its major components and also used Swings combo box to get year of study.
In this program there are two classes : 1. Registration class which contains the main method and the details class which does the rest of the work
Output
Registration class
public class Registration
{
public static void main(String[] args)
{
Details d1 = new Details();
d1.Register();
}
}
detailsClass
import java.awt.*;
import java.awt.event.*;
import javax.swing.JComboBox;
public class Details extends Frame implements ActionListener
{
TextField t1;
static JComboBox jc1;
String[] s = new String[9];
static Checkbox cb1,cb2;
CheckboxGroup cbg;
Button b;
Details()
{
setVisible(true);
setBounds(100,50,700,500);
setTitle("Registration Form");
setLayout(null);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
dispose();
}
});
}
void Register()
{
setLayout(null);
Font f = new Font("Arial",Font.BOLD,20);
Label l1 = new Label("Registration Form");
l1.setBounds(250, 50, 400, 40);
l1.setForeground(Color.BLUE);
l1.setFont(f);
Label l2 = new Label("Student_Id:");
l2.setBounds(50, 100, 60, 20);
t1 = new TextField();
t1.setBounds(150, 100, 120, 20);
Label l3 = new Label("Semester:");
l3.setBounds(50, 150, 60, 20);
for(int i=1; i<=8;i++)
{
s[i] = i+" semester";
}
jc1 = new JComboBox(s);
jc1.setBounds(150, 150, 120, 20);
Label l4 = new Label("Type:");
l4.setBounds(50, 200, 60, 20);
Label l5 = new Label("Type of study:");
l5.setBounds(50, 210, 80, 20);
cbg = new CheckboxGroup();
cb1 = new Checkbox("GOVERNMENT",cbg,false);
cb2 = new Checkbox("SELF",cbg,false);
cb1.setBounds(140, 210, 100, 20);
cb2.setBounds(240, 210, 100, 20);
b = new Button("Register");
b.setBounds(150, 250, 50, 20);
b.addActionListener(this);
add(l1);
add(l2);
add(t1);
add(l3);
add(jc1);
add(l5);
add(cb1);
add(cb2);
add(b);
}
@Override
public void actionPerformed(ActionEvent e)
{
Label l = new Label("PRINTING DETAILS");
l.setBounds(250, 300, 100, 30);
l.setForeground(Color.BLUE);
Label l2 = new Label();
l2.setBounds(50, 320, 150, 30);
Label l3 = new Label();
l3.setBounds(50, 340, 180, 30);
Label l4 = new Label();
l4.setBounds(50, 360, 180, 30);
Label l5 = new Label();
l5.setBounds(50, 380, 180, 30);
int student =Integer.parseInt(t1.getText());
int fees = 0;
String Sem = (String) jc1.getSelectedItem();
if(cb1.getState()==true)
{
if(Sem.contains("1") || Sem.contains("2"))
fees=100*2;
if(Sem.contains("3") || Sem.contains("4"))
fees=100*4;
if(Sem.contains("5") || Sem.contains("6"))
fees=100*6;
if(Sem.contains("7") || Sem.contains("8"))
fees=100*8;
}
else if(cb2.getState()==true)
{
if(Sem.contains("1") || Sem.contains("2"))
fees=50000*2;
if(Sem.contains("3") || Sem.contains("4"))
fees=40000*4;
if(Sem.contains("5") || Sem.contains("6"))
fees=30000*6;
if(Sem.contains("7") || Sem.contains("8"))
fees=20000*8;
}
l2.setText("Student Number:" + student+" ");
l3.setText("Type : Government Scholarship");
l4.setText("Semester: " + Sem);
l5.setText("Total Amount to be paid:" + fees);
add(l);
add(l2);
add(l3);
add(l4);
add(l5);
}
}