Posts

Showing posts from April, 2022

Code for Library Management using Java

 Hey there, Arin here, The below code is for a usual Library Management using Java Language  The Conditions used for the above Topic is, You have to implement a library using Java Class "Library" Methods: addBook, issueBook, returnBook, showAvailableBooks Properties: Array to store the available books, Array to store the issued books we have used Concepts of constructors, object & classes, and Methods under classes. The Logic can be further be extended based on the Requirements: package com.company ; class Library { String [] books ; int no_of_books ; Library (){ this . books = new String [ 100 ]; this . no_of_books = 0 ; } void addBook ( String book ){ this . books [ no_of_books ] = book ; no_of_books ++; System . out . println ( book + " has been added!" ); } void showAvailableBooks (){ System . out . println ( "Available Books are:" ); for ( String book ...

CODE for Guess the Number using OOP's Concepts

 Hey there,  Arin here, Below I'm posting a code for the Topic: Guess the Number (OOPs Edition) Create a class Game, which allows a user to play "Guess the Number" game once. Game should have the following methods: Constructor to generate the random number takeUserInput() to take a user input of number isCorrectNumber() to detect whether the number entered by the user is true getter and setter for noOfGuesses The for the above Game is : package com.company ; import java.util.Random ; import java.util.Scanner ; class game { int number ; int noOfGuesses ; int inputNumber ; public int getNoOfGuesses () { return noOfGuesses ; } public void setNoOfGuesses ( int noOfGuesses ) { this . noOfGuesses = noOfGuesses ; } game (){ Random rand = new Random (); this . number = rand . nextInt ( 100 ); } boolean isCorrectNumber (){ if ( inputNumber == number ){ return true ; } else if ( inp...

Code for Creating a ROCK-PAPER-SCISSOR Game Using Java

Hey there,  Happy Coding! Just Don't Give up Yet BUD! So the code goes something like this that I'm about to provide below, This is something that I Learnt While taking a Java Course from Youtube, I aim to be a Developer Some day!  The Program gives three chances to the user to play, Rock is set as 0, Paper as 1 and Scissor as 2. This is checked with the random variable 'a' which for the Random class is imported.    package com.company ; import java.util.Random ; import java.util.Scanner ; public class problemtwo { public static void main ( String [] args ) { Random r = new Random (); Scanner sc = new Scanner ( System . in ); int j = 3 ; int a = r . nextInt ( 3 ); for ( int i = 1 ; i <= j ; i ++) { System . out . println ( "Enter \n 0 for Rock \n 1 for Paper \n 2 for Scissor " ); int b = sc . nextInt (); if ( a == b ) { System . out . println ...