Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java script class #8

Merged
merged 21 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions .github/workflows/approved-label.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
on: pull_request_review
name: Label approved pull requests
name: Add "approved" label when approved

on:
pull_request_review:
types:
- submitted

jobs:
labelWhenApproved:
name: Label when approved
add_label:
name: Add "approved" label when approved
runs-on: ubuntu-latest

steps:
- name: Label when approved
uses: abinoda/label-when-approved-action@1.0.5
env:
APPROVALS: "2"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ADD_LABEL: "approved"
REMOVE_LABEL: "awaiting%20review"
- name: Check for approval
id: check_approval
run: echo "::set-output name=approved::${{ github.event.review.state == 'approved' }}"

- name: Add "approved" label
if: steps.check_approval.outputs.approved == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Adding 'approved' label"
gh pr edit ${{ github.event.pull_request.number }} --add-label approved
64 changes: 0 additions & 64 deletions .github/workflows/codeql.yml

This file was deleted.

36 changes: 0 additions & 36 deletions .github/workflows/gh-pages.yml

This file was deleted.

51 changes: 37 additions & 14 deletions .github/workflows/jsBuild.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
name: Build
name: Continuous Integration for JS

on:
push:
branches:
- main
paths:
- "JavaScript/**"
- ".github/workflows/jsBuild.yml"
- 'JavaScript/**' # Include the JavaScript folder and its subdirectories
- '.github/workflows/jsBuild.yml'
pull_request:
types: [opened, synchronize, reopened]


jobs:
sonarcloud:
name: SonarCloud
build:
name: Code style and tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
node-version: 16
cache: npm

- name: 📦 Install dependencies
run: npm install

- name: 🧪 Run all tests
if: ${{ github.event_name == 'push' }}
run: npm run test

- name: 🧪 Run tests for changed files only
if: ${{ github.event_name == 'pull_request' }}
run: npm run test-changed

- name: 💄 Code style
run: npm run style

codespell:
name: Check for spelling errors
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: codespell-project/actions-codespell@master
with:
# file types to ignore
skip: "*.json,*.yml,DIRECTORY.md"
ignore_words_list: "ba,esy,yse,falsy"
Empty file removed Java/.gitkeep
Empty file.
63 changes: 63 additions & 0 deletions Java/Classes/OOPs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Defining the OOPs class
/**
*
* In Object-Oriented Programming (OOP), classes are used to define blueprints
* or templates for creating objects. Objects, in turn, are instances of classes
* and encapsulate both data (attributes or fields) and behavior (methods or
* functions). Java is a popular programming language that fully supports OOP
* principles, and you can create your own classes in Java to model and structure
* your programs.
*
*/
public class OOPs {
// Attributes (data members)
private String language;
private int year;

// Constructor to initialize attributes
public OOPs(String language, int year) {
this.language = language;
this.year = year;
}

// Method to display information about the OOPs language
public void displayInfo() {
System.out.println("Language: " + language);
System.out.println("Year of Introduction: " + year);
}

// Getter method for the language attribute
public String getLanguage() {
return language;
}

// Setter method for the language attribute
public void setLanguage(String language) {
this.language = language;
}

// Getter method for the year attribute
public int getYear() {
return year;
}

// Setter method for the year attribute
public void setYear(int year) {
this.year = year;
}

// Main method to demonstrate the OOPs class
public static void main(String[] args) {
// Create an instance of the OOPs class
OOPs oopsLanguage = new OOPs("Java", 1995);

// Display information about the OOPs language
oopsLanguage.displayInfo();

// Update the year attribute
oopsLanguage.setYear(1996);

// Display the updated information
oopsLanguage.displayInfo();
}
}
5 changes: 5 additions & 0 deletions JavaScript/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"presets": [
"@babel/preset-env"
]
}
1 change: 1 addition & 0 deletions JavaScript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
Empty file removed JavaScript/.gitkeep
Empty file.
5 changes: 5 additions & 0 deletions JavaScript/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run style
npm run test-changed
15 changes: 15 additions & 0 deletions JavaScript/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"arrowParens": "always",
"bracketSpacing": true,
"endOfLine": "lf",
"insertPragma": false,
"printWidth": 80,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
}
52 changes: 52 additions & 0 deletions JavaScript/Classes/Shape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* @author dev-madhurendra
*
*
* @class : In Object-Oriented Programming (OOP), a class is a blueprint or template
* for creating objects (instances). It defines the properties (also known as
* attributes or fields) and methods (functions) that the objects created from
* the class will have. JavaScript, starting from ECMAScript 6 (ES6), introduced
* support for classes, making it easier to work with OOP principles in JavaScript.
*
* Represents a basic shape.
* @class
*/
class Shape {
/**
* Create a new shape.
* @param {number} x - The X coordinate of the shape's position.
* @param {number} y - The Y coordinate of the shape's position.
*/
constructor (x, y) {
this.x = x
this.y = y
}

/**
* Get the X coordinate of the shape.
* @returns {number} The X coordinate.
*/
getX () {
return this.x
}

/**
* Get the Y coordinate of the shape.
* @returns {number} The Y coordinate.
*/
getY () {
return this.y
}

/**
* Move the shape to a new position.
* @param {number} newX - The new X coordinate.
* @param {number} newY - The new Y coordinate.
*/
move (newX, newY) {
this.x = newX
this.y = newY
}
}

export default Shape
28 changes: 28 additions & 0 deletions JavaScript/Classes/test/Shape.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Shape from '../Shape'
describe('Shape', () => {
it('should have correct initial position', () => {
const myShape = new Shape(10, 20)
expect(myShape.getX()).toBe(10)
expect(myShape.getY()).toBe(20)
})

it('should be able to move and update position', () => {
const myShape = new Shape(10, 20)
myShape.move(30, 40)
expect(myShape.getX()).toBe(30)
expect(myShape.getY()).toBe(40)
})

it('should create another shape with the correct initial position', () => {
const anotherShape = new Shape(5, 8)
expect(anotherShape.getX()).toBe(5)
expect(anotherShape.getY()).toBe(8)
})

it('should be able to move another shape and update position', () => {
const anotherShape = new Shape(5, 8)
anotherShape.move(15, 25)
expect(anotherShape.getX()).toBe(15)
expect(anotherShape.getY()).toBe(25)
})
})
Loading
Loading