Friday, January 27, 2017

food class || show ,adding new item qyt , selling

using oops concept
Food class and create object , create method , constructs method


import java.util.Scanner;
class Food {
public String fProducName;
public int fUnitPrice;
public int fToatalQuentity;
public int fTotalAmount;
public Food(){
fProducName = new String();
fUnitPrice = 0;
fToatalQuentity = 0;
fTotalAmount = 0;
}
public Food(String name, int fUnitPric, int fTotalQuentity){
fProducName = new String(name);
fUnitPrice = fUnitPric;
fToatalQuentity = fTotalQuentity;
}
public void totalItemAmount(){
fTotalAmount = fUnitPrice*fToatalQuentity;
System.out.println("Toatal Quentity : "+fToatalQuentity);
System.out.println("Toatal Amount : "+fTotalAmount);
}
public void addingNewItem(int add){
fToatalQuentity = fToatalQuentity + add;
fTotalAmount = fUnitPrice*fToatalQuentity;
}
public void addingNew(int add){
fToatalQuentity = fToatalQuentity + add;
}
public void changefProducName(String name){
fProducName = name;
}
public void sellinFoodProduct(int sell){
fToatalQuentity = fToatalQuentity - sell;
}
public void afterAdding(){
System.out.print(" Product Name: "+fProducName+"\n Total Qyt: "+fToatalQuentity+"\t Total Amount: "+fUnitPrice*fToatalQuentity+" Taka\n");
}
public void dispFoodDetails(){
System.out.print(" Total Qyt: "+fToatalQuentity+"\t Total Amount: "+fUnitPrice*fToatalQuentity+" Taka\n");
}
}
class SuperShop {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Scanner s = new Scanner(System.in);
String fFoodName[] = new String[100];
int fUnitPrice[] = new int[100];
int fQuentity[] = new int[100];
int option;
String fname;
int zeroo=1;
Food[] n = new Food[12];
fFoodName[0]="Banana";
fFoodName[1]="Cake";
fFoodName[2]="Bread";
fFoodName[3]="Gelly";
fFoodName[4]="rochi";
fFoodName[5]="Paddis";
fFoodName[6]="Paddis";
fFoodName[7]="Biscuit";
fFoodName[8]="tea";
fFoodName[9]="coffee";
fUnitPrice[0] =40;
fUnitPrice[1] =10;
fUnitPrice[2] =15;
fUnitPrice[3] =20;
fUnitPrice[4] =35;
fUnitPrice[5] =30;
fUnitPrice[6] =12;
fUnitPrice[7] =22;
fUnitPrice[8] =19;
fUnitPrice[9] =10;
fQuentity[0] = 80;
fQuentity[1] = 30;
fQuentity[2] = 200;
fQuentity[3] = 122;
fQuentity[4] = 50;
fQuentity[5] = 33;
fQuentity[6] = 32;
fQuentity[7] = 22;
fQuentity[8] = 33;
fQuentity[9] = 44;
System.out.println(" \n\n\n\n\n\n\t\t\t\t\t\t********************************************** ");
System.out.println(" ");
System.out.println(" ");
System.out.println(" \t\t\t\t\t\t Ornet Super Shop ");
System.out.println(" ");
System.out.println(" ");
System.out.println("tFood Name-- Unit Price--Total Qyt ");
for(int j = 0; j< 10; j++){
n[j] = new Food(fFoodName[j], fUnitPrice[j],fQuentity[j]);
System.out.println(" Item "+(j+1)+":"+fFoodName[j]+"\t"+fUnitPrice[j]+"\t"+fQuentity[j]);
}
System.out.print(" **********************************************\n ");
do{
System.out.print(" Select option:\n ");
System.out.print(" 1:Show Details Above Item \n ");
System.out.print(" 2: Edit\n ");
System.out.print(" 3: Add qyt\n ");
System.out.print(" 4: Selling\n ");
System.out.print(" 5: exit\n ");
option = sc.nextInt();
switch(option){
case 1:{
System.out.print(" Enter the product ID: ");
int num = sc.nextInt();
System.out.print(" Name OF Product: "+n[num-1].fProducName+"\n");
n[num-1].dispFoodDetails();
break;
}
case 2:{
System.out.println("Select name of FooD ID:");
int choiceSell = sc.nextInt();
System.out.print((choiceSell)+": "+n[choiceSell-1].fProducName+"\n");
System.out.println("Enter name of FooD :");
fname = sc.next();
n[choiceSell-1].changefProducName(fname);
n[choiceSell-1].afterAdding();
break;
}
case 3:{
System.out.print(" ----Adding----\n Enter number of Food ID: ");
int serch = sc.nextInt();
System.out.print(" Name OF Product: "+n[serch-1].fProducName+"\n");
System.out.print(" \n\nAdding number of Qyt: ");
int nu = sc.nextInt();
n[serch-1].addingNew(nu);
System.out.print("\n\n\nAfter Adding:\n\n Details Of ");
n[serch-1].afterAdding();
break;
}
case 4:{
System.out.println("Selling : select name of FooD ID:");
int choiceSell = sc.nextInt();
System.out.print((choiceSell)+": "+n[choiceSell-1].fProducName+"\n");
System.out.println(" Enter onumber of FooD selling: ");
int sell = sc.nextInt();
n[choiceSell-1].sellinFoodProduct(sell);
n[choiceSell-1].afterAdding();
break;
}
default:
System.out.print("not valid\n ");
}
System.out.print("\nEnter 0 for continue: and anykey for exit\n ");
zeroo = sc.nextInt();
}while(zeroo == 0);
}
}
view raw superShop.java hosted with ❤ by GitHub

Tuesday, January 24, 2017

Sorting number using class and interface--

import java.util.Scanner;
interface Sorted{
public void calculation(int num[],int n);
}
class SortingDemo implements Sorted{
public void calculation(int num[],int n){
int a,c;
for(int i = 0; i<n-1; i++){
for(int j = 0; j<n-1; j++){
if(num[j] > num[j+1]){
c=num[j];
num[j] = num[j+1];
num[j+1] = c;
}
}
}
System.out.println("sorting ");
for(int p = 0; p <n; p++){
System.out.println((p+1)+":"+num[p]);
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num[] = new int[50];
SortingDemo sendNum = new SortingDemo();
int n;
System.out.print("How many nmber input: ");
n = sc. nextInt();
for(int i = 0 ; i <n; i++){
System.out.print(" input num "+(i+1)+":");
num[i] = sc. nextInt();
}
sendNum.calculation(num,n);
}
}
view raw sorting.java hosted with ❤ by GitHub



A small program use java object oriented program

import java.util.Scanner;
interface Medicin{
public void addingMedicine(int addM);
public void sellingMedicine(int buy);
}
class Medicine implements Medicin {
public String m_name;
public int m_num;
public Medicine(){
m_name = new String();
m_num = 0;
}
public Medicine(String name, int num){
m_name = new String(name);
m_num = num;
}
public void addingMedicine(int addM){
m_num = m_num+addM;
}
public void sellingMedicine(int buy){
m_num = m_num - buy;
}
public void disp(){
System.out.println(" Name of Medicine: "+m_name+" \n At Present Number of Medicine "+m_num);
}
}
class MedicineShop {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
Scanner s = new Scanner(System.in);
String mName[] = new String[50];
int mNum[] = new int[50];
Medicine[] n = new Medicine[4];
System.out.println("Enter total num of medicine . you will add: ");
int num = sc.nextInt();
for(int i = 0; i<num; i++){
System.out.println("Enter the name of medicine"+(i+1)+":");
mName[i] = s.nextLine();
System.out.println("Enter the amount of medicine"+(i+1)+":");
mNum[i] = sc.nextInt();
}
for(int j = 0; j< num; j++){
n[j] = new Medicine(mName[j], mNum[j]);
n[j].disp();
}
//adding new medicine
System.out.println("Adding Medicine: select name of medicine: ");
for(int j = 0; j< num; j++){
System.out.print((j+1)+": "+n[j].m_name+"\n");
}
int choice = sc.nextInt();
System.out.println("adding onumber of medicine: ");
int nu = sc.nextInt();
n[choice-1].addingMedicine(nu);
n[choice-1].disp();
//selling sum tablet
System.out.println("Selling : select name of medicine:");
for( int k = 0; k< num; k++){
System.out.print((k+1)+": "+n[k].m_name+"\n");
}
int choiceSell = sc.nextInt();
System.out.println("Enter onumber of medicine selling: ");
int sell = sc.nextInt();
n[choiceSell-1].sellingMedicine(sell);
n[choiceSell-1].disp();
}
}
view raw Hospital.java hosted with ❤ by GitHub

Saturday, January 21, 2017

abstract class in java

Sunday, January 15, 2017

inheritance in java

Inheritance in java is a mechanism in which one object acquires all the properties and behaviors of parent object.

The class which inherits the properties of other is known as subclass (derived class, child class) and the class whose properties are inherited is known as superclass (base class, parent class).


Inheritance represents the IS-A relationship, also known as parent-child relationship.


Example of Single Inheritance

class Calculation{
void adding(int a, int b){
System.out.println("adding in super class: "+(a+b));
}
}
class Calculation2 extends Calculation{
void adding2(int a, int b){
System.out.println("adding in sub class: "+(a+b));
}
public static void main(String args[]){
Calculation2 add = new Calculation2();
add.adding(12,8);
add.adding2(12,8);
}
}





Example of Multilevel Inheritance


class Calculation{
void adding(int a, int b){
System.out.println("adding in super class: "+(a+b));
}
}
class Calculation2 extends Calculation{
void adding2(int a, int b){
System.out.println("adding in Calculation2 class: "+(a+b));
}
}
class Calculation3 extends Calculation2{
void adding3(int a, int b){
System.out.println("adding in Calculation3 class: "+(a+b));
}
public static void main(String args[]){
Calculation3 add = new Calculation3();
add.adding(12,8);
add.adding2(10,8);
add.adding3(8,8);
}
}


Example of Heirarchical Inheritance


class A{
void displayA(){
System.out.println(" This is a content of parent class");
}
}
class B extends A{
void displayB(){
System.out.println(" This is a content of child class 1 B");
}
}
class C extends A{
void displayC(){
System.out.println(" This is a content of child class 2 C");
}
}
class Myclass{
public static void main(String args[]){
C c = new C();
B b = new B();
c.displayC();
c.displayA();
b.displayB();
b.displayA();
}
}


Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object. Any Java object that can pass more than one IS-A test is considered to be polymorphic


There are two types of polymorphism in java: compile time polymorphism and runtime polymorphism. We can perform polymorphism in java by method overloading and method overriding.


Example of method overloading


class OverloaddingDemo{
void sum(int a, int b){
System.out.println("Adding a+b:"+(a+b));
}
void sum(int a, int b, int c ){
System.out.println("Adding a+b+c:"+(a+b+c));
}
public static void main(String args[]){
OverloaddingDemo ad = new OverloaddingDemo();
ad.sum(25,30);
ad.sum(25,30,20);
}
}


Example of method overriding


class Dept{
void address(){
System.out.println("Acadimic Building , Just");
}
}
class Cse extends Dept{
void address(){
System.out.println(" 2nd floar , Acadimic Building , Just");
}
public static void main(String args[]){
Dept d = new Dept();
Cse ad = new Cse();
d.address();
ad.address();
}
}


Thursday, January 12, 2017

java progrma

##
import java.util.Scanner;
class Employee{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
Scanner inty = new Scanner(System.in);
String emp_name[] = new String[3];
int emp_salary[] = new int[3];
int emp_id[] = new int[3];
int tax = 7;
int en = 2;
String emp_post[] = new String[3];
double total_groce_sallary;
for(int i = 0; i <= 2; i++){
System.out.println("\n Enter Details Employee: "+(i+1));
System.out.print("Enter Emplyee ID: ");
emp_id[i] = sc.nextInt();
System.out.print("Enter Employee Name: ");
emp_name[i] = inty.nextLine();
System.out.print("Enter Employee Salary: ");
emp_salary[i] = sc.nextInt();
System.out.print("Enter Employee Post: ");
emp_post[i] = inty.nextLine();
}
for(int j = 0; j <=2; j++){
double total_tax = (emp_salary[j]*7)/100;
double total = emp_salary[j] - total_tax;
double extara_add = (emp_salary[j]*2)/100;
double gross_salary = total+extara_add;
System.out.println(" \n Emplyee Details:"+(j+1));
System.out.println(" Emplyee ID: "+emp_id[j]);
System.out.println(" Employee Name: "+emp_name[j]);
System.out.println(" Employee post: "+emp_post[j]);
System.out.println(" Employee salary: "+emp_salary[j]);
System.out.println(" Employee tax : "+total_tax);
System.out.println(" En : "+extara_add);
System.out.println(" without tax in salary : "+total_tax);
System.out.println("Total Gross Salary: "+gross_salary);
System.out.println("***************");
}
}
}
view raw employee.java hosted with ❤ by GitHub


Tuesday, January 10, 2017

Introduction to OOP :

What Is an Object?

An object is a software bundle of related state and behavior. Software objects are often used to model the real-world objects that you find in everyday life. 

What Is a Class?

A class is a blueprint or prototype from which objects are created. 

What Is Inheritance?

Inheritance provides a powerful and natural mechanism for organizing and structuring your software. 

What Is an Interface?

An interface is a contract between a class and the outside world. When a class implements an interface, it promises to provide the behavior published by that interface. 

What Is a Package?

A package is a namespace for organizing classes and interfaces in a logical manner. Placing your code into packages makes large software projects easier to manage.