NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

PROGRAM :1

AIM: Write a program to perform mathematical operations using switch case taking input from the user.
OBJECTIVE: This program would take user defined input and would perform mathematical operations like addition, subtraction, multiplication, division and modulus on the basis of user’s specification using switch case.
FLOW CHART:


ALGORITHM:
1. Get the numbers a and b form the user.
2. Print the module: 1 for addition, 2 for subtraction, 3 for division, 4 for multiplication, 5 for modulus.
3. Take the operation from the user in terms of n.
4. Switch n from 1 to 5.
5. Now check the condition according to the user input for switching. For case 1 i.e. addition and so on.
6. Repeat step 5 till the condition is satisfied as per user’s instruction.
7. Print the valid answer with a valid statement.

SOURCE CODE:
package n;
import java.util.Scanner;
class Calc{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
System.out.println("Enter any number: ");
float a =s.nextFloat();
System.out.println("Enter any number: ");
float b =s.nextFloat();
System.out.println("Enter 1. for addition, 2. for subtraction, 3. for division, 4. for multiplication, 5. for Modulus");
int n = s.nextInt();
switch(n)
{
case 1: System.out.println("Addition of the number is : "+(a+b));
break;
case 2: System.out.println("Difference of the number is : "+(a-b));
break;
case 3: System.out.println("Division of the number is : "+(a/b));
break;
case 4: System.out.println("Multiplication of the number is : "+(a*b));
break;
case 5: System.out.println("Modulus of the number is : "+(a%b));
break;
default: System.out.println("SORRY! NOT APPLICABLE");
}
}
}
Date: 1st of August,2019
PROGRAM: 2
AIM: Write a program define a student class, describe its constructor, overload the constructor and initialize the object.
OBJECTIVE: The program contains a class student which uses the concept of constructor, to initialise various variables required accordingly. Finally, overload the constructors i.e. use of default and parameterized constructors in the program to understand the concept of constructor overloading.
FLOWCHART:

ALGORITHM:
1. Start with the initialization of objects for different constructors.
2. The object ob for default constructor, obj for first input of parameterized constructor and obj1 for second input.
3. The objects stores the instance variables university, sem, name, course and year and is initialized through default and parameterized constructor.
4. The objects then call the constructors accordingly and print the values based on the input.
SOURCE CODE:
package e;
public class Student {
int roll;
String name;
String university;
int sem;
String course;
Student()
{
university= "|****CHANDIGARH UNIVERSITY****|";
}
Student(String name,int i, int sem,String c)
{
this.name=name;
roll=i;
this.sem=sem;
course=c;
System.out.println("NAME: "+name);
System.out.println("ID: "+i);
System.out.println("SEMESTER: "+sem);
System.out.println("COURSE: "+c);
}
void print()
{
System.out.println(university);
}
public static void main(String[] args) {
Student ob=new Student();
System.out.println("-------------------------------");
ob.print();
System.out.println("-------------------------------");
Student obj=new Student("NEHA",1944,3,"BE-CSE");
System.out.println("-------------------------------");
Student obj1=new Student("LOL",0000,0,"LOTS-OF-LOL");
}
}



OUTPUT:

















Date: 08th August,2019
PROGRAM: 3
AIM: Write a program in java to show details of Vehicle-Car class using Inheritance as Car is a Vehicle.
OBJECTIVE: The program mainly includes the basic property of object-oriented programming and that is Inheritance. The class is to be defined with the class name Vehicle and the class car inherits the basic properties of vehicle to demonstrate how is inheritance actually performed.
FLOWCHART:

ALGORITHM:
1. The class Vehicle is created as main class which contains the attributes wheels, type, regno and function.
2. The class Vehicle inherits another class Car which contains the same attributes.
3. Cursor firstly is placed at public static void main() which contains the object of class Car which calls the function containing attributes for itself and class Vehicle using super.
4. Output is obtained for class Vehicle and Car.
SOURCE CODE:
import java.util.*;
class Vehicle
{
String type="Four-Wheeler";
String regno="UK07-5540";
int wheels=4;
String func="Automatic";
int speed=100;
void print()
{
System.out.println("Car type:"+type);
System.out.println("Reg no. : "+regno);
System.out.println("No. of wheels: "+wheels);
System.out.println("Functioning-Type: "+func);
}}
class Main extends Vehicle
{
Scanner sc=new Scanner(System.in);
String type;
String regno;
int wheel;
String func;
int speed;
void print()
{
System.out.println("Enter your registration number :");
regno=sc.next();
System.out.println("Enter the type of your car: ");
type=sc.next();
System.out.println("Enter the no.of wheels in car: ");
wheels=sc.nextInt();
System.out.println("Enter the functioning of car: ");
func=sc.next();
System.out.println("Enter the maximum speed of car: ");
speed=sc.nextInt();
System.out.println("*******************************");
System.out.println("Car type:"+type);
System.out.println("Reg no. : "+regno);
System.out.println("No. of wheels: "+wheels);
System.out.println("Functioning-Type: "+func);
System.out.println("Maximum speed: "+speed);
System.out.println("*******************************");
}
void display()
{
super.print();
print();
}
public static void main(String[] args)
{
Main obj=new Main();
obj.display();
}
}
OUTPUT:



PROGRAM: 4
Date: 9th August,2019

AIM: Write a program in java to define a vehicle car class, define its variable as private & (get, set) method as public. Create another class to instantiate the object with values.

OBJECTIVE: The defined parameters get and set are taken to identify the various attributes, the private data members are hence accessible to function which makes it accessible in the whole program. Initialisation is carried out in the methods get and set itself.
ALGORITHM:
1. The main method has the object of class vehicle which instantiates the values through set methods.
2. The initialised parameters then go to class vehicle.
3. Main1 class has the get values which points the various data members.
4. The public functions returns the values as per the parameters.

SOURCE CODE:
class Vehicle
{
private String model;
private String color;
private int price;
private int mod_year;
private String comp_name;
public String getmodel()
{
return model;
}
public String getcolor()
{
return color;
}
public int getprice()
{
return price;
}
public int getmod_year()
{
return mod_year;
}
public String getcomp_name()
{
return comp_name;
}
public void setmodel(String model)
{
this.model=model;
}
public void setcolor(String color)
{
this.color=color;
}
public void setprice(int price)
{
this.price=price;
}
public void setmod_year(int mod_year)
{
this.mod_year=mod_year;
}
public void setcomp_name(String comp_name)
{
this.comp_name=comp_name;
}
}
class Main
{
public static void main(String[] args) {
Vehicle obj1=new Vehicle();
Vehicle obj2=new Vehicle();
Vehicle obj3=new Vehicle();
obj1.setmodel("Wagon-R");
obj1.setcolor("Black");
obj1.setprice(1500000);
obj1.setmod_year(2018);
obj1.setcomp_name("Suzuki");
obj2.setmodel("Zen");
obj2.setcolor("Red");
obj2.setprice(20000000);
obj2.setmod_year(2017);
obj2.setcomp_name("Maruti");
obj3.setmodel("Indigo");
obj3.setcolor("Indigo");
obj3.setprice(95000000);
obj3.setmod_year(2019);
obj3.setcomp_name("Tata");
System.out.println("********************");
System.out.println("Company name: "+obj1.getcomp_name() +"nModel Name: "+obj1.getmodel()+ "nModel Year: "+obj1.getmod_year()+"nColor: "+obj1.getcolor()+ "nPrice: "+obj1.getprice());
System.out.println("********************");
System.out.println("Company name: "+obj2.getcomp_name() +"nModel Name: "+obj2.getmodel()+ "nModel Year: "+obj2.getmod_year()+"nColor: "+obj2.getcolor()+ "nPrice: "+obj2.getprice());
System.out.println("********************");
System.out.println("Company name: "+obj3.getcomp_name() +"nModel Name: "+obj3.getmodel()+ "nModel Year: "+obj3.getmod_year()+"nColor: "+obj3.getcolor()+ "nPrice: "+obj3.getprice());
}
}
OUTPUT:

PROGRAM:5
Date: 6th September, 2019
AIM: Write a program to demonstrate the use of interfaces by taking area as an interface and create three subclasses rectangle, square and circle to implement the area interface.
OBJECTIVE: To make this program we need interface as a class through which we will inherit three classes rectangle circle, rectangle and square. Interface is used to hide data but we can use it in inherited class through objects.
ALGORITHM:
1. The interface consists of three attributes with private as access specifiers.
2. Then we will inherit class though that interface.
3. Then we will call the attributes to use in the class though the object.
4. The values of object are sent by parameters to the function.
5. The resultant details are printed through the object in int main.

SOURCE CODE:
interface Area
{
public void area(int l, int b);

}
class Rectangle implements Area
{
int a;
public void area(int l,int b)
{
a=l*b;
System.out.println("The area of rectangle is : "+a);
}
}
class Square implements Area{
int a1;
public void area(int l,int b)
{
a1=l*l;
System.out.println("The area of square is : "+a1);
}
}
class Main implements Area{
double a2;
public void area(int l,int b){
a2=3.14*l*l;
System.out.println("The area of circle is : "+a2);
}
public static void main(String[] args)
{
Rectangle obj=new Rectangle();
obj.area(4,3);
Square obj1=new Square();
obj1.area(5,0);
Main obj2=new Main();
obj2.area(8,0);
}
}

PROGRAM :6

AIM: Write a program in one packages to find the Area of Circle, Square, Triangle.
Then create another package with single class which invoke the methods of classes defined in the first package by taking input from the user.

PROGRAM:-

package First;
import java.util.Scanner;
class radius
{
public void area_circle(int x,int y,int z)
{
int area_c=22/7*x*x;
System.out.println("Area of the circle is : "+area_c);
}
}
public class Circle extends radius{
public void input()
{
int x,y,z;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Radius : ");
x=sc.nextInt();
y=sc.nextInt();
z=sc.nextInt();
area_circle(x,y,z);
}
}

package First;
import java.util.Scanner;
class side
{
public void area_square(int x,int y)
{
int area_s=x*x;
System.out.println("The area of Square is : "+area_s);
}
}
public class Square extends side{
public void input()
{
int x,y;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the side: ");
x=sc.nextInt();
y=sc.nextInt();
area_square(x,y);
}
}

package First;
import java.util.Scanner;
class dimensions
{
public void area_triangle(double x,double y,double z)
{
double s=(x+y+z)/2;
double area2 = Math.sqrt(s*(s-x)*(s-y)*(s-z));
System.out.println("Area of traingle: "+ area2);
}
}
public class Triangle extends dimensions
{
public void input()
{
double x,y,z;
Scanner sc = new Scanner(System.in);
System.out.println("Enter sides of triangle: ");
x= sc.nextDouble();
y= sc.nextDouble();
z= sc.nextDouble();
area_triangle(x,y,z);
}
}

package Scond;
import First.*;
public class Area {
public static void main(String[] args)
{
Circle ob=new Circle();
ob.input();
Square obj=new Square();
obj.input();
Triangle obj1=new Triangle();
obj1.input();
}
}






OUTPUT :













Date: 26th of September,2019
PROGRAM: 7
AIM: WAP to implement the concept of exception handling by creating user defined examples.
SOURCE CODE:
import java.io.*;
class Inexception extends Exception
{
private double amount;
public Inexception(double amount)
{
this.amount = amount;
}
public double getAmount()
{
return amount;
}
}
class CheckingAccount
{
private double balance;
private int number;
public CheckingAccount(int number)
{
this.number = number;
}
public void deposit(double amount)
{
balance += amount;
}
public void withdraw(double amount) throws Inexception
{
if(amount <= balance)
{
balance -= amount;
}
else
{
double needs = amount - balance;
throw new Inexception(needs);
}
}
public double getBalance()
{
return balance;
}
public int getNumber()
{
return number;
}
}
public class Main
{
public static void main(String [] args)
{
CheckingAccount c = new CheckingAccount(101);
System.out.println("Depositing Rs 500...");
c.deposit(500.00);
try
{
System.out.println("nWithdrawing Rs. 100...");
c.withdraw(100.00);
System.out.println("nWithdrawing Rs. 600...");
c.withdraw(600.00);
}catch(Inexception e)
{
System.out.println("Sorry, but you are short rupees" + e.getAmount());
}
}
}

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.