Assignments

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 24

Assignment

Rani:
Assignment 1: Take the number from end user check it is even or odd?

import java.util.Scanner;
class FlowControlStatements
{ public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
System.out.println("Enter a num:");
int num = s.nextInt();

if (num%2==0)
{ System.out.println("Number is Even....");
}
else
{ System.out.println("Number is Odd....");
}
s.close();
}
}

O/P:

Enter a num:
09
Number is Odd....

Assignment 2: Take the two numbers from end user print the bigger number?

import java.util.Scanner;
class FlowControlStatements
{ public static void main(String[] args)
{

Scanner s = new Scanner(System.in);


System.out.println("Enter a num1:");
int num1 = s.nextInt();
System.out.println("Enter a num2:");
int num2 = s.nextInt();

if (num1>num2)
{ System.out.println("Number1 is Greater...."+num1);
}
else
{ System.out.println("Number2 is Greater."+num2);
}
s.close();
}
}

O/P:
Enter a num1:
66
Enter a num2:
88
Number2 is Greater.88

Assignment 3: Take the year from end user check it is leap year or not?

import java.util.Scanner;
class FlowControlStatements
{ public static void main(String[] args)
{
int year;
Scanner s = new Scanner(System.in);
System.out.println("Enter year");
year = s.nextInt();

if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))


{

System.out.println(year + " : Leap Year");


}

else {

System.out.println(year + " : Non - Leap Year");


}
}
}

O/P:
Enter year
2000
2000 : Leap Year

Assignment 4: Take the user name & password from end user.
Check the condition print the the message login Success or
fail.
import java.util.Scanner;
class FlowControlStatements
{ public static void main(String[] args)
{
String uname;
String pwd;
Scanner s = new Scanner(System.in);
System.out.println("Enter user name:");
uname = s.next();
System.out.println("Enter password");

pwd=s.next();

if (uname.equals("Rani") && pwd.equalsIgnoreCase("PassworD"))


{
System.out.println("login is success "+uname);
}

else {
System.out.println("Login fail");
}
}
}
//O/P:Enter user name:
// Rani
// Enter password
// PASSWORD
// login is success Rani

Assignment-5: what is the difference between next() & nextLine() write one
example.
s.next() : It read input from the input device till the space character.

s.nextLine() : It read input from the input device till the line
change.

Java class Assignment-1

class FlowControlStatements
{
static int num1=22,num2=12;
static void add()
{

System.out.println(FlowControlStatements.num1+FlowControlStatements.num2);
}
static void mul()
{
System.out.println(FlowControlStatements.num1*FlowControlStatements.num2);

}
public static void main(String[] args)
{
FlowControlStatements.add();
FlowControlStatements.mul();
}
}

class FlowControlStatements
{
int num1=40;
int num2=70;
static void add()
{
FlowControlStatements t=new FlowControlStatements();

System.out.println(t.num1+t.num2);

}
static void mul()
{ FlowControlStatements t=new FlowControlStatements();

System.out.println(t.num1*t.num2);
}
public static void main(String[] args)
{
FlowControlStatements.add();
FlowControlStatements.mul();
}
}

class FlowControlStatements
{
public static void main(String[] args)

{
Services s=new Services();
s.voteRegister("Rekha","hyderabad",90309464,19,741258); // call
the voteRegister by passing the argument.
Services.marry("Ram",100,10000.00);// call the marry method by
passing the arguments.

}
}

package com.ratan.sessions;

class Services
{

String name;
String location;
long mobile;
long age;
long sscRoolNo;

void voteRegister(String name,String location,long mobile,int age,long


sscRoolNo)
{

if(age>18)
{
if(location=="hyderabad")
{
long res=mobile+sscRoolNo+age;
System.out.println("Eligible for voting"+res);
//System.out.println(mobile+sscRoolNo+age);
}

else
{
System.out.println("Location doesn't support");
}
}
else
{
System.out.println("Age doesn't support"+age);
}
}
static void marry(String mname,int mage,double bankBalance)
{
if(mage>=18 && mage<=34)

{
System.out.println("Eligible for marriage" +mage);
}

else if (mage<18)
{
System.out.println("not eligible try after some time "
+mage);
}
else
{
System.out.println("Sorry your tooooo late ..... " +mage);
}

}
}

26-04-2021

package com.tcs.data.instancedata;

public class Test {


public int a;
public void add(int a)
{
this.a=a;
System.out.println("Add method starts"+a);
}

package com.tcs.data.staticdata;

public class Demo {


public static String cname;

public static void companyName(String cname)


{

System.out.println("company name "+cname);

}
}

package com.tcs.data.client;
import com.tcs.data.instancedata.Test;
import com.tcs.data.staticdata.Demo;

public class TestClient {

public static void main(String[] args) {


Test t=new Test();
t.add(10);

Demo.companyName("TCS");
}

Siva kumar:

Usman:

Guru Assignment:-

Assignment 1: Take the number from end user check it is even or odd?
Ans:-
=====
package Guru.Rat.Com;

import java.util.Scanner;
public class OddEven {
public static void main(String[] args){
Scanner s=new Scanner(System.in);

System.out.println("Please Enter your Number :-");


int num=s.nextInt();

if (num %2 == 0)
{
System.out.println("The Given Number "+num+" is even number");
}
else
System.out.println("The Given Number "+num+" is Odd number");
s.close();
}

Assignment 2: Take the two numbers from end user print the bigger number?
Ans:-
====
package Guru.Rat.Com;

import java.util.Scanner;
public class BigNum {
public static void main(String[] args){
Scanner s=new Scanner(System.in);

System.out.println("Please Enter your First Number :-");


int num1=s.nextInt();

System.out.println("Please Enter your Second Number :-");


int num2=s.nextInt();

if (num1 > num2)


{
System.out.println("The Given First Number "+num1+" is Bigger");
}
else
System.out.println("The Given Second Number "+num2+" is
Bigger");
s.close();
}

Assignment 3: Take the year from end user check it is leap year or not?
Ans
===
package Guru.Rat.Com;

import java.util.Scanner;
public class LeapOrNot {

public static void main(String[] args){


Scanner s=new Scanner(System.in);
System.out.println("Please Enter the year :-");
int year=s.nextInt();

if ((year %4==0) &&((year %100!=0))||(year%400 == 0)){


System.out.println("Mentioned year is a leap year");
}
else
System.out.println("Mentioned year is not a leap year");
s.close();

}
}

Assignment 4: Take the user name & password from end user.
Check the condition print the the message login Success or
fail.
Ans
===
package Guru.Rat.Com;

import java.util.Scanner;
public class UserPwdCheck {
public static void main (String[] args){
Scanner s=new Scanner(System.in);
System.out.println("Enter a user Name:- ");
String uname=s.next();
System.out.println("Enter a password:- ");
String upwd=s.next();

if (uname.equals("ratan") && upwd.startsWith("r")){


System.out.println(uname+ " you are succesfully login as a
Admin");
}
else {

System.out.println(uname + " you are succesfully login as a


Maker");
}
s.close();
}

Assignment-5: what is the difference between next() & nextLine() write one
example.
Ans
====
s.next() : to read the String data --> Next is
print upto space from the input
s.nextLine() : to read the String data. --> NextLine
is print until the line end with space words
package Guru.Rat.Com;

import java.util.Scanner;
public class NextLin {

public static void main (String[] args){

Scanner s=new Scanner(System.in);

System.out.println("Enter your Word :: ");


String nxtline=s.nextLine();
System.out.println("your word in NextLine:- "+nxtline);

System.out.println("Enter your Word :: ");


String nxt=s.next();
System.out.println("your word in Next:- "+nxt);

s.close();

}
}

Assignment-6:
Take the day from end user
mon tue wed : print the Discount 5%
thr fri : print the Discount 4%
sat sun : print the Discount 3%
when user entered wrong data give proper error information.

Ans
===
package Guru.Rat.Com;

import java.util.Scanner;

public class Discount {


public static void main(String[] args) {

Scanner s = new Scanner(System.in);


System.out.println("Please Enter your purchase Day :- ");
String days = s.nextLine();
{
System.out.println("Enter your Purchase Amount :- ");
double bill = s.nextDouble();

if ((days.startsWith("Mon")) || (days.startsWith("Tue"))
|| (days.startsWith("Wed"))) {
double dis1 = bill * 5 / 100;
double pay = bill - dis1;
System.out.println("Your Discount Amount is " + dis1);
System.out
.println("After Discount your bill Amount is "
+ pay);
}

else if ((days.startsWith("Thu")) || (days.startsWith("Fri"))) {


double dis1 = bill * 4 / 100;
double pay = bill - dis1;
System.out.println("Your Discount Amount is " + dis1);
System.out
.println("After Discount your bill Amount is "
+ pay);
} else if ((days.startsWith("Sat")) || (days.startsWith("Sun")))
{
double dis1 = bill * 3 / 100;
double pay = bill - dis1;
System.out.println("Your Discount Amount is " + dis1);
System.out
.println("After Discount your bill Amount is "
+ pay);
} else
System.out.println("Given Day is Wrong");
s.close();
}
}
}

Arshitha

Assignment:1
import java.util.Scanner;
class Assign
{
public static void main(String[] args)
{
Scanner a=new Scanner(System.in);
System.out.println("Enter Number");
int num=a.nextInt();

if (num%2==0)
{
System.out.println("Your number is even");
}
else
{
System.out.println("Your number is odd");

}
a.close();
}

Assignment:2

import java.util.Scanner;
class Assign1
{
public static void main(String[] args)
{
Scanner b=new Scanner(System.in);
System.out.println("Enter the First Number");
int num1=b.nextInt();
System.out.println("Enter the Second Number");
int num2=b.nextInt();

if(num1>num2)
{
System.out.println("First Number is bigger");
}
else
{
System.out.println("Second Number is bigger");
}

b.close();

}
}

Assignment:3

import java.util.Scanner;
class Assign2
{
public static void main(String[] args)
{
Scanner c=new Scanner(System.in);
System.out.println("Enter the Year");
int year=c.nextInt();
if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
{
System.out.println("This is leap year");
}
else
{
System.out.println("This is not a leap year");
}
c.close();
}
}

Assignment:4

import java.util.Scanner;
class Assign3
{
public static void main(String[] args)
{
Scanner c=new Scanner(System.in);
System.out.println("Enter the Username");
String uname=c.next();
System.out.println("Enter the Password");
String pwd=c.next();
if(uname.equals("arshi") && pwd.startsWith("r"))
{
System.out.println("Login Success");
}

else
{
System.out.println("Login failure");
}
c.close();

}
}

Guru:
Positive or Negative with Odd or Even numbers

import java.util.Scanner;
public class EvenOrOdd {
public static void main (String[] args){
Scanner s=new Scanner(System.in);

{
System.out.println("Please Enter your Number :: ");
int num=s.nextInt();

if (num >0)
{
System.out.println("Your Number is Positive number.The number
is :: " + num);
if (num %2==0){
System.out.println("and this is a Even Number");
}
else {
System.out.println("and this is a Odd Number");
}
}
else if (num<0)
{
System.out.println("Your Number is Negative number.The number
is :: " + num);
if (num %2==0){
System.out.println("and this is a Even Number");
}
else {
System.out.println("and this is a Odd Number");
}
}
else
{
System.out.println("The Given Number is Zero");
}

}
s.close();
}

Arshitha:

import java.util.Scanner;
class Assign5
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);

System.out.println("Enter the Day");


String str=s.next();
switch(str)
{
case "Mon" :
case "Tue" :
case "Wed" :
case "Thu" :
case "Fri" : System.out.println("Weekdays focus on work");
break;
case "Sat" :
case "Sun" : System.out.println("Weekend enjoy the party");
break;
default : System.out.println("Give the days only from monday-
sunday");
break;

}
s.close();

}
}

*******************************************************************************
Usman: Assignment Date: 06th April 2021

Assignment 1: Take the number from end user check it is even or odd?

import java.util.Scanner;
class Evenodd
{
public static void main(String[] args)
{
System.out.println("Enter the number to know EVEN or ODD");
Scanner s = new Scanner(System.in);
int num = s.nextInt();
if ((num%2)==0)
{
System.out.println("Entered number is EVEN");
}
else
{
System.out.println("Entered number is ODD");
}
s.close();
}
}

Assignment 2: Take the two numbers from end user print the bigger number?

import java.util.Scanner;
class BiggerNum
{
public static void main(String[] args)
{
System.out.println("Enter the FIRST number: ");
Scanner s = new Scanner(System.in);
int num1 = s.nextInt();
System.out.println("Enter the SECOND number: ");
int num2 = s.nextInt();
if (num1>num2)
{
System.out.println(num1+" is bigger");
}
else
{
System.out.println(num2+" is bigger");
}
s.close();
}
}

Assignment 3: Take the year from end user check it is leap year or not?

import java.util.Scanner;
class Leapyear
{
public static void main(String[] args)
{ boolean isleap = false;
int year;
System.out.println("Enter any YEAR");
Scanner s = new Scanner(System.in);
year = s.nextInt();
if(year % 4 == 0)
{
if( year % 100 == 0)
{
if ( year % 400 == 0)
isleap = true;
else
isleap = false;
}
else
isleap = true;
}
else {
isleap = false;
}

if(isleap==true)
System.out.println(year + " is a Leap Year.");
else
System.out.println(year + " is not a Leap Year.");
s.close();
}
}

Assignment 4: Take the user name & password from end user. Check the condition
print the the message login Success or fail.

import java.util.Scanner;
class LoginTest
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
String actualUname = "usmanjava";
String actualPass = "ratansir";
String uname;
String pass;
System.out.println("Enter Username");
uname = s.next();
System.out.println("Enter Password");
pass = s.next();
if (actualUname.equals(uname) && actualPass.equals(pass))
System.out.println("Login Successful");
else
System.out.println("Login Failed");
}
s.close();
}

Assignment-5: what is the difference between next() & nextLine() write one
example.
s.next() : to read the String data
s.nextLine() : to read the String data.

next() can read the input only till the space. It can't read two words separated by
a space. Also, next() places the cursor in the same line after reading the input.

nextLine() reads input including space between the words (that is, it reads till
the end of line). Once the input is read, nextLine() positions the cursor in the
next line.

import java.util.Scanner;
class NextLineNext
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);

System.out.println("Enter your Line: ");


String nxtline=s.nextLine();
System.out.println("Your word in NextLine: "+nxtline);

System.out.println("Enter your Line: ");


String nxt=s.next();
System.out.println("Your word in Next: "+nxt);
s.close();
}
}

Assignment-6:
Take the day from end user
mon tue wed : print the Discount 5%
thr fri : print the Discount 4%
sat sun : print the Discount 3%
when user entered wrong data give proper error information.

import java.util.Scanner;
class PurchaseDay
{
public static void main(String[] args)
{
String mon = "mon";
String tue = "tue";
String wed = "wed";
String thur = "thur";
String fri = "fri";
String sat = "sat";
String sun = "sun";
System.out.println("Enter the purchase day from the options: Mon, Tue,
Wed, Thur, Fri, Sat, Sun: ");
Scanner s = new Scanner(System.in);
String str = s.next();
if (str.equalsIgnoreCase(mon) || str.equalsIgnoreCase(tue) ||
str.equalsIgnoreCase(wed))
{
System.out.println("Discount is 5%");
}
else if (str.equalsIgnoreCase(thur) || str.equalsIgnoreCase(fri))
{
System.out.println("Discount is 4%");
}
else if (str.equalsIgnoreCase(sat) || str.equalsIgnoreCase(sun))
{
System.out.println("Discount is 3%");
}
else
{
System.out.println("Incorrect Input");
}
s.close();
}
}

*******************************************************************************
Usman: Assignment Date: 12th April 2021
Assignment 1:
-------------

class Test5
{
int a=100;
int b=30;
void add()
{

System.out.println(a+b);
}
void mul()
{

System.out.println(a*b);
}
public static void main(String[] args)
{
Test5 d = new Test5();
d.add();
t.mul();
}

Assignment 2:
-------------
class Demo
{
int a=100;
int b=30;
}
class Test5
{
int a=100;
int b=30;
void add()
{
Demo d =new Demo();
System.out.println(a+b);
}
void mul()
{
Demo d1 =new Demo();
System.out.println(a*b);
}
public static void main(String[] args)
{
Test5 t = new Test5();
t.add();
t.mul();
}
}

*******************************************************************************
Usman: Assignment Date: 13th April 2021

Assignment-1:
class Test
{ declare 2-static var
static void add()
{ print the addition
}
static void mul()
{ print the multiplication
}
public static void main(String[] args)
{ call the add
call the mul
}
}

ANSWER:
class Static1
{
static int a = 10;
static int b = 20;
public static void main(String[] args)
{
Static1.add();
Static1.mul();
}

static void add()


{
System.out.println("Addition is: "+(a+b));
}

static void mul()


{
System.out.println("Multiplication is: "+(a*b));
}
}

/* OUTPUT
Addition is: 30
Multiplication is: 200
*/

=====================================================================
Assignment-2:
class Test
{ declare 2-instance var
static void add()
{ print the addition
}
static void mul()
{ print the multiplication
}
public static void main(String[] args)
{ call the add
call the mul
}
}
ANSWER:
class Static2
{
int a = 10;
int b = 20;
public static void main(String[] args)
{
Static2 st = new Static2();

st.add();
st.mul();
}

static void add()


{
Static2 plus = new Static2();
System.out.println("Addition is: "+(plus.a+plus.b));
}

static void mul()


{
Static2 mult = new Static2();
System.out.println("Multiplication is: "+(mult.a*mult.b));
}
}

/* OUTPUT:
Addition is: 30
Multiplication is: 200
*/
*/
*******************************************************************************
Usman: Assignment Date: 19th April 2021

import java.util.Scanner;
class Voter
{

public static void main(String[] args)


{
String name, location;
int age, mobile, sscRollNo;
float bankBalance;
Scanner s = new Scanner(System.in);

System.out.println("Please enter your name: ");


name = s.nextLine();

System.out.println("Please enter your location: ");


location = s.nextLine();

System.out.println("Please enter your age: ");


age = s.nextInt();

System.out.println("Please enter your mobile number: ");


mobile = s.nextInt();

System.out.println("Please enter your ssc roll number: ");


sscRollNo = s.nextInt();

System.out.println("Please enter your bank balance: ");


bankBalance = s.nextFloat();

Voter v = new Voter();


v.voteRegister(name, location, mobile, age, sscRollNo);
Voter.marry(name, age, bankBalance);

void voteRegister(String name, String location, int mobile, int age, int
sscRollNo)
{

if((age>17) && (location=="hyd"))


{

System.out.println("You are eligible for voting: "+"Name:


"+name+", Age: "+age+", Your voting number is : "+(mobile+age+sscRollNo));

else
{
System.out.println("Not eligible for voting");
}

static void marry(String name2,int age2, float bankBalance)


{

if((age2>=18) && (age2<=35))


{
System.out.println("You are eligible for marriage: "+"Name:
"+name2+", Age: "+age2+", Bank Balance: "+bankBalance);
}
else if (age2>35)
{
System.out.println("You are too late");
}

else
{
System.out.println("Not eligible, please try after sometime");
}

}
}
*******************************************************************************
Arshitha:

Assignment:1

class Services
{
void voteRegister(String name,int mobile,int age,int sscRollNo,String
location)
{
if(age>18 && location.equalsIgnoreCase("Hyd")){
System.out.println("You are eligible for voting"+" "+"Your Voter
Id num:"+" "+mobile+sscRollNo+age);
}
else if((age<=18 && location.equalsIgnoreCase("Hyd")) || (age>=18 &&
location.equalsIgnoreCase("Hyd")));
{
System.out.println("Not eligible for voting");
}
}

static void marry(String name,int age,double bankBalance)


{
if(age<18){
System.out.println("Not eligible try after some time");
}
else if (age>=18 && age<=34)
{
System.out.println("Eligible for mrg");
}
else{
System.out.println("Sorry you are too late");
}
}
}
class Trails
{
Services s;
public static void main(String[] args)
{
Services s=new Services();
s.voteRegister("Arshitha",630834,32,90876,"Hyd");
Services.marry("Arshi",24,200000.00);

}
}

siva kumar:-
==============
constructor assignment:- (22/04/2021)
========================
class Customer
{
String cname;
int pid;
String pname;
double pcost;
int quantity;
public static final int gst=10;
public static final String brand="honeywell";
public static final int discount=5;
Customer(String cname,int pid,String pname,double pcost,int quantity)
{
this.cname=cname;
this.pid=pid;
this.pname=pname;
this.pcost=pcost;
this.quantity=quantity;
}
double totalBill()
{
double bill;
bill=(pcost*quantity+Customer.gst)*95/100;
return bill;
}

public static void main(String[] args)


{
Customer c=new Customer("siva",1234,"book",500.45,2);
System.out.println("cname:"+c.cname+" "+"pid:"+c.pid+" "+"pname:"+c.pname+"
"+"pcost:"+c.pcost+" "+"quantity:"+c.quantity
+" "+"gst:"+Customer.gst+" "+"brand:"+Customer.brand+"
"+"discount:"+Customer.discount);
double total1=c.totalBill();
System.out.println("your bill is:"+ total1);

System.out.println("***************************************************************
************************************");
Customer c1=new Customer("kumar",4321,"shirt",1000.45,5);
System.out.println("cname:"+c.cname+" "+"pid:"+c.pid+" "+"pname:"+c.pname+"
"+"pcost:"+c.pcost+" "+"quantity:"+c.quantity+
" "+"gst:"+Customer.gst+" "+"brand:"+Customer.brand+"
"+"discount:"+Customer.discount);
double total2=c1.totalBill();
System.out.println("your bill is:"+total2);
}
}
o/p:-
======
D:\java by siva>java Customer
cname:siva pid:1234 pname:book pcost:500.45 quantity:2 gst:10 brand:honeywell
discount:5
your bill is:960.355
***********************************************************************************
****************
cname:siva pid:1234 pname:book pcost:500.45 quantity:2 gst:10 brand:honeywell
discount:5
your bill is:4761.6375

assignment:-
================
ex-3: Application contains three packages.
com.tcs.data.instancedata;
class Test
{ 1-instance var
1-instance methods
}

com.tcs.data.staticdata;
class Demo
{ 1-static var
1-static method
}

com.tcs.data.client;
class TestClient
{ public static void main(String[] args)
{ Acccess the instance data
Access the static data.
}
}

siva kumar:-(26-04-2021):
=========================
package assignment-1:-
======================
package com.tcs.data.instancedata;
public class Test
{
int a=10;
int b=20;

public void add()


{
System.out.println(a+b);
}
}

package com.tcs.data.staticdata;

public class Demo


{
static int num1=5;
static int num2=4;

public static void mul()


{
System.out.println(num1*num2);
}
}

package com.tcs.data.main;
import com.tcs.data.instancedata.Test;
import com.tcs.data.staticdata.Demo;

public class Clint


{
public static void main(String[] args)
{
Test t=new Test();
t.add();
Demo.mul();

}
}
o/p:-
======
D:\java by siva>javac -d . Test.java

D:\java by siva>javac -d . Demo.java

D:\java by siva>javac -d . Clint.java

D:\java by siva>java com.tcs.data.main.Clint


30
20public class MyThread extends Thread {
public void run() {
for (int i = 0; i <3; i++) {
printMsg();
}
}
public void printMsg() {
System.out.println("Good morning"+Thread.currentThread().getName());
}
public static void main(String[] args) {
MyThread tt = new MyThread();
tt.start();

}
}

27-07-2021:-
============
sivakumar
==*****==
class Test
{
public static void main(String[] args){
int[] a={10,20,30,40,50};
int sum=0;
for (int i=0;i<a.length ;i++ )
{
sum=sum+a[i];
}
System.out.println("the sum of array is:"+sum);
int min=a[0];
int max=a[0];
for (int i=0;i<a.length ;i++ )
{
if(a[i]<min)
min=a[i];
if(a[i]>max){
max=a[i];
}
}
System.out.println("minimum value in the array is:"+min);
System.out.println("maximum value in the array is:"+max);
}
}

You might also like