Java Report

Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

Visvesvaraya Technological University

“Jnana Sangama,” Belagavi-590 018

An Internship Report on
CORE JAVA
Submitted in partial fulfilment of requirement for the III & IV semester
Bachelor of Engineering in ELECTRONICS and
COMMUNICATION Engineering Submitted By
PRASHANTH A-[1CK21EC023]
Under the guidance of

PROF&HOD, Dept of ECE


CBIT-Kolar

C. BYREGOWDA INSTITUTE OF TECHNOLOGY


An ISO 9001 2015 Certified Institute
Department of ELECTRONICS and COMMUNICATION
Engineering
Srinivaspura Road, Kolar – 563101
2022-2023
C. BYREGOWDA INSTITUTE OF TECHNOLOGY
An ISO 9001 2015 Certified Institute
Department of ELECTRONICS and
COMMUNICATION Engineering
(Srinivaspura Road, Kolar (T&D) Kolar – 563101)

CERTIFICATE

This is Certified that the internship report entitled with “CORE JAVA” is a Bonafede work
carried out by PRASHANTH A bearing the university seat number 1CK21EC023 partial
fulfilment for the award of Bachelor of Engineering in Computer Science &Engineering of
the Visvesvaraya Technological University, Belagavi during the year 2022-2023.It is
certified that all corrections/suggestions indicated for the internal assessment have been
incorporated in the internship report. The internship report has been approved as it satisfies
the academic requirements in respect of internship report prescribed for the IV semester
Bachelor of Engineering Degree.

Signature of the Report Guide Signature of the HOD


& Co-ordinator Dr G K VENKATESH
DR. G K VENKATESH Prof & HOD,
Prof, Dept ECE, CBIT-Kolar
Dept of ECE, CBIT-Kolar
ABSTRACT

The word Core describes the basic concept of something, and here, the phrase 'Core Java'
defines the basic Java that covers the basic concept of Java programming language. We all are
aware that Java is one of the well-known and widely used programming languages, and to
begin with it, the beginner has to start the journey with Core Java and then towards the
Advance Java. The Java programming language is a general-purpose programming language
that is based on the OOPs concept. The ocean of Java is too deep to learn, i.e., as much you
learn more, you will know its depth. Java is a platform-independent and robust programming
language. The principle followed by Java is WORA that says Write Once, Run Anywhere.
The programming language is quite simple and easy to understand. But one should know that
Core Java is not different from Java. Java is complete in itself, but for the beginners, it is
natural that the beginner must begin with the core concepts of Java. In actual, Java has
different editions, where Core Java is one of the parts of an edition.

i
DECLARATION

I am PRASHANTH A bearing USN 1CK21EC023 student of 4th semester B.E, Computer


Scienceand Engineering of VTU, declare that this report entitled “CORE JAVA”, embodies
the reportof the internship carried out under the guidance of Prof. G K VENKATESH Dept.
of ECE, CBIT as partial fulfilment of the requirement of the award of the degree in Bachelor
of Engineering, Computer Science and Engineering, affiliated to Visvesvaraya Technological
University, Belagavi during the academic year 2022-23. Further the content embodies in the
internship report has not been submitted previously by anybody for the award of any other
degree.

[PRASHANTH A]-[1CK21EC023]

ii
ACKNOWLEDGEMENT

The completion of any work is a showcase of constant dedication and co-operation of many
people who lent their hands which went seen or unseen.

We are grateful to our Institution and Management, C. BYREGOWDA INSTITUTE OF


TECHNOLOGY with its ideals and inspirations for having provided us with the facilities,
which has made this project a success.

We would like to thank our beloved Principal Dr. APRAMEYAN S, CBIT for his kind
disposition for completing this undertaking successfully.

We express our heart full gratitude to Dr G K VENKATESH, Professor and HOD,


Department of Electronics & communication Engineering, CBIT, for giving us guidance,
valuable advice and support.

We extend our gratitude to our guide Prof. G K VENKATESH, Professor, Department of


ELECTRONICS & COMMUNICATION Engineering, CBIT for her valuable advice,
support andconstructive suggestions.

We also thank to all our professors and the entire department of ELECTRONICS &
COMMUNICATION Engineering for their co-operation and suggestions.

The report would be incomplete if I do not thank our parents and friends for their continuous
encouragement and moral support.

[PRASHANTH A]-[1CK21EC023]

iii
TABLE OF CONTENTS
ASBTRACT i
DECLARATION ii
ACKNOWLEDGMWNT iii
TABLE OF CONTENTS iv
LIST OF FIGURES v

CHAPTER NO CHAPTER NAME PAGE NO

1 INTRODUCTION TO COMPANY

1.1 Introduction 1

1.2 Vision 1

1.3 Services 2

1.4 Culture and values 2

1.5 Methodology Work 3

2 ABOUT PROJECT

2.1 Introduction to java 5

2.2 Learning Outcomes 10

2.3 Data types in java 13

2.4 Project on core java 15

3 CODE

3.1 Code 18

3.2 Result 20

3.3 Code conclusion 22

4 FUTURE ENHANCEMENT 23

iv
LIST OF FIGURES

FIGURE NO FIGURE NAME PAGE NO

1 Progoton logo 3

2 Rock, paper and scissor cycle 17

v
CHAPTER 1

INTRODUCTION TO COMPANY

1.1 Introduction

Progton is a B2B services and solutions company delivering complete ENTERPRISE


web solutions by capitalizing on a dedicated, knowledgeable and experienced cadre of multi-
talented team. During our time in the industry, we have focused our efforts on providing a full-
service solution for all of our clients’ needs. Our focus has been and will remain upon
developing and continually enhancing our relationship with our clients by ensuring that we
meet their expectations. Their success is ours as well. We design & build Web applications,
Mobile apps using technologies like Ruby on Rails, JavaScript, Node.js, Ember.js, Angular.js,
React.js, Android, iOS and many more Our mission is to add value for our customers by helping
them achieve their desired level of quality and safety for their products, assets and processes.

Progton Technologies is a software development company with 15+ years of experience


in building billion-dollar enterprise software and applications with top developers having
efficiency in proven technologies imbibing the industry-standard coding and security practices
with ethics and integrity. Our innovations and products have successfully been able to raise
billion-dollar investments from top VCs and investment firms such as Sequoia, IP Ventures, B
Ventures, and Cantos, etc.

1.2 Vision

“To be the most innovative Software Services, Consulting and Development Company,
and to be a committed partners of our Customers and Representatives.” Progton is on a mission
to accelerate the business of our customers by embracing the idea of quality and speed to deliver
innovative solutions. We do this with the help of our exceptionally.

1
CORE JAVA INTRODUCTION

where we encourage them to innovate, explore, automate and take ownership of their own
and company’s growth both technically and professionally. This is possible because of our
open work environment and culture that encourages a clear focus on delivering high-quality
software solutions with the highest level of customer satisfaction.
1.3 Services

 Web development

 Mobile app development

 UI / UX Designing

 Cloud Devops

 Digital Marketing

 AI / ML Services

 Data Services
1.4 Culture and values

 Trust in God

 Customer First

 Mentor Based

 Knowledge Sharing

 Experiment, fail fast and Succeed Faster

 All are Equal

 Trust & Integrity

 Grow Together

 Teamwork

 Passion

 Hard work & Excellence

 Innovation

Dept of ECE-CBIT-KOLAR 2 2022-2023


CORE JAVA INTRODUCTION

Fig no: 1.1


Company logo

1.5 Methodology Work

Requirement Analysis:
We compile all the data obtained from our customers and carry out a complete
analysis to find possibilities in existing business processes, to take into account the current
processes and technologies of our customers and how they can interact with future design.
And how we can deliver faster thereby minimizing the lead time to market.

Designing:

We Build a holistic and appropriate solution delivery architecture, prioritizing


activities into three classes Vital, Relevant & Optional on the nature of business
requirements and current investments. And then design the workflows, mock-ups and high-
fidelity prototypes to support the need and visualize the application and make sure it is as
per the idea of our customer.

Architecture:

Our process of software design and architecture is usually separated into four views:
conceptual, module, execution, and code. This separation is based on our study of the
software architectures of large systems, and on our experience designing and reviewing
software architectures. We architect the solution as per the requirements & design so that the
application supports all the requirements and is easy to scale. We provide a project plan
focused on compliance guidelines and best practices in the industry, using change
management to ensure adequate management, efficient communication, and contingency
planning.

Dept of ECE-CBIT-KOLAR 3 2022-2023


CORE JAVA INTRODUCTION

Development:

Develop a project plan with comprehensive implementation criteria, consideration of


resource mapping, scheduling, and execution of processes. All the mock-ups and workflows
are converted into pieces for development. We select features as per the priority and start
developing upon the language required and agreed on. Monitor the progress continuously
through the development period.

Staging Release:

We enable a staging environment for the initial release to make sure the application
is coming up as we planned. Here we test and rigorously roll out features so that the
application is tested with all criteria’s, bug -free and make sure we achieve the business
needs. And make the application Production ready.

CI/CD With Testing:

At Progton Technologies, CI/CD pipeline is in practice to build efficient- application


while reducing risk and time in the lifecycle of software development.

Quality Assurance:

Our Quality Assurance covers the entire process of the development cycle with both
Functional testing and Non-Functional testing to make sure that a product has met its
specification in the topmost qualitypossible along with the business requirements ofthe client.

Going Live & Monitoring:


At Progton Technologies, we ensure that before the application is published, a load
test and Performance test is performed on all parts of your environment to ensure that the
current architecture setup meets the metrics

Dept of ECE-CBIT-KOLAR 4 2022-2023


CHAPTER 2

ABOUT PROJECT

2.1 Introduction to Java


Java is a programming language and a platform. Java is a high level, robust, object-
oriented and secure programming language. Java was developed by Sun Microsystems
(which is now the subsidiary of Oracle) in the year1995. James Gosling is known as the
father of Java. Before Java, its name was Oak. Since Oak was already a registered company,
so James Gosling and his team changed the name from Oak to Java.
Platform: Any hardware or software environment in which a program runs, is known
as a platform. Since Java has a runtime environment (JRE) and API, it is called a platform.

2.1.1 Application:

According to Sun, 3 billion devices run Java. There are many devices
where Java is currently used. Some of them are as follows:
1. Desktop Applications such as acrobat reader, media player, antivirus, etc.

2. Web Applications such as irctc.co.in, javatpoint.com, etc.

3. Enterprise Applications such as banking applications.

4. Mobile

5. Embedded System

6. Smart Card

7. Robotics

8. Games, etc.
2.1.2 Types of Java Applications:

There are mainly 4 types of applications that can be created using Java programming:

1. Standalone Application

Standalone applications are also known as desktop applications or window- based

5
CORE JAVA DESCRIPTION TO PROJECT

applications. These are traditional software that we need to install on every machine.
Examples of standalone application are Media player, antivirus, etc. AWT and Swing are
used in Java for creating standalone applications.

2. Web Application

An application that runs on the server side and creates a dynamic page is called a web
application. Currently, Servlet, JSP, Struts, Spring, Hibernate, JSF, etc. technologies are
used for creating web applications in Java.

3. Enterprise Application

An application that is distributed in nature, such as banking applications, etc. is called


an enterprise application. It has advantages like high-level security, load balancing, and
clustering. In Java, EJB is used for creating enterprise applications.
4. Mobile Application

An application which is created for mobile devices is called a mobile application.


Currently, Android and Java ME are used for creating mobile applications.
2.1.3 HISTORY

The Java platform and language began as an internal project at Sun Microsystems
in December 1990, providing an alternative to the C++/C programming languages. Engineer
Patrick Naughton had become increasingly frustrated with the state of Sun's C++ and C
application programming interfaces (APIs) and tools. While considering moving to NeXT,
Naughton was offered a chance to work on new technology and thus the Stealth Project was
started.
The Stealth Project was soon renamed to the Green Project with James Gosling
and Mike Sheridan joining Naughton. Together with other engineers, they began work in a
small office on Sand Hill Road in Menlo Park, California. They were attempting to develop
a new technology for programming next generation smart appliances, which Sun expected
to be a major new opportunity. The team originally considered using C++, but it was rejected
for several reasons. Because they were developing an embedded system with limited
resources, they decided that C++ needed too much memory and that its complexity led to
developer errors. The language's lack of garbage collection meant that programmers had to

Dept of ECE-CBIT-KOLAR 6 2022-2023


CORE JAVA DESCRIPTION TO PROJECT

to manually manage system memory, a challenging and error- prone task. The team was also
troubled by the language's lack of portable facilities for security, distributed programming,
and threading. Finally, they wanted a platform that could be easily ported to all types of
devices.

Bill Joy had envisioned a new language combining Mesa and C. In a paper called
Further, he proposed to Sun that its engineers should produce an object-oriented environment
based on C++. Initially, Gosling attempted to modify and extend C++ (that he referred to as
"C++ ++ --") but soon abandoned that in favor of creating a new language, which he called
Oak, after the tree that stood just outside his office. By the summer of 1992, they were able to
demonstrate portions of the new platform including the Green OS, the Oak language, the
libraries, and the hardware. Their first attempt, demonstrated on September 3, 1992, focused
on building a personal digital assistant (PDA) device named Star7 that had a graphical
interface and a smart agent called "Duke to assist the user.

2.1.4 Features of java

 Java is simple, easy to design, easy to write, and therefore easy to compile, debug, and learn
than any other programming languages.

 Java is object-oriented, that is used to build modular programs and reusable code in other
application.

 Java is platform-independent and flexible in nature. The most significant feature of Java is
to run a program easily from one computer system to another.

 Java works on distributed environment. It is designed to work on distributed computing,


any network programs in Java is same as sending and receiving.

● data to and from a file.

● Java is secure. The Java language, compiler, interpreter and runtime environment are
securable.

Dept of ECE-CBIT-KOLAR 7 2022-2023


CORE JAVA DESCRIPTION TO PROJECT

● Java is robust. Robust means reliability. Java emphasis on checking for possible errors, as
Java compilers are able to detect many errors problem in program during the execution of
respective program code.

● Java supports multithreaded. Multithreaded is the path of execution for a program to perform
several tasks simultaneously within a program. The java come with the concept of
Multithreaded Program. In other languages, operating system-specific procedures have to
becalled in order to work on multithreading.

● Java fully follows oops. The Simple Types

● Java defines eight simple (or elemental) types ofdata: byte, short, int, long, char, float, double,
and Boolean.

2.1.5 Type Conversion and Casting

If you have previous programming experience, then you already know that it is fairly
common to assign a value of one type to a variable of another type. If the two types are
compatible, then Java will perform the conversion automatic ally. For example, it is always
possible to assign an int value to a long variable. However, not all types are compatible, and
thus, not all type conversion ns are implicitly allowed. For instance, there is no conversion
defined from double to byte. To do so, you must use a cast, which performs an explicit
conversion between incompatible types. Let's look at both automatic type conversions and
casting.

2.1.6 Inheritance in Java

Inheritance is a compile-time mechanism in Java that allows you to extend a class


(called the base class or super class) with another class (called the derived class or subclass).
This mechanism of deriving a new class from existing/old class is called inheritance. The
old class is known as base class, super class or parent class and the new class is known as
sub class, derived class, or child class. The inheritance allows subclasses to inherit all prop

Dept of ECE-CBIT-KOLAR 8 2022-2023


CORE JAVA DESCRIPTION TO PROJECT

-erties (variables and methods) of their parent classes.

The different forms of inheritance are:

● Single inheritance (only one super class)

● Multiple inheritance (several super classes)

● Hierarchical inheritance (one super class, many sub classes)

● Multi-Level inheritance (derived from a derived class)

● Hybrid inheritance (more than two types)

● Multi-path inheritance (inheritance of some properties from two sources).

2.1.7 Multithreading in java

In Java, Multithreading refers to a process of executing two or more threads


simultaneously for maximum utilization of the CPU. A thread in Java is a lightweight
process requiring fewer resources to create and share the process resources. Multithreading
and Multiprocessing are used for multitasking in Java, but we prefer multithreading over
multiprocessing.
2.1.8 Thread

 sequentially executed stream of instructions

 Shares address space with other threads

 Has own execution context

 Multiple threads in process execute same program also known as lightweight process.

 Captures logical structure of problem

 May have concurrent interacting components

 Can handle each component using separate thread

 Simplifies programming for problem

Dept of ECE-CBIT-KOLAR 9 2022-2023


CORE JAVA DESCRIPTION TO PROJECT

 Better utilize hardware resources

 When a thread is delayed, compute other threads

 Given extra hardware, compute threads in parallel

 Reduce overall execution time

2.1.9 Constructors in Java

 In Java, a constructor is a block of codes similar to the method. It is called when an


instance of the class is created. At the time of calling constructor, memory for the object
is allocated in the memory.
 It is a special type of method which is used to initialize the object.
 Every time an object is created using the new () keyword, at least one constructor is
called.
 It calls a default constructor if there is no constructor available in the class. In such case,
Java compiler provides a default constructor by default.

Rules for creating Java constructor


There are two rules defined for the constructor.

 Constructor name must be the same as its class name


 A Constructor must have no explicit return type
 A Java constructor cannot be abstract, static, final, and synchronized

2.2 Learning Outcomes:


 The Enum data structure
 Switch Statements
 Defining Classes and Calling Methods
 Translating Business Rules into Java Classes
 Java basics, including variables, loops, conditionals, and methods

2.2.1Prerequisites
 Basic knowledge of Java programming concepts
 Java Development Kit (JDK) installed

Dept of ECE-CBIT-KOLAR 10 2022-2023


CORE JAVA DESCRIPTION TO PROJECT

 A Java Integrated Development Environment (IDE), such as Eclipse or IntelliJ


IDEA
2.2.2 Java Future Scope and Career Opportunities

1. Java Developer
The future of Java programming language is Java Developers. Working on mobile
applications to middleware, the future of Java developers is evolving. Java developers must
be aware of Core Java, Spring, JavaScript, HTML, CSS, Database and another Client-side
programming. Courses are available at leading IT academies like Logic Rays Academy,
Ahmedabad where you can get career opportunities like web developer, tester, graphic
designer, application developer, Software developer, or even a professional teacher in
JAVA.
2. DevOps Engineer
The profession of a Devop Engineer requires applying several practices of DevOps
and Java app development concepts. You will be the people-first approach as continuous
integration will be a part of the work. The use of microservices instead of monolithic Java
applications will be there.

3. Solution Architect

A Solution Architect creates a technical vision for a specific task of the organization’s
setback. As a problem solver, you will be in charge of designing, and managing the solution.
Depending upon the environment of the present and the technical aspects, the software
product is developed making a Solution Architect indispensable.
4. Mobile App Development

One of the promising Java career paths is being into Mobile App development.
Solving the challenges of tapping into the cloud for a better user experience is the core task
of this position. Every field finds a need for this career from retail to telecommunication,
healthcare, food industries, e-commerce, government organizations and others. Employers
need employees to develop mobile applications to suit their needs and generate revenue for
the business.
5. Java Web Development

If you are somebody with web technologies, aware of other frameworks, and can

Dept of ECE-CBIT-KOLAR 11 2022-2023


CORE JAVA DESCRIPTION TO PROJECT

create Java web projects, you are in for Java web development opportunities. The future of
Java developers in India is bright. Projects like Digital India saw their rise only due to Java
web development programmers. The technical know-how hence must be top-notch.
2.2.3 Java In the Next 10 Years

As one can see Java in the next 10 years, is already booming with the rise emergence of new
languages like Kotlin, Clojure, JavaScript, J Ruby, Ceylon and Scala. Java will be the
ultimate interface for various devices.
1. What is the scope of Java in future?

 Java developers’ future scope is huge not only in India but also abroad. India’s IT
services outsourcing industry with heavy revenue generation is increasing
rapidly.
 Java is popular in different domains like banking, retail, stock market, financial
services, big data, scientific and research community and other industries.
2. What are the industries using Java today?

The largest segments that use JAVA today are Computer Software and Information
Technology. The usage is in the healthcare industry, hospitality, tourism, education, food,
textile and other industries.
3. Is Java still in demand by 2022?

Java is evolving day in and out and is still in demand. This day the US has 44% of Java users
and the percentage is getting higher.
Salaries and Future of Java Developer in India

A fresher begins their salary up to 2 lacs p.a. The salary depends upon qualification,
expertise, and years of experience. The salary ranges anything from 5 lacs and above. If you
hold a master’ degree, expect a salary from 1.5 lac to 2. Lacs. Bachelor’s degree holders can
expect 1.10 lac to 1.25 lacs p.a. Employees with 8-12 years’ experience get 25 lacs.
Candidates with 16-20 years get 45 lacs.
To Sum Up the Future of Java

Companies using Java in India use object-oriented programming language. It is crucial to


learn the language for future projects and career paths.

Dept of ECE-CBIT-KOLAR 12 2022-2023


CORE JAVA DESCRIPTION TO PROJECT

2.3 Data types in java

Integers:

This group includes byte, short, int, and long, which are for whole-valued signed
numbers. Floating-point numbers This group includes float and double, which represent
numbers with fractional precision. All of these are signed, positive and negative values. Java
does not support unsigned, positive -only integers. The width of an integer type should not
be thought of as the amount of storage it consumes, but rather as the behavior it defines for
variables and expressions of that type. The Java run-time environment is free to use whatever
size it wants, as long as the types behave as you declared them. In fact, at least one
implementation stores bytes and shorts as 32-bit (rather than 8- and 16-bit) values to improve
performance, because that is the word size of most computers currently in use. The width
and ranges of these integer types vary widely, as shown in this table:

Byte

The smallest integer type is byte. This is a signed 8-bit type that has a range from –128
to127. Variables of type byte are especially useful when you're working with a stream of
data from a network or file. They are also useful when you're working with raw binary data
that may not be directly compatible with Java's other built-in types. Byte variables are
declared by use of the byte keyword. For example, the following declares two-byte variables
called b and c: byte b, c;

Short

Short is a signed 16-bit type. It has a range from –32,768 to 32,767. It is probably the
least- used Java type, since it is defined as having its high byte first (called big-endian
format). This type is mostlyapplicable to 16 -bit computers, which are becoming increasingly
scarce. Here are some examples of short variabledeclarations:

Ex: short s;

Dept of ECE-CBIT-KOLAR 13 2022-2023


CORE JAVA DESCRIPTION TO PROJECT

Int

The most commonly used integer type is int. It is a signed 32-bit type that has a range. Its
range is from –2,147,483,648 to 2,147,483,647. Any time you have an integer expression
involving bytes, shorts, ints, and literal numbers, the entire expression is promoted to int
before the calculation is done.

Double

Double precision, as denoted by the double keyword, uses 64 bits to store a value. Double
precision is actually faster than single precision on some modern processors that have been
optimized for high -speed mathematical calculations. All transcendental math functions, such
as sin (), cos (), and sqrt (), return double values. When you need to maintain accuracy over
many iterative calculations, or are manipulating large –valued numbers, double is the best
choice

Characters

This group includes char, which represents symbols in a character set, like letters and
numbers. In Java, the data type used to store characters is char. Java uses Unicode to
represent characters. Unicode defines a fully international character set that can represent all
of the characters found in all human languages. In Java char is a 16-bit type. The range of a
char is 0 to 65,536. There are no negative chars. The standard set of characters known as
ASCII still ranges from 0 to 127 as always, and the extended 8-bit character set, ISO-Latin-
1, ranges from 0 to 255.

Boolean
This group includes Boolean, which is a special type for representing true/false values.
You can use these types as -is, or to construct arrays or your own class types. Thus, they form
the basis for all other types ofdata that you can create. Java has a simple type, called Boolean,
for logical values. It can have only one of two possible values, true or false. This is the type
returned by all relational operators, such as a < b. Boolean is also the type required by the
conditional expressions that govern the control statements such as if and for.

Dept of ECE-CBIT-KOLAR 14 2022-2023


CORE JAVA DESCRIPTION TO PROJECT

2.4 Project on core java

2.4.1 Introduction
Rock-Paper-Scissors is a game famous for being played by not only children, but people of
all ages. Here you will learn how to write a simple Java program to play the game against a
computer. Whether you are fairly new to programming or not, this presents a useful project
to either practice writing code or freshen up on your Java skills.

2.4.2 Procedure and steps to develop code for Rock-Paper-Scissors


The java file should consist of a public class of the same name and a main () method where
we will put all of the code.
First let’s get input:
The first step is to get input from the user. We want to let our user choose what move they want
to make, right? We do this with the Scanner class, which needs to be imported at the top of our
program via java. util. Scanner. In addition, we will declare and initialize a Scanner object
within our main () method like this:

This is good because the Scanner class provides many useful methods for getting input
from the user, such as the method next Line () which returns a captured line of typed text.
Furthermore, this text can be stored in a String variable called player Move which can be used
later for comparing the user’s move against the computers. next Line () is called directly on us
object scanner and note the lowercase ‘s’ because we are calling it on the object.Now the
program will ask the player to make a move and after typing either “rock”, “paper” or
“scissors” the move will be saved in player Move.

Random class for generating randomness which we will use to get a number between 0 and 2
(0, 1 or 2), each one corresponding to one of the three moves (rock, paper or scissors). To do
this we the computer needs to make a move as well and we want it to be random. Luckily for
us there need two things: an object of type Random and an int variable to store the random
integer. In addition, we can call next Int (3) on the object to get a value from 0 to 2. Do not
forget to import java. util. Random at the top of your program! Now we will declare a String
variable called computer Move and below it we will decide what it should contain. Decisions
are easily done with the help of conditions. So, this is exactly what we will be doing with if-
elseif-else blocks. Now every random integer from 0 to 2 will assign

Dept of ECE-CBIT-KOLAR 15 2022-2023


CORE JAVA DESCRIPTION TO PROJECT

computer Move a specific move.


So, who wins?
A Rock-Paper-Scissors game requires comparing the moves of both players, which can
be done with more if-elseif-else blocks, but this could be very long and unreadable. Instead,
there is a much easier solution: creating a player Wins () method under main () which returns
true if the player wins, false otherwise. Subsequently, this method would serve as a condition
in an if- elseif-else block in main () so the program could decide what result to print. Our
player Wins () method will look like this

See how the method takes two arguments: player Move and computer Move
and returns true for all the cases where the player wins. For example, if the player chose “rock”
then if computer Move. Equals("scissors") is true that means the player won, the other two
cases being a loss and a draw (which we will handle soon).

Printing the results:


Going back to our main () method we will write the other if-elseif-else now. There are
three possible scenarios: either the player wins, the player loses or it is a draw. Since player
Wins () can handle wins and losses we will check for draws in the first if-block, wins in the
if else- block. The condition playerMove.equals(computerMove) checks whether the choices
were equal.This main () method now calls player Wins () which is run from another place in
our file!

Let’s make it multiple rounds!


To make it so we can play the game over and over again we will need to wrap it all in a
method of its own like this:

playRockPaperScissors () is a static void method which takes the Scanner object as an


argument and does everything our program did before. The code is just in a different place.
Consequently, the game can now be run multiple times by looping the execution
of playRockPaperScissors () which is precisely what we will be doing next.
Rock-Paper-Scissors is often played in rounds. So, we will ask the user how many rounds they
want to play and then repeat the game that many rounds. A for-loop works well in this scenario
since we want to iterate a known number of times and we ask for input

Dept of ECE-CBIT-KOLAR 16 2022-2023


CORE JAVA DESCRIPTION TO PROJECT

again, using our Scanner object. Unfortunately, there are some issues with Java skipping line
using scanner.

Next Int () to immediately get an integer. We will instead use scanner. next Line () and
convert the received String to an int using Integer. Parse Int (). The final program looks
like this:

Extras

 Clean code: The code above is very long and maybe hard to read. In programming it
is often a good practice to divide your code into many smaller methods. Try doing
that with the contents of playRockPaperScissors ()!

 Error handling: The way this game is written right now there is much room for
logical errors. For example, the user could enter “Rock” or “rock” and the program
would not understand it, leading to weird outputs. Try writing a loop to keep asking
the user for an input that is correct before proceeding! Alternatively write a method
for converting text like “rock” to “rock”!

Fig no 2.1

Rock, paper and scissor game cycle

Dept of ECE-CBIT-KOLAR 17 2022-2023


CHAPTER 3
CODE

3.1 Code

import java. util. Random;

import java. util. Scanner;

public class RockPaperScissors {

public static void main (String [] args) {

Scanner scanner = new Scanner(System.in);

System. out. println("How many rounds of Rock-Paper-Scissors would you

like to play?");

int rounds = Integer.parseInt(scanner. nextLine());

for (int i = 0; i < rounds; i++)

{ playRockPaperScissors(scanner);

static void playRockPaperScissors(Scanner scanner) {

// Getting input from the user

System.out.println("Make a move! (rock/paper/scissors)");

String playerMove = scanner.nextLine();

// Getting input from the computer

Random random = new Random();

int randomNumber = random.nextInt(3);

String computerMove;

18
CORE JAVA CODE

if (randomNumber == 0) {
computerMove = "rock";
}
else if (randomNumber == 1)
{ computerMove = "paper";
}
else {
computerMove = "scissors";
}

System.out.println("Computer chose " + computerMove + "!");

// Print results

if (playerMove.equals(computerMove))
{System.out.println("It's a
draw!");
}
else if (playerWins(playerMove, computerMove))
{System.out.println("Player wins!");
}
else {
System.out.println("Computer wins!");

static boolean playerWins(String playerMove, String computerMove)


{if (playerMove.equals("rock")) {
return computerMove.equals("scissors");

}
else if (playerMove.equals("paper")) {

Dept of ECE-CBIT-KOLAR 19 2022-2023


CORE JAVA CODE

return computerMove.equals("rock");
}
else {

return computerMove.equals("paper");

3.2 Result:

How many rounds of Rock-Paper-Scissors would you like to play?

5 Make a move! (rock/paper/scissors)

paper

Computer chose rock! Player wins!

Make a move! (rock/paper/scissors)

rock

Computer chose rock! It's a draw!

Make a move! (rock/paper/scissors)

rock

Computer chose rock! It’s a draw!

Make a move! (rock/paper/scissors)

Dept of ECE-CBIT-KOLAR 20 2022-2023


CORE JAVA CODE

scissors

Computer chose paper!

Player wins!

Make a move! (rock/paper/scissors)

paper

Computer chose scissors!

Computer win

How many rounds of Rock-Paper-Scissors would you like to play? 4

Make a move! (rock/paper/scissors)

paper

Computer chose rock! Player wins!

Make a move! (rock/paper/scissors)

rock

Computer chose rock! It's a draw!

Make a move! (rock/paper/scissors)

rock

Computer chose rock! It’s a draw!

Make a move! (rock/paper/scissors)

scissors

Computer chose paper! Player wins!

Dept of ECE-CBIT-KOLAR 21 2022-2023


CORE JAVA CODE

3.3 Code conclusion:

 Games like these can be easily coded provided we know the logic and basic syntax of

the language we are to write code in. By using simple if-else statements we can build

up a Rock, Paper, Scissors Game in Java.

 The “Rock, Paper, Scissors” commercial equates an Android with unity, diversity, and

togetherness. It uses the friendship of a rock, paper, and scissors metaphor to a associate

an android with a better “mobile ecosystem that promotes a diverse range of options”

for customers. It celebrates diversity and uniqueness that may not be shown with

another popular phone.

 Implementing rock paper scissors in solidity

 Using hash functions first hand

 Understanding privacy in public blockchains

 Understanding randomness and the importance of true randomness

 Understanding attack vectors of rock paper scissors on blockchain

 This project introduced you to Java basics, including variables, loops, conditionals, and

methods. You can now expand on this project, adding features such as a scoring system,

improved user interface, or even multiplayer support. Keep practicing and exploring

the vast possibilities of Java programming

Dept of ECE-CBIT-KOLAR 22 2022-2023


CHAPTER 4

FUTURE ENHANCEMENT

 Predicting rock-paper-scissors (RPS) outcomes with machine learning involves training


a model to recognize patterns in the player's choices and use those patterns to make
predictions.

 Rock paper scissors AI game usually features a simple interface where the user picks
one of the three options, and the AI opponent reveals its choice almost instantaneously,
revealing the result of the round. Rock paper scissors AI game usually features a simple
interface where the user picks one of the three options, and the AI opponent reveals its
choice almost instantaneously, revealing the result of the round.

 By analyzing vast amounts of historical data and leveraging advanced algorithms, AI


can identify patterns, detect trends and make accurate predictions about future
outcomes.

 We can also bring game into visual form with appropriate CGI and other visual effects

 We can also include players profile of the player which keep track regarding the
performance of the player over a course of time. Performance may in terms of its
prediction, achievements and accuracy in prediction of future event.

 We can also include authentication and encryption to make game more protective and
denying the access to other people other than player.

 We can also make game online so that players can participate globally through global
network or server.

 Including chat box, emoji and may other conversation medium which enables the
players to share their experience, emotion and feedback while playing the game.

23

You might also like