Check if the letter is vowel or consonant

C Program
#include <stdio.h>
#include <stdlib.h>
int main()
int main()
{
    char c;
    printf("Enter any word: ");
    scanf("%c",&c);
    if(c=='A'||c=='a'|| c=='E'||c=='e'||c=='I'||c=='i'||c=='O'||c=='o'||c=='U'||c=='u')
        printf("%c is a vowel",c);
    else
        printf("%c is a Consonant",c);
}



Write a word in both Upper Case and Lower Case

C Program
#include <stdio.h>
#include <stdlib.h>
int main()
{
    char Str[10];
    printf("Enter any Word: ");
    scanf("%s",&Str);
    printf("Word: %s\n",&Str);
    printf("UPPERCASE: %s \n", strupr(Str));
    printf("lowercase: %s ", strlwr(Str));
}



Python Program
S = input("Enter a sentence: ")
print("Lower case: " + S.lower())
print("Upper case: " + S.upper() )

C program to find Sin, Cos, Tan of a number

C Program
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
   float x;
   printf("Enter Value of X:");
   scanf("%f",&x);
   printf("The sin of the value is :%f\n",sin(x));
   printf("The cos of the value is :%f\n",cos(x));
   printf("The tan of the value is :%f\n",tan(x));
}


Paper Measurement(Convert ream to sheets)

1 ream contains 500 sheets of paper

C Program
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int s,r;
    printf("Enter total ream of paper:");
    scanf("%d",&r);
    s=r*500;
    printf("Total sheets of paper in %d ream is %d",r,s);
    return 0;
}


Java Program
import java.util.Scanner;

public class PaperMeasurement {

	public static void main(String[] args) 
	{
		Scanner S = new Scanner(System.in);
		int s,r;
		System.out.print("Enter total ream of paper:");
	    r= S.nextInt();
		s=r*500;
		System.out.print("Total sheets of paper in " +r + " ream is " + s);
	}

}

Caculate Profit

Profit is calculated by subtracting cost price from selling price.
That is, Profit = SellingPrice - CostPrice

C Program
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int p,cp,sp;
    printf("Enter Cost Price:");
    scanf("%d",&cp);
    printf("Enter Selling Price:");
    scanf("%d",&sp);
     p=sp-cp;
    printf("Profit from the item is %d",p);
    return 0;
}


Java Program
import java.util.Scanner;

public class Profit {

	public static void main(String[] args) 
	{
		Scanner S = new Scanner(System.in);
		int p,cp,sp;
	    System.out.print("Enter cost Price:");
	    cp = S.nextInt();
	    System.out.print("Enter Selling Price:");
	    sp=S.nextInt();
	     p=sp-cp;
	    System.out.print("Profit from the item is " + p);
	  
	}

}

WorkDone(W=F*N)

C Program
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int w,f,d;
    printf("Enter Force(N): ");
    scanf("%d",&f);
    printf("Enter Distance travelled  by the body(m): ");
     scanf("%d",&d);
    w=f*d;
    printf("The work done is %d Joules",w);
    return 0;
}


Java Program
import java.util.Scanner;

public class WordDone {

	public static void main(String[] args) 
	{
		Scanner S = new Scanner(System.in);
		 int w,f,d;
		    System.out.print("Enter Force(N):");
		    f= S.nextInt();
		    System.out.print("Enter Distance travelled  by the body(m): ");
		    d= S.nextInt();
		    w=f*d;
		    System.out.print("The work done is "+ w + "Joules");
	  
	}

}
Python Program
f = int(input("Enter total force applied: "))
d = int(input("Enter distance displaced: "))
w = f * d
print("Total work done is : " +  str(w))

OHMS LAW(V=IR)

Ohm’s law explains the relationship between voltage and current flowing through resistors. The mathematical formula is V=IR.

C Program
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int v,i,r;
    printf("Enter current(Amphere):");
    scanf("%d",&i);
    printf("Enter Resistance(Ohm):");
    scanf("%d",&r);
     v=i*r;
    printf("Voltage of the circuit is %d",v);
    return 0;
}


Java Program
import java.util.Scanner;

public class Swap {

	public static void main(String[] args) 
	{
		Scanner s = new Scanner(System.in);
		int v,i,r;
		 System.out.print("current(Amphere):");
		i = s.nextInt();
	     System.out.print("Enter Resistance(Ohm):");
		r = s.nextInt();
		v=i*r;
		System.out.print("Voltage of the circuit is " + v);   
	}
}



Python Program
i = int(input("Enter value of current in amphere: "))
R = int(input("Enter value of Resistance in ohm: "))
v = i*R
print("The voltage(V) applied is: " + str(v))

What is Electronics?




Electronics is the branch of science and engineering which deals with the study of behavior and movement of electrons in different materials. It can also be defined as the engineering branch, which is concerned with the design of electronic circuits using different electronic components like chips, transistor, semiconductor, resistors and etc. Electronics is a vast subject and hence there are many branches of electronics. Electronic also has a wide range of applications. We shall also look at some jobs for Electronics engineers.

Branches of Electronics:

  • Digital electronics:
  • This branch is concerned with usage of Boolean logic and discrete signal electronics for design of electronic componenets. Eg: Computers, digital cameras.

  • Analog electronics:
  • This branch is concerned with analysis of electrical signals and relationship between signal and current or voltage. Eg: radio and audio equipment

  • Micro electronics(Integrated circuits) :
  • As the word micro means small this branch is concerned with design of electronic components using materials like resistors, capacitors etc. Eg: chips, motherboards,etc.

  • Nano electronics:
  • This branch usually refers to nanotechnology for electronic components.

  • Opto electronics:
  • This branch deals with conversion of electrical energy into light energy. Example: LED(Light emitting devices), Solar cells(photovoltaic).

Applications of Electronics:

  • Communication Industry:
  • Communication has become very effective and fast. This is all possible due to transmission of information via radio waves

  • Entertainment Industry:
  • Phones and computer help us pass our boredom

  • Defense and Welfare Industry
  • Barometer is used to predict weather, Missile launching systems, Check pollution ,etc

  • Medicinal Appliances:
  • Electronic devices are used to test and diagnosis of various diseases. Stethoscope are used to listen to our inner heart beats.

  • Design of hardware:
  • Electronics is used to design hardware of various components like mobile phones, computers, etc.

Job opportunity for Electronic Engineers in 2021:

    1. Communication Officier
    2. Project manager
    3. Network engineering
    4. Rocket science
    5. Satellite engineering
    6. ICT officer
    7. Electronic design Engineering
    8. Aerospace engineering
    9. Biomedical engineering
    10. Computer hard ware engineering

Frequently Asked Question:

    1. What is an electronic device?
    Electronic devices are those devices which use electric current to encode, decode and transmit information. Eg: Computer, mobile phones, etc.

    2. Who is the father of electronics?
    Michael Faraday is the father of electronics.

    3. Is coding important for electronic engineering?
    Yes C, C++ and java are few programming language ECE students require to deal with embedded systems.

    4. What is the scope of electronic engineering after four years?
    It will have more scope as computers are becoming powerful day by day.

Difference between Pre Increment and Post Increment

Pre Increment and Post Increment are the features of unary operators. Unary operators are the important concepts of programming and is very easy to learn. Unary operators are mostly used to looping statements, function calls, etc. The unary operators have high precedence in C compared to other operators.(click here to check precedence table). Unary operators are operators with only one operand. Two types of unary operators in C program:
1. Increment operator (++): it increases the value by one.
2. Decrement operator (--): It decreases the value by one.

Difference Between Pre Increment and Post Increment.

Pre Increment Post Increment
It is used to increase the value of the variable by one before using in the expression It is used to increase the value of the variable by one only after using in the expression
It value gets incremented as soon as the expression is used The original value is used in an expression and then only it is incremented.
Its syntax is : ++ variable; Its syntax is : variable ++;
code snippet:
#include <stdio.h>
#include <stdlib.h>

void main()
{
   
   int res, n;

   n = 7;

   res = ++n;
   
   printf("%d", res);
}
Output: 8
code snippet:
#include <stdio.h>
#include <stdlib.h>

void main()
{
   
   int res, n;

   n = 7;

   res = n++;
   
   printf("%d", res);
}
Output: 7

C OPERATORS PRECEDENCE AND ASSOCIATIVITY

Rank

Operator

Explanation

Associativity

1

()

[]

.

->

Parenthesis

Square brackets

Direct Member selection

Indirect Member selection

 

Left to right

2

++

--

!

~

(type)

&

*

Increment

Decrement

Logical negation

Bitwise complement

Type casting

Address

Pointer reference

Right to left

3

*

/

%

Multiplication

Division

Remainder

Left to right

4

+

-

Addition

Subtraction

Left to right

5

<< 

>> 

Left shift

Right shift

Left to right

6

< 

<=

> 

>=

Less than

Less than or equal to

Greater than

Greater than or equal to

Left to right

7

==

!=

Equal to

Not equal to

Left to right

8

&

 

Bitwise AND

 

Left to right

9

^

 

Bitwise exclusive OR

 

Left to right

10

|

Bitwise Inclusive OR

Left to right

11

&&

Logical AND

Left to right

12

||

Logical OR

Left to right

13

?:

Ternary operator

Right to Left

14

=

*=

/=

%=

+=

-=

&=

^=

|=

<<=

>>=

Assignment

Multiplication assignment

Division assignment

Modulus assignment

Addition assignment

Subtraction assignment

Bitwise And assignment

Bitwise inclusive assignment

Bitwise exclusive assignment

Bitwise shift left assignment

Bitwise shift right assignment

Right to left

15

,

Comma

Left to right

 

Difference between Method Overloading and Method Overriding

Method Overloading and Overriding help us to achieve polymorphism, which is one of the features of Object-Oriented-programming language

1. Method Overloading

  • Method overloading is a oops concepts in which a class can have two or more methods with same name but with different parameter
  • It is also called static polymorphism or time binding or early binding
  • It is implemented during compile time
  • There are two ways to overload method in java :
    1.Different Number of Arguments
    2.Different Data Types

Example

public class MethodOverloading 
  {
		public static void main(String[] args) 
	{
			MethodOverloading a = new MethodOverloading ();
			a.age(5);
			a.age(18, "CSE");
			a.display('H');
			a.display(12);	
	}
		public void age(int a)
		{
			System.out.println("The age is:" + a);
		}
		public void age(int a, String c)
		{
			System.out.println("The age is:" + a +" Name:" + c);
		}
		public void display(int a)
		{
			System.out.println("The age is:" + a);
		}
		public void display(char a)
		{
			System.out.println("Name is:" + a);
		}
		

}
    

2. Method Overriding

  • if sub class has the same method as declared in parent class it is called method overriding
  • it is also called dynamic binding/ dynamic polymorphism
  • It is implemented during run time

Example

class baby 
{
	
	void display()
	{
		System.out.println("This is the Child class");
	}
	
}
public class MethodOverriding extends baby
{
	public static void main(String[] args) 
	{
		 MethodOverriding obj = new  MethodOverriding ();
		 obj.display();

	}
	void display()
	{
		super.display();
		System.out.println("This is the parent class");
	}
}

Importance of Digital Proficiency




The modern world is to be proficient in digital world. The invention of computer by Charles Babbage and the development of internet by ARPANET is a milestone in the process of digitalization of the modern world (Schafer, 2019). Digital technology is a recent long wave of socio-economic evolution that has transformed every aspect of human life. With such advent of technologies, it has become mandatory to master it. Therefore, being digitally proficient is the way of living in this modern world. It is an idea to create awareness for the good of humanity, for prospering business and to retain information for explorations in various fields.

To the grass root level, being digitally proficient helps in the conduct of campaigns to the targeted number of people. As an elevated method to create awareness, it provides a platform to give voice to voiceless. For an instance the Danish branch of the World Wildlife Federation (WWF) developed a campaign leveraging the short-lived nature of snapshot posts to help protect endangered species. Snap chat users were accustomed to their selfies disappearing within seconds of posting. To convey their message the authorities alerted about the vulnerability of endangered species by sharing dramatic, close up photos of animals on the verge of extinction with the message: “Don’t let this be my last selfie.” The WWF authorities asked the users to share the post and make some donation. The act was digitally a simple procedure but the result was large where 5000 people had shared the post within hours on twitter and by the end of the week, more than 120 million had seen the message. Moreover, within three days, the charity reached its fundraising goal for the entire month. (“Last Selfie,”2014). This shows that digitally equipped can give voice to voiceless and privileges to underprivileged ones. Furthermore, it also helps in marketing of individual business to successful level.

The literacy in digital technologies serves to connect businessman and the consumer by effective communication and digital platforms. For a consumer to purchase goods it is must that the details of the product should be known by the consumers. However, to fill that gap the businessman with the help of technologies must convey the features of the product by publicizing its brand or ideology. In Bhutan, Zala company gained over 150,000 views and many comments to buy the product. Furthermore, the term online shopping has become a trend in today’s era where the products to be sold are displayed through websites describing the products prices and its feature. Ultimately the method is found to be a success and made huge profit. Such is the power of being digitally literate. On next level digital proficiency can be used to retain information for scientific explorations.




On an advanced level of being digitalized, engineers all over the world had used the retained information to explore the universe. One such incident can be noted from the work of Katherine Johnson who is a NASA employee and was credited the success of the first and subsequent U.S crewed spaceflights. (Loff, 2016). It was all because of the algorithms which calculated the trajectories, launch windows and significantly more. Furthermore, the image of black hole; less apparently clear though, which was once thought impossible to capture is being captured by Katie Bouman and it was possible because of the computer program developed by Katie. At present the data they captured has been stored on hundreds of hard drives to central processing centers in Boston, US and Bonn, Germany for the creation of striking image. (Bouman,2019).

To conclude, an easy way to educate yourself is by being proficient in digital world through which one convey the ideas through various digital campaign. Furthermore, on next level of upgrading oneself financially, online business could be implemented if one has a good knowledge on information technology. To be unaware about the digital technologies will subsequently have a negative impact and would remain backward compared to others. Therefore, to help oneself and promote one must be having a good knowledge about the technologies around as significantly explained above.



Digital Technology




Digital technology is changing every aspect of the world. Digital technologies includes social media, online games, multimedia and mobile phones and any technology that stores and process data. Digital technologies have revolutionized the way people think or the way they live their everyday lives without even realizing it. Digital technology has changed education, given people broader access to information, changed the way people maintain contact which will all be for naught if people don’t keep up with the constantly changing digital world.

Due to most people using phones, technology has slowly become integrated into schools and serves as a link between home and school. Using technologies in education has enabled students to learn things that interest them from different resources. This is known as digital learning. It is stated that over 90% of young people are online and have cell phones, over half of adults aged 65 and above are online and 78% own a cell phone (Anderson, 2015).It has become valuable as it is readily accessible and it is visual based learning there by making children learn more easily than non-visual means. For example, watching videos and playing games enable people to learn about different cultures and language. They watch videos and listen to people speaking from different parts of the world and enable them to learn about their everyday lives.

Furthermore, technology has revolutionized the way people keep in contact from letter writing to cell phones, video calls, and social media. It has also changed the way individuals participate in social, cultural and political activities as all sorts of information these days is first uploaded to the internet and then shared to social media sites where people participate in discussions and debates. Social media has destroyed the barriers that separate the people of this world by making it easier to communicate with each other and making information easily accessible anytime and anywhere to anyone who wants it. Using social networks can shorten the time. All sorts of services can be availed through the internet without leaving the comfort of your home. Digital technologies are being improved and developed gradually to match the needs of the people but if people aren’t proficient in using these technologies then it can lead to lots of problem.




Due to the present situation of covid-19, remote working has been advised which meant that people needed to know the skills to navigate through social media, in mobile phones and computers. Times like these has made us learn the importance of digital literacy. Even though digital learning had become quite popular only some children and young people have access to knowledgeable adults and technological resources that can help improve their learning and creativity. This is because most aren’t knowledgeable about digital technology and they do not find it necessary to give their children access to broadband internet or let them learn skills in computers. People need to be educated in digital technology to a certain level to understand and to be aware what happens on the internet. Digital literacy keeps you more connected as you learn not only how to create content using information, you can also share what you know or heard or watch to people who are interested in the same things as you. Digital literacy is very important to know what information on the internet is fake so that you don’t get scammed and to find out what is a good source of information. Digital literacy is lifelong learning that one should never forego.

To conclude, people should understand that technologies will continue to become embedded in the daily lives of every human being and the physical infrastructure of their homes. Digital technologies have transformed how people communicate, learn and live their lives.Our life got to be more helpful since social media may be an exceptionally valuable apparatus in 21st century, it might offer assistance to improve our life. But people must be mindful of how to utilize it.



Programs using Recursive Function

Recursive Function is a functtion which calls itself.Every recursive function must have a base condition to stop the function else the program will never end

Advantage of Recurive Function

1.it makes the coding clean

2.it helps solve a complex problem by breaking it down into many parts



Question: Write a program to find the sum of a number from 1 to n using recursive function

Solution:

import java.util.Scanner;

public class Recursive1
    {
	static int sum=0;

	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		System.out.print("Enter A number:");
		int n = s.nextInt();
		System.out.print("The sum of the numbers from 1 to " + n +" is " + sum(n));	
	}

	public static int sum(int n)
	{ 
		int i=n;
		if(i!= 0)
		{
			sum = sum + i;
			i--;
			return sum(i);
		}
		return(sum);				
	}
   }

Output:



Question: Write a program to find the factorial of a given number using recursive function

Solution:

import java.util.Scanner;
public class Recursive2
  {
	static int fac=1;

	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		System.out.print("Enter A number:");
		int n = s.nextInt();
		System.out.print("The factorial of the number is " + n +" is " + fac(n));	
	}

	public static int fac(int n)
	{ 
		int i=n;
		if(i!= 0)
		{
			fac = fac * i;
			i--;
			return fac(i);
		}
		return(fac);				
	}
  }

output:





Question:Write a program to print multiplication table of any number from 1 to 12 using recursive function

Solution:

import java.util.Scanner;
public class Recursive3
  {
	static int i=1;
	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		System.out.print("Enter A number:");
		int n = s.nextInt();
		System.out.print("The Multiplication table of " + n +" from 1 to 12 is \n");
		mut(n);	
	}

	public static int mut(int n)
	{ 
	
		if(i<=12)
		{
			System.out.println(i +"*"+ n+ " : " + (i*n));
			i++;
			fac(n);
		}
		return(n);				
	}
  }
  

output:



Question: Write a program to find the prime number using recursive program

Solution

import java.util.Scanner;
public class Recursive4
  {
	static int count=0;
	static int i=1;
	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		System.out.print("Enter a number:");
		int n = s.nextInt();
		System.out.print("The given number "+ n +" ");
		check(n);
		if(count==2)
			System.out.print("is prime");
		else
			System.out.print("is not prime");
	
	}

	public static int check(int n)
	{ 
		if(i<=n)
		{
			if(n%i==0)
			{
				count++;
			}
			i++;
			return check(n);
		}	
		return count;
			
	}
}

Output:


Question: Write a program to find the cube of a given number

Solution:

import java.util.Scanner;

public class Recursive5
  {
	static int i =1;
	static int p =1;
	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		System.out.print("Enter a number:");
		int n = s.nextInt();
		System.out.print("The cube of " + n+ " is " + cal(n));
	}

	public static int cal(int n)
	{ 
		if(i&jlt;=3)
		{
					p=p*n;
					i++;
					return cal(n);
		}						
			return p;
	}
}
output:


Computer and its generations




In this modern world we see computers everywhere and all over the world. Computers has been part of all industries be it transportation, communication, Medical, Education. Starting from personal computers to smart phones to tablets all are computers that has changed the way we live our lives and undoubtedly made a better place to live in. As computers are present in all the industries it is necessary for us to be computer literates and keep up to date with advancement of technology. The term computer can be defined as an electronic device which helps humans in many different ways. It can be used to store data, play games, write, read and watch all sort of things one likes. The chip that is present in the computer makes the computer work. The computers understands data as 1s and 0s and unique combination of zeros and ones (Binary numbers) makes the computer do complex works. Computers consists of two parts hardware and software. Hardware are the parts of the computer which we can touch and feel (E.g.: Keyboard, mouse monitor) and software is the program inside the hard disk of the computer that instructs the hardware. To communicate with a computer we need to learn computer languages which are basically of two types’ high level and low level. Hence computers play a very major role in our life.

Father of computer is Charles Babbage but the Person who purposed the idea of modern computer is Alan Turing.

5 Generations of Computers




  • First generation Computers: Use of vacuum tubes for circuitry and magnetic drums for storage. It was huge, expensive and very limited. It could not do multitasking.

  • Second generation Computers: Vacuum tubes were replaced by transistors. It became cheaper, smaller and faster compared to first generation computers.

  • Third generation Computers: Introduction of IC (integrated circuit). The usage of IC drastically reduced the size of the computers. Operating systems, input and output devices were also used from third generation. It could do multitasking.

  • Fourth generation Computers: Microprocessors were used which led to development of lab-size computers. Computer had become available in the market and were powerful.

  • Fifth generation Computers: Introduction of AI (Artificial Intelligence) and bio metric sensors. Computer became more advanced and faster.


C program using all 32 keywords available in ANSCII

Question:WAP in c using all 32 keyword available in ANSCII

solution

#include ⁢stdio.h>
#include ⁢stdlib.h>
const signed sub = 5;
typedef enum number {student1, student2, student3};
union Job {
     unsigned int  Tyear;
     volatile int Lyear;
} T;
extern float grade=3.0;
 struct
{
    char fn[12],ln[8];
    short int sn,cpl,egp,mat,tsm,phy,t;
     float per;
}student[3];
static long int i=0;
int main()
{
   auto int choice;
    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 EGP101 marks:");
        scanf("%d",&student[i].egp);
        printf("Enter MAT102 marks:");
        scanf("%d",&student[i].mat);
        printf("Enter TSM101 marks:");
        scanf("%d",&student[i].tsm);
        printf("Enter PHY101 marks:");
        scanf("%d",&student[i].phy);
        student[i].t = student[i].phy+student[i].tsm+student[i].mat+student[i].egp+student[i].cpl;
        student[i].per=student[i].t/sub;
    }
    retry:
    printf("Press\n 1: to see Highest Percentage\n 2:to see overall grading\n 3:to print result\n" );
    scanf("%d",&choice);
    switch(choice)
    {
        case 1: printf("the Highest percentage is:");
                topper();
                break;
        case 2:printf("Analysis:");
                news();
                break;
        case 3:printf("Printing result:");
                printingresult();
                break;
        default: printf("Wrong Choice\n");
                goto retry;
    }
    return 0;

}
void printingresult()
{
     printf("\nstd.no        name       cpl        phy       mat       egp             tsm           total           per\n");
     i=0;
        do
    {
        printf("%d\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t\t%f\n",student[i].sn,student[i].fn,student[i].ln,student[i].cpl,student[i].phy,student[i].mat,student[i].egp,student[i].tsm,student[i].t,student[i].per);
                i++;
    }while(i&lt3);
}
void topper()
{
    register double max;
    for(i =student1;i&lt=student3;i++)
    {
        if(max>student[i].per)
        {
            continue;
        }
        else
        {
                 max = student[i].per;
        }
    }
    printf("%4f",max);
}
void news()
{
    T.Lyear=2020;
    printf("Result in year: %d",T.Lyear);
    printf("\nGrade last year: %f",grade);
    T.Tyear=2021;
    printf("\nResult this year %d",T.Tyear);
    grade = student[0].per+student[1].per+student[2].per;
    printf("\nOverall Grade:%f",(grade/3));

}

output

Posted in

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

Posted in

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: