Code Review

Data types. Variables. Operators

Git/GitHub/Best Practice

  • "Code smell: Magic Number - Solution: Named Constants"

  • "Violation: 'nameVariable' was not used for variable naming - Solution: Rename variable"

  • "Violation: Useless blank lines - Solution: Remove blank lines"

  • 1 Pull Request ~ 1 issue

?

public class Task01 {
    public static void main(String[] args) {
        int x = 9;
        int y = 5;
        double b = x/y;
        double a =x%y;
        System.out.println("результат деления x на y - " + b);
        System.out.println("остаток от деления x на y - " + a);

    }
}

?

public class Task03 {
    public static void main(String[] args) {
      int r = 9;
     double s = Math.PI*r*r;
     double l = Math.PI*2*r;
        System.out.println("Площадь окружности - " +String.format("%.2f",s));
        System.out.println("Длина окружности - " + String.format("%.2f",l));
    }
}

?

package lesson02;

public class Task04 {
    public static void main(String[] args) {
        int n = 666;
        int sum = n/100 + n%100/10 + n%100%10;
        System.out.println("Сумма цифр числа n равна - " + sum);
    }
}

?

package lesson02;

public class Task01 {
    public static void main(String[] args) {
        int x = 5;
        int y =  2;
        int res1 = x / y;
        int res2 = x % y;

        System.out.println(res1);
        System.out.println(res2);



    }
}

?

package lesson02;

public class Task02 {
    public static void main(String[] args) {

        int x = 5;
        int y =  2;
        int per = x * 2 + y * 2; /*   it's  the perimeter of a rectangle */
        int area = x * y; /* It's the area of a rectangle */

        System.out.println(per);
        System.out.println(area);


    }

}

?

public class Task04 {
    public static void main(String[] args) {
        int abc = 747;
        int c = abc % 10;
        int ab = abc / 10;
        int b = ab % 10;
        int a = ab / 10;
        int sum = a + b + c;
        System.out.println(sum);

    }
}

?

package lesson02;

public class Task05 {
    public static void main(String[] args) {
        double n = 3.00;
      double a = n % 1; // fractional part
        boolean fract = 0.0 == a;

        System.out.print("the number dosen't has a fractional part: ");
        System.out.println(fract);



       /*  Old solution
       System.out.println(a);
        if (a > 0)
            System.out.println("tne number n  have a fractional part.");
        else
            System.out.println("the number n dosen't have a fractional part."); */
    }
}

?

public class lesson2task1{
    public static void main(String...arg){
        int x=7;
        int y=5;
        float b=(float)x/y;
        System.out.println(x+"/"+y+"="+b);


    }
}

?

static int getNumberFullTrucks(int cargo, int carryingCapacity) {
    int totalTrucks = cargo / carryingCapacity;
    return totalTrucks;
}

?

static float getTotalDepositAmount(int depositAmount, int depositYears, int depositAnnualPercentage) {
    float totalAmount = depositAmount+((float)(depositAmount*depositAnnualPercentage) / 100) * depositYears;
    return totalAmount;
}

?

static float getDistance(float milliseconds) {
    float speed = (float)(SOUND_SPEED / 3.6);
    float time = milliseconds/1000;
    float distance = speed * time;
    return distance;
}

?

static int calculateDeviationStandardWeight(int height, int weight) {
int standartWeight = height - 110;
int extraWeight = weight - standartWeight;
    return extraWeight;
}

?

static String getPlayingTime(int playingTimeInSeconds) {
    //SimpleDateFormat playingTime = new SimpleDateFormat("d:h:m:s");
    //String result = playingTime.format(new Date(playingTimeInSeconds*1000));
    int day = playingTimeInSeconds / 86400;
    playingTimeInSeconds = playingTimeInSeconds - day*86400;
    int hour = playingTimeInSeconds / 3600;
    playingTimeInSeconds = playingTimeInSeconds - hour*3600;
    int minutes = playingTimeInSeconds / 60;
    playingTimeInSeconds = playingTimeInSeconds - minutes*60;


    return day + " " + hour + ":" + minutes + ":" + playingTimeInSeconds;
}

?

public class Lesson2Task4 {
    public static void main(String[] args) {
        int n = 287;
        int first_n = n / 100;
        int second_n = ((n / 10) % 10);
        int third_n = n % 10;
        int sum = first_n + second_n + third_n;
        System.out.println(sum);
    }
}

?

public class Lesson2Task5 {
    public static void main(String[] args) {
        double a = 11.0;
        double PI = 3.14;
        System.out.println(a % 1);
        System.out.println(PI % 1);

    }
}

?

public class Task03 {
    public static void main(String[] args) {
        double r;
        Scanner in = new Scanner(System.in);
        System.out.println("Введите радиус:");
        r = Double.parseDouble(in.nextLine());
        System.out.println("Вывести площадь круга:" + 2 * Math.PI * r );
        System.out.println("Вывести длину окружности:" + Math.PI * Math.pow(r,2.0));
    }
}

?

public class Task04 {
    public static void main(String[] args) {
        int n;
        Scanner in = new Scanner(System.in);
        System.out.println("Введите целое трехзначное число:");
        n = in.nextInt();
        int d1 = n % 10;
        int d2 = (n % 100 ) / 10;
        int d3 = n / 100;
        System.out.println("Cумма цифр числа:" + (d1 + d2 + d3));

    }
}

?

public class Task05 {
    public static void main(String[] args) {
        double x;
        Scanner in = new Scanner(System.in);
        System.out.println("Введите число:" );
        x = Double.parseDouble(in.nextLine());
        if ((x % 1)==0){
            System.out.println("Число целое");
        }else {
            System.out.println("Число с вещественной частью");
        }

    }
}

?

static float getTotalDepositAmount(int depositAmount, int depositYears, int depositAnnualPercentage) {
    return (float) depositAmount * (float) depositAnnualPercentage / 100 * (float) depositYears + (float) depositAmount;
}

?

static float getDistance(float milliseconds) {
    float wholeDistancef =(1191.6f/3600)*milliseconds;
    return wholeDistancef;
}

?

static String getPlayingTime(int playingTimeInSeconds) {
    //TODO
    // Код, решающий задачу пишем ниже, при этом используя параметры метода
    int days, hours, minutes, seconds;
    days = playingTimeInSeconds / 60 / 60 / 24;
    hours = playingTimeInSeconds / 60 / 60 - (days * 24);
    minutes = playingTimeInSeconds / 60 - (days * 24 * 60) - (hours * 60);
    seconds = playingTimeInSeconds - (days * 24 * 60 * 60) - (hours * 60 * 60) - (minutes * 60);

    System.out.printf("%s %s:%s:%s", days,
            hours < 10 ? "0" + hours : hours,
            minutes < 10 ? "0" + minutes : minutes,
            seconds < 10 ? "0" + seconds : seconds);


    return String.format("%s %s:%s:%s", days,
            hours < 10 ? "0" + hours : hours,
            minutes < 10 ? "0" + minutes : minutes,
            seconds < 10 ? "0" + seconds : seconds);
}

?

public class task1 {
    public static void main(String[] args){
        int x=(int)(Math.random()*50);
        int y=(int)(Math.random()*20);
        System.out.println("Значение = "+x+" см.");
        System.out.println("Значение = "+y+" см.");
        System.out.println("Результат деления = "+x/y+" см.");
        System.out.println("Остаток деления = "+x%y+" см.");
    }
}

?

public class task5 {
   public static void main(String[] args) {
       double c=(Math.random());
       System.out.println(c);

       double ost=c%0;
       if(ost==0)
           System.out.println("число не имеет вещ части");
       else;
           System.out.println("число с вещ частью");




   }
}

?

static float getTotalDepositAmount(int depositAmount, int depositYears, int depositAnnualPercentage) {
    float profitYear = (float) depositAmount * depositAnnualPercentage / 100;
    float totalDepositAmount = (float) depositAmount + profitYear * depositYears;
    return totalDepositAmount;
}