By GokiSoft.com| 19:56 13/02/2023|
Java Basic

Java Basic- Overview - Tổng hợp bài tập ôn luyện java basic - Kiểm tra 60 phút

Bài 1: Tính tổng các số nguyên từ 0->N (N được nhập từ bàn phím)

Bài 2: Nhập vào mảng số nguyên gồm N phần tử (N được nhập từ bàn phím) -> In ra các số chia hết cho 2

Bài 3 : Tạo lớp đối tượng Book gồm các thuộc tính sau

- tên sách, tác giả, nhà sản xuất, năm sản xuất

-Viết getter/setter và 2 hàm tạo 

- Viết hàm nhập/hàm hiển thị

- Tạo 2 đối tượng Book với 2 hàm tạo tương ứng trong phương thức main của lớp test. Nhập và hiển thị thông tin sách

Bài 4 :

Tạo lớp People gồm các thuộc tính : tên, địa chỉ

- tạo hàm nhập và hiển thị thông tin sinh viên

Tạo lớp Student kế thừa từ lớp People và có thêm các thuộc tính rollNo

- Ghi đè 2 phương thức nhập và hiển thị thông tin sinh viên

Tạo 2 đối tượng People và Student trong phương thức main của lớp Test. Thực hiện nhập và hiển thị thông tin của 2 đối tượng trên.

Bài 5:

Tạo lớp Vehicle gồm 3 phương thức abstract : running, input, display

Tạo lớp Car kế thừa từ lớp Vehicle có thuộc tính name, số bánh xe.

- Viết các hàm input và display và running (hàm running sẽ hiển thị dòng Car is running)

Tạo lớp BikeCycle kế thừa từ lớp Vehicle có thuộc tính name, số bánh xe

- Viết các hàm input và display và running (hàm running sẽ hiển thị dòng BikeCycle is running)

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

5

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

Phí Văn Long [T1907A]
Phí Văn Long

2020-03-11 10:02:15

bài 1 

/*
 * 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 Bai1_javabasic;

import java.util.Scanner;

/**
 *
 * @author PhiNong
 */
public class Main {
    public static void main(String[] args) {
        float sum = 0 , number ;
        Scanner scanner = new Scanner(System.in);
        
    do {
        System.out.println("Nhap vao so :");
        number = scanner.nextFloat();
        sum += number;
        
        if(sum > 1000)
              break;
    }while(number >= 0);
        System.out.println("Tong = " + sum);
    }
}
bài 2 :
/*
 * 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 Bai1_javabasic;

import java.util.Scanner;

/**
 *
 * @author Nong
 */
public class bai2 {
    public static void main(String[] args) {
        int n;
        Scanner scanner = new Scanner(System.in);
        
        do{
            System.out.println("Nhap vao so phan tu của mảng: ");
            n = scanner.nextInt();
        }while (n <=0 );
        
        int A[] = new int[n];
        
        System.out.println("Nhập các phần tử cho mảng: ");
        for (int i = 0; i < n; i++) {
            System.out.println("Nhập phần tử thứ" + i + ":");
            A[i] = scanner.nextInt();
        }
        System.out.println("Cac phần tử trong mảng chia hết cho 2 là : ");
        for (int i = 0; i < n; i++) {
            if (A[i] % 2 == 0){
                System.out.println(A[i] +"\t");
            }
        }
    }
}


Phí Văn Long [T1907A]
Phí Văn Long

2020-03-11 10:02:15

bài 1 

/*
 * 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 Bai1_javabasic;

import java.util.Scanner;

/**
 *
 * @author PhiNong
 */
public class Main {
    public static void main(String[] args) {
        float sum = 0 , number ;
        Scanner scanner = new Scanner(System.in);
        
    do {
        System.out.println("Nhap vao so :");
        number = scanner.nextFloat();
        sum += number;
        
        if(sum > 1000)
              break;
    }while(number >= 0);
        System.out.println("Tong = " + sum);
    }
}
bài 2 :
/*
 * 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 Bai1_javabasic;

import java.util.Scanner;

/**
 *
 * @author Nong
 */
public class bai2 {
    public static void main(String[] args) {
        int n;
        Scanner scanner = new Scanner(System.in);
        
        do{
            System.out.println("Nhap vao so phan tu của mảng: ");
            n = scanner.nextInt();
        }while (n <=0 );
        
        int A[] = new int[n];
        
        System.out.println("Nhập các phần tử cho mảng: ");
        for (int i = 0; i < n; i++) {
            System.out.println("Nhập phần tử thứ" + i + ":");
            A[i] = scanner.nextInt();
        }
        System.out.println("Cac phần tử trong mảng chia hết cho 2 là : ");
        for (int i = 0; i < n; i++) {
            if (A[i] % 2 == 0){
                System.out.println(A[i] +"\t");
            }
        }
    }
}


Phí Văn Long [T1907A]
Phí Văn Long

2020-03-11 10:02:12

bài 1 

/*
 * 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 Bai1_javabasic;

import java.util.Scanner;

/**
 *
 * @author PhiNong
 */
public class Main {
    public static void main(String[] args) {
        float sum = 0 , number ;
        Scanner scanner = new Scanner(System.in);
        
    do {
        System.out.println("Nhap vao so :");
        number = scanner.nextFloat();
        sum += number;
        
        if(sum > 1000)
              break;
    }while(number >= 0);
        System.out.println("Tong = " + sum);
    }
}
bài 2 :
/*
 * 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 Bai1_javabasic;

import java.util.Scanner;

/**
 *
 * @author Nong
 */
public class bai2 {
    public static void main(String[] args) {
        int n;
        Scanner scanner = new Scanner(System.in);
        
        do{
            System.out.println("Nhap vao so phan tu của mảng: ");
            n = scanner.nextInt();
        }while (n <=0 );
        
        int A[] = new int[n];
        
        System.out.println("Nhập các phần tử cho mảng: ");
        for (int i = 0; i < n; i++) {
            System.out.println("Nhập phần tử thứ" + i + ":");
            A[i] = scanner.nextInt();
        }
        System.out.println("Cac phần tử trong mảng chia hết cho 2 là : ");
        for (int i = 0; i < n; i++) {
            if (A[i] % 2 == 0){
                System.out.println(A[i] +"\t");
            }
        }
    }
}


Trương Công Vinh [T1907A]
Trương Công Vinh

2020-03-11 10:01:33



/*
 * 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 Bt997.Bai5;

/**
 *
 * @author DELL
 */
public abstract class Vehicle {
    public abstract void running();
    public abstract void input();
    public abstract void display();
}



Trương Công Vinh [T1907A]
Trương Công Vinh

2020-03-11 10:01:03



/*
 * 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 Bt997.Bai5;

import java.util.Scanner;

/**
 *
 * @author DELL
 */
public class Car extends Vehicle{
    String name;
    int soBanhXe;

    public Car() {
    }

    @Override
    public void running() {
        System.out.println("Car is running...");
    }

    @Override
    public void input() {
        Scanner scan = new Scanner(System.in);
        System.out.println("Car name  : ");
        name=scan.nextLine();
        System.out.println("So banh xe : ");
        soBanhXe = Integer.parseInt(scan.nextLine());
    }

    @Override
    public void display() {
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "Car{" + "name=" + name + ", soBanhXe=" + soBanhXe + '}';
    }
    
}



Trương Công Vinh [T1907A]
Trương Công Vinh

2020-03-11 10:00:24



/*
 * 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 Bt997.Bai5;

import java.util.Scanner;

/**
 *
 * @author DELL
 */
public class BikeCycle extends Vehicle{
    String name;
    int soBanhXe;

    public BikeCycle() {
    }

    @Override
    public void running() {
        System.out.println("BikeCycle is running...");
    }

    @Override
    public void input() {
        Scanner scan = new Scanner(System.in);
        System.out.println("BikeCycle name  : ");
        name=scan.nextLine();
        System.out.println("So banh xe : ");
        soBanhXe = Integer.parseInt(scan.nextLine());
    }

    @Override
    public void display() {
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "BikeCycle{" + "name=" + name + ", soBanhXe=" + soBanhXe + '}';
    }

}



Trương Công Vinh [T1907A]
Trương Công Vinh

2020-03-11 09:59:16



/*
 * 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 Bt997.Bai5;

/**
 *
 * @author DELL
 */
public class Test {
    public static void main(String[] args) {
        Vehicle C = new Car();
        Vehicle B = new BikeCycle();
        C.input();
        C.display();
        B.input();
        B.display();
        C.running();
        B.running();
    }
}



Đường Thanh Bình [T1907A]
Đường Thanh Bình

2020-03-11 09:53:08



/*
 * 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 Nhap.N.tubanphim;

import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class Main {
    public static void main(String[] agrs){
        float sum = 0;
        float number;
        Scanner scanner = new Scanner(System.in);
        
        do{
            System.out.println("Nhap vao so");
            number = scanner.nextFloat();
            sum += number;
            
        }while (number > 0);
        
        System.out.println("Tong =" + sum);
        
        
    }
    
}



thienphu [T1907A]
thienphu

2020-03-11 09:52:47

BT1

/*
 * 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 BT60p;

import java.util.Scanner;

/**
 *
 * @author Thien Phu
 */
public class BT01 {

    public static void main(String[] args) {
        int sum = 0;
        Scanner sc = new Scanner(System.in);
        System.out.println("nhap N :");
        int n = sc.nextInt();
        for (int i = 0; i <= n; i++) {
            sum += i;
        }
        System.out.println("Tong cac so nguyen tu 0 den N: " + sum);
    }
}
BT2




/*
 * 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 BT60p;

import java.util.Scanner;

/**
 *
 * @author Thien Phu
 */
public class BT02 {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap vao N phan tu vao mang");
        int n = sc.nextInt();
        int[] mang = new int[n];
        for (int i = 0; i < n; i++) {
            System.out.println("Nhap vao phan tu thu: " + (i + 1));
            mang[i] = sc.nextInt();
        }
        System.out.println("Phan tu trong mang chia het cho 2 la:");
        for (int i = 0; i < mang.length; i++) {
            if (mang[i] % 2 == 0) {
                System.out.print("\t" + mang[i] + "\t");
            }
        }
    }
}
BT3


/*
 * 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 BT60p;

import java.util.Scanner;

/**
 *
 * @author Thien Phu
 */
public class Book {

    String tenSach, tacGia, nhaSx;
    int namSx;

    public Book() {
    }

    public Book(String tenSach, String tacGia, String nhaSx, int namSx) {
        this.tenSach = tenSach;
        this.tacGia = tacGia;
        this.nhaSx = nhaSx;
        this.namSx = namSx;
    }

    public String getTenSach() {
        return tenSach;
    }

    public void setTenSach(String tenSach) {
        this.tenSach = tenSach;
    }

    public String getTacGia() {
        return tacGia;
    }

    public void setTacGia(String tacGia) {
        this.tacGia = tacGia;
    }

    public String getNhaSx() {
        return nhaSx;
    }

    public void setNhaSx(String nhaSx) {
        this.nhaSx = nhaSx;
    }

    public int getNamSx() {
        return namSx;
    }

    public void setNamSx(int namSx) {
        this.namSx = namSx;
    }

    @Override
    public String toString() {
        return "Book{" + "tenSach=" + tenSach + ", tacGia=" + tacGia + ", nhaSx=" + nhaSx + ", namSx=" + namSx + '}';
    }

    public void input() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap ten sach");
        tenSach = sc.nextLine();
        System.out.println("Nhap tac gia:");
        tacGia = sc.nextLine();
        System.out.println("Nhap nha san xuat: ");
        nhaSx = sc.nextLine();
        System.out.println("Nhap nam san xuat");
        namSx = Integer.parseInt(sc.nextLine());
    }

    public void display() {
        System.out.println(toString());
    }
}



/*
 * 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 BT60p;

/**
 *
 * @author Thien Phu
 */
public class MainBook {

    public static void main(String[] args) {
        Book bk = new Book();
        bk.input();
        bk.display();

        Book b = new Book("tai chinh", "smile", "Apha", 1997);
        b.display();
    }
}
BT4




/*
 * 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 BT60p;

import java.util.Scanner;

/**
 *
 * @author Thien Phu
 */
public class People {

    String ten, diachi;

    public People() {
    }

    public People(String ten, String diachi) {
        this.ten = ten;
        this.diachi = diachi;
    }

    public void input() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap ten: ");
        ten = sc.nextLine();
        System.out.println("Nhap dia chi");
        diachi = sc.nextLine();
    }

    public void display() {
        System.out.print(toString());
    }

    @Override
    public String toString() {
        return "People:" + "ten=" + ten + ", diachi=" + diachi + ':';
    }

    public String getTen() {
        return ten;
    }

    public void setTen(String ten) {
        this.ten = ten;
    }

    public String getDiachi() {
        return diachi;
    }

    public void setDiachi(String diachi) {
        this.diachi = diachi;
    }

}



/*
 * 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 BT60p;

import java.util.Scanner;

/**
 *
 * @author Thien Phu
 */
public class Student extends People {

    String rollNo;

    public Student() {
    }

    public Student(String rollNo, String ten, String diachi) {
        super(ten, diachi);
        this.rollNo = rollNo;
    }

    @Override
    public void display() {
        super.display();
        System.out.print("RollNo: " + this.rollNo);
    }

    @Override
    public void input() {
        super.input();
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap rollNo: ");
        rollNo = sc.nextLine();
    }

    public String getRollNo() {
        return rollNo;
    }

    public void setRollNo(String rollNo) {
        this.rollNo = rollNo;
    }

}



/*
 * 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 BT60p;

/**
 *
 * @author Thien Phu
 */
public class MainBT4 {

    public static void main(String[] args) {
        People p = new People();
        p.input();
        p.display();
        System.out.println("Nhap thong tin student:");
        Student st = new Student();
        st.input();
        st.display();
    }
}
BT5




/*
 * 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 BT60p;

/**
 *
 * @author Thien Phu
 */
public abstract class Vehicle {

    public abstract void running();

    public abstract void input();

    public abstract void display();
}



/*
 * 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 BT60p;

import java.util.Scanner;

/**
 *
 * @author Thien Phu
 */
public class Car extends Vehicle {

    String name;
    int sobanhxe;

    public Car() {
    }

    public Car(String name, int sobanhxe) {
        this.name = name;
        this.sobanhxe = sobanhxe;
    }

    @Override
    public void running() {
        System.out.println("Car is running");
    }

    @Override
    public void input() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap ten xe:");
        name = sc.nextLine();
        System.out.println("Nhap so banh xe");
        sobanhxe = Integer.parseInt(sc.nextLine());
    }

    @Override
    public void display() {
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "Car{" + "name=" + name + ", sobanhxe=" + sobanhxe + '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getSobanhxe() {
        return sobanhxe;
    }

    public void setSobanhxe(int sobanhxe) {
        this.sobanhxe = sobanhxe;
    }

}



/*
 * 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 BT60p;

import java.util.Scanner;

/**
 *
 * @author Thien Phu
 */
public class BikeCycle extends Vehicle {

    String name;
    int sobanhxe;

    public BikeCycle() {
    }

    public BikeCycle(String name, int sobanhxe) {
        this.name = name;
        this.sobanhxe = sobanhxe;
    }

    @Override
    public void running() {
        System.out.println("BikeCycle is running");
    }

    @Override
    public void input() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap ten xe dap:");
        name = sc.nextLine();
        System.out.println("Nhap so banh xe: ");
        sobanhxe = sc.nextInt();
    }

    @Override
    public void display() {
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "BikeCycle{" + "name=" + name + ", sobanhxe=" + sobanhxe + '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getSobanhxe() {
        return sobanhxe;
    }

    public void setSobanhxe(int sobanhxe) {
        this.sobanhxe = sobanhxe;
    }

}



/*
 * 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 BT60p;

/**
 *
 * @author Thien Phu
 */
public class MainBT5 {

    public static void main(String[] args) {
        Car car = new Car();
        car.input();
        car.display();
        car.running();

        BikeCycle bk = new BikeCycle();

        bk.input();
        bk.display();
        bk.running();
    }
}