blabla

mail@pastecode.io avatar
unknown
java
2 years ago
2.1 kB
2
Indexable
Never
package com.Methods;

public class Main {

    public static void main(String[] args) {
        int newScore = calculateScore("Tim", 500);
        System.out.println("New score is " + newScore);
        calculateScore(75);
        calculateScore();
        double centimeters = calcFeetAndInchesToCentimeters(6, 0);
        if (centimeters < 0.0) {
            System.out.println("invalid parameters");
        }
        calcFeetAndInchesToCentimeters(157);
    }

    public static int calculateScore(String playerName, int score) {
        System.out.println("Player " + playerName + "scored " + score + " points");
        return score * 1000;
    }

    public static int calculateScore(int score) {
        System.out.println("Unnamed player scored " + score + " points");
        return score * 1000;

    }

    public static int calculateScore() {
        System.out.println("No player name, no player score");
        return 0;
    }

    public static double calcFeetAndInchesToCentimeters(double feet, double inches) {

        if ((feet <= 0) || (inches < 0) || (inches > 12)) {
            System.out.println("Invalid feet or inches parameters");
            return -1;
        }
        double centimeters = (feet * 12) * 2.54;
        centimeters += inches * 2.54;
        System.out.println(feet + " feet," + inches + "inches = " + centimeters + " cm");
        return centimeters;
    }

    public static double calcFeetAndInchesToCentimeters(double inches) {

        if (inches < 0) {
            return -1;
        }
        double feet = (int) inches / 12;
        double remainingInches = (int) inches % 12;
        System.out.println(inches + " Inches is equal to " + feet + "feet and " + remainingInches + "inches");
        return calcFeetAndInchesToCentimeters(feet, inches);
    }


}

// rješenje:
Player Timscored 500 points
New score is 500000
Unnamed player scored 75 points
No player name, no player score
6.0 feet,0.0inches = 182.88 cm
157.0 Inches is equal to 13.0feet and 1.0inches
Invalid feet or inches parameters

Process finished with exit code 0