By GokiSoft.com| 19:36 27/06/2022|
Java Basic

[Source Code] Java Basic- OOP - Tạo máy tính cơ bản calculator trong java - C2108L

Java Basic- OOP - Tạo máy tính cơ bản calculator trong java


#Calcultor.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bt986;

/**
 *
 * @author std
 */
public class Calcultor {
    public float cong(float x, float y) {
        return x + y;
    }
    
    public float hieu(float x, float y) {
        return x - y;
    }
    
    public float tich(float x, float y) {
        return x * y;
    }
    
    public float thuong(float x, float y) {
        return x / y;
    }
}


#Main.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bt986;

import java.util.Scanner;

/**
 *
 * @author std
 */
public class Main {
    public static void main(String[] args) {
        Calcultor cal = new Calcultor();
        
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Nhap a = ");
        float a = Float.parseFloat(scan.nextLine());
        
        System.out.println("Nhap b = ");
        float b = Float.parseFloat(scan.nextLine());
        
        System.out.println("Tong: " + cal.cong(a, b));
        System.out.println("Hien: " + cal.hieu(a, b));
        System.out.println("Tich: " + cal.tich(a, b));
        System.out.println("Thuong: " + cal.thuong(a, b));
    }
}


Tags:

Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)