GithubHelp home page GithubHelp logo

kplanisphere / overloaded-method-demonstrations-in-java Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 1 KB

Proyecto 9 - Programación 2

Home Page: https://linktr.ee/planisphere.kgz

Java 100.00%
beginner-friendly code-snippets java-programming method-overloading object-oriented-programming object-oriented-programming-in-java oop overloaded-methods programming-education

overloaded-method-demonstrations-in-java's Introduction

Overloaded Method Demonstrations in Java

This repository contains a Java project that demonstrates the use of overloaded methods. The project includes classes for handling various types of input, performing calculations, and displaying results using methods with the same name but different parameters.

Features

  • Method Overloading: Demonstrates the concept of method overloading with multiple methods having the same name but different parameter lists.
  • User Interaction: Handles user input to demonstrate different overloaded methods.
  • Result Display: Outputs the results of the operations performed by the overloaded methods.

Code Snippets

Main Class

The main class initializes the program, handles user input, and invokes the overloaded methods.

public class Principal {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Impresiones impresiones = new Impresiones();

        System.out.print("Enter an integer: ");
        int intValue = scanner.nextInt();
        impresiones.print(intValue);

        System.out.print("Enter a double: ");
        double doubleValue = scanner.nextDouble();
        impresiones.print(doubleValue);

        System.out.print("Enter a string: ");
        scanner.nextLine(); // Consume newline
        String stringValue = scanner.nextLine();
        impresiones.print(stringValue);
    }
}

Impresiones Class

The Impresiones class contains overloaded methods for printing different types of inputs.

public class Impresiones {
    public void print(int value) {
        System.out.println("Integer value: " + value);
    }

    public void print(double value) {
        System.out.println("Double value: " + value);
    }

    public void print(String value) {
        System.out.println("String value: " + value);
    }
}

Usage

  1. Compile the Java files using a Java compiler (e.g., javac).
  2. Run the main class (Principal) to start the program.
  3. Follow the prompts to enter different types of input.
  4. The program will call the appropriate overloaded method and display the result.

Classes and Methods

  • Principal: The main class that handles user input and program execution.
    • main(String[] args): The entry point of the program.
  • Impresiones: A class containing overloaded methods for printing different types of input.
    • print(int value): Method that prints an integer value.
    • print(double value): Method that prints a double value.
    • print(String value): Method that prints a string value.

overloaded-method-demonstrations-in-java's People

Contributors

kplanisphere avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.