Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
34 views

Java Ass

The document discusses a Java program to register and login users with validation of inputs like password and confirm password matching and unique emails. It also includes a question on creating two classes - Friend and Buddy where Buddy inherits from Friend and adds more data members and methods to display user details.

Uploaded by

rupeshpawar0086
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Java Ass

The document discusses a Java program to register and login users with validation of inputs like password and confirm password matching and unique emails. It also includes a question on creating two classes - Friend and Buddy where Buddy inherits from Friend and adds more data members and methods to display user details.

Uploaded by

rupeshpawar0086
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Jethva Devang SUB : JAVA Programming

Q.1 : Write a code in java for input First name,Last Name, Gender, Email, Password,Confirm Password,
Country, State, City. Also provide following facilities given in Following menu.

Press [1] Register

Press [2] Login

-For Register following criteria should beconsidered.

- Password and Confirm Password must be the same.

- Email id must be unique for each user.

Ans:

import java.io.*; class

register

String Name,Gender,Email,Password,Confirm_Password,Country,State,City; public

register()

Name="";

Gender="";

Email="";

Password="";

Confirm_Password="";

Country="";

State="";

City="";

1|Page
Kakadiya Maulik V. SUB : JAVA Programming

public register(String Name1,String Gender1,String Email1,String Password1,String


Confirm_Password1,String country1,String State1,String City1)

Name=Name1;

Gender=Gender1;

Email=email1;

Password=Password1;

Confirm_Password=Confirm_Password1;

Country=Country1;

State=State1;

City=City1;

public void dis()

System.out.println(Name+"\t",Gender+"\t",Email+"\t",Password+"\t",Confirm_Passwor
d+"\t",Country+"\t",State+"\t",City);

};

class login

public static void main(String o[])throws IOException

2|Page
Kakadiya Maulik V. SUB : JAVA Programming

register[] b=false;

int ch=0,f=0;

int len; char[] temp=new

char[15];

BufferedReader j=new BufferedReader(new InputStreamReader(System.in));

String Name,Gender,Email,Password,Confirm_Password,Country,State,City;

do

System.out.println("1.Register");

System.out.println("2.Login");

System.out.println("3.Exit");

System.out.println("\nEnter Your Choice");

ch=Integer.parseInt(j.readLine());

switch(ch)

case 1:

System.out.println("Enter Mail");

Email=j.readLine();

System.out.println("Enter Name");

3|Page
Kakadiya Maulik V. SUB : JAVA Programming

Name=j.readLine();

do

b=false;

System.out.println("Enter Gender (M/F)"); Gender=j.readLine();

if

Gender.equals("m") || Gender.equals("M") || Gender.equals("f") || Gender.equals("F")

b=true;

while(b!=true);

System.out.println("Enter Password");

pass=j.readLine();

do

b=false;

System.out.println("Enter Confirem Password");

cpass=j.readLine();

if

4|Page
Kakadiya Maulik V. SUB : JAVA Programming

cpass.equals(pass)!=true

System.out.println("Invalid Confirm Password");


b=true;

while(b==true);

System.out.println("Enter Counter");

cnt=j.readLine();

System.out.println("Enter City");

City=j.readLine();

System.out.println("Enter State");

State=j.readLine();

obj[f]=new
register(Name,Gender,Email,Password,Confirm_Password,Country,State,City);

f++;

break;

case 2:

System.out.println("Enter Resister id");

5|Page
Kakadiya Maulik V. SUB : JAVA Programming

Email=j.readLine();

b=false;

for(int k=0;k<f;k++)

if(Email.equals(obj[k].Email)==true)

System.out.println("Enter Password");
pass=j.readLine();

if(pass.equals(obj[k].pass)==true)

System.out.println("Login
Succesfully");

System.out.println("\n\nName\Gender\nEmail\nPassword\
nConfirm_Password,Country ,State,City");

obj[k].dis();

b=true;

while(b==false)

case 0:

System.Exit(0);

6|Page
Kakadiya Maulik V. SUB : JAVA Programming

while(ch!=3);

Q.7 : Create a two class one is Friend and another is Buddy, Friend class has data member like
name and email id, and Buddy class inherit the properties of Friend class and it has data member
like dob, mobile no and address and do the following operation.

a. Create three constructor for base and derived class.

b. Insert data throught derived class parameterized constructor.

c. Illustrate the use of this reference and super.

d. Display all the information through parent class reference variable.

Ans :

import java.lang.*;

import java.io.*;

class friend

String name,email; public

friend()

7|Page
Kakadiya Maulik V. SUB : JAVA Programming

name=null;

email=null;

public friend(String fname,String femail)

name=fname;

email=femail;

public void dis_friend()

System.out.println("\n\nname ="+name+"\n\nemail ="+email);

};

class Buddy extends friend

String dob,add,mno; public

buddy()

dob=null;

add=null; mno=null;

public buddy(String bdob,String bmno,String fname,String femail)

8|Page
Kakadiya Maulik V. SUB : JAVA Programming

super(fname,femail);

dob=bdob;

add=badd; mno=bmno;

public void dis_buddy()

super.dis_friend();

System.out.println("\ndob ="+dob+"\n\naddress ="+add+"\nmno


="+mno+"\n\n\n");

};

class mainbuddy

public static void main(String o[])

buddy obj1=new buddy();

buddy obj2=new buddy ("04-06-


1999","surat","+911111111111","om","ABCDEFG.HI");

obj2.dis_buddy();

9|Page
Kakadiya Maulik V. SUB : JAVA Programming

24. Write a java applet program to draw Micky mouse.

import java.io.*; import java.applet.*; import java.awt.*;

import java.util.*; public class Mickymouse extends Applet

implements Runnable

Thread t; int a=1,h=1;

public void init()

setBackground(Color.red);

public void start()

10 | P a g e
Kakadiya Maulik V. SUB : JAVA Programming

Thread t=new Thread(this);

t.start();

public void run()

try {

while(true)

repaint();

t.sleep(100);

catch(Exception e)

public void paint(Graphics g)

g.setColor(Color.black);

11 | P a g e
Kakadiya Maulik V. SUB : JAVA Programming

g.fillOval(380,95,150,150);

g.fillOval(720,95,150,150);

g.setColor(Color.red);

g.fillOval(440,159,80,80);

g.fillOval(733,159,80,80);

g.setColor(Color.orange);

g.fillOval(400,160,450,450);

g.setColor(Color.white);

g.fillOval(490,255,80,130);

g.fillOval(665,255,80,130);

g.setColor(Color.black);

g.fillOval(512,322,40,60);

g.fillOval(688,322,40,60);

g.fillOval(595,400,55,55);

g.drawArc(550,430,140,120,0,-180);

try{

if(h==1)

t.sleep(500);

g.setColor(Color.black);

g.drawArc(550,430,140,120,0,-180);

g.fillOval(512,322,40,60);

g.fillOval(688,322,40,60);

12 | P a g e
Kakadiya Maulik V. SUB : JAVA Programming

h--;

if(h==0)

t.sleep(200);

g.setColor(Color.white);

g.drawArc(550,430,140,120,0,-180);

g.fillOval(512,322,40,60);

g.fillOval(688,322,40,60);

h++;

catch(Exception e)

try

if(a==1)

t.sleep(200);

g.setColor(Color.black);

13 | P a g e
Kakadiya Maulik V. SUB : JAVA Programming

g.drawArc(550,430,140,120,0,-180);

a--;

if(a==0)

t.sleep(500);

g.setColor(Color.red);

g.drawArc(550,430,140,120,0,180);

a++;

catch(Exception e)

<html>

<body>

<applet code="applet3.java" width="600" height="550">

</applet>

</body>

</html>

14 | P a g e
Kakadiya Maulik V. SUB : JAVA Programming

25.Write a java applet program to draw digital wall clock which display real time.

import java.lang.Exception; import java.lang.Runnable;

import java.io.*; import java.applet.*; import java.awt.*;

import java.util.*; import java.text.*; public class

Digitalclock extends Applet implements Runnable

Thread t; int

h=0,m=0,s=0;

String timestring="";

public void init()

15 | P a g e
Kakadiya Maulik V. SUB : JAVA Programming

setBackground(Color.green);

public void start()

t=new Thread(this);

t.start();

public void run()

try

while(true)

Calendar cal=Calendar.getInstance();

h=cal.get(Calendar.HOUR_OF_DAY);

if(h>12)

h=h-12;

m=cal.get(Calendar.MINUTE);

s=cal.get(Calendar.SECOND);

SimpleDateFormat sobj=new

SimpleDateFormat("hh:mm:ss"); Date dobj=cal.getTime();

timestring=sobj.format(dobj);

16 | P a g e
Kakadiya Maulik V. SUB : JAVA Programming

repaint();

t.sleep(1000);

catch(Exception e)

17 | P a g e
Kakadiya Maulik V. SUB : JAVA Programming

27.write java applet pogram to draw image.

import java.awt.*; import

java.applet.*; public class imagerx

extends Applet

Image picture;

public void init()

picture = getImage(getDocumentBase(),"myimage.jpg");

public void paint(Graphics g)

g.drawImage(picture, 50,50,this);

18 | P a g e

You might also like