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)

Nguyễn Anh Vũ [T2008A]
Nguyễn Anh Vũ

2021-02-22 09:51:23



*
 * 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.java;

/**
 *
 * @author Admin
 */
public class Bai1Java {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        int n, tong = 0;
        
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap so n ");
        n = scan.nextInt();
        if (n > 0) {
            for (int i = 0; i <= n; i++) {
                tong = tong + i;
                 }
            System.out.format("Tong tu 0 den n la: %d ", tong);
        } else {
            System.out.println("Nhap lai so n ");
        }
    }
    
}



vuong huu phu [T2008A]
vuong huu phu

2021-02-22 09:35:16


bai 3 -----Test
/*
 * 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 baittt;

/**
 *
 * @author Admin
 */
public class Test {
    public static void main(String[] args) {
     Book book1 = new Book("cuon sach 1","tac gia 1","nha xuat ban 1",1990);
     Book book2 = new Book();
     book2.Nhap();
     book2.Hien_thi();
    }
}



vuong huu phu [T2008A]
vuong huu phu

2021-02-22 09:29:43


bai 3-----Book
/*
 * 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 baittt;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Book {

    String Ten_sach, Tac_gia, Nha_san_xuat;
    int Nam_xuat_ban;

    public Book() {
    }

    public Book(String Ten_sach, String Tac_gia, String Nha_san_xuat, int Nam_xuat_ban) {
        this.Ten_sach = Ten_sach;
        this.Tac_gia = Tac_gia;
        this.Nha_san_xuat = Nha_san_xuat;
        this.Nam_xuat_ban = Nam_xuat_ban;

        System.out.format(" Ten cuon sach: %s , Ten tac gia: %s , Ten nha san xuat: %s , Nam xuat ban: %d ", Ten_sach, Tac_gia, Nha_san_xuat, Nam_xuat_ban);
    }

    public String getTen_sach() {
        return Ten_sach;
    }

    public void setTen_sach(String Ten_sach) {
        this.Ten_sach = Ten_sach;
    }

    public String getTac_gia() {
        return Tac_gia;
    }

    public void setTac_gia(String Tac_gia) {
        this.Tac_gia = Tac_gia;
    }

    public String getNha_san_xuat() {
        return Nha_san_xuat;
    }

    public void setNha_san_xuat(String Nha_san_xuat) {
        this.Nha_san_xuat = Nha_san_xuat;
    }

    public int getNam_xuat_ban() {
        return Nam_xuat_ban;
    }

    public void setNam_xuat_ban(int Nam_xuat_ban) {
        this.Nam_xuat_ban = Nam_xuat_ban;
    }
    Scanner scan = new Scanner(System.in);

    public void Nhap() {
        System.out.println();
        System.out.println("Nhap ten cuon sach: ");
        Ten_sach = scan.nextLine();
        System.out.println("Nhap ten tac gia: ");
        Tac_gia = scan.nextLine();
        System.out.println("Nhap ten nha san xuat: ");
        Nha_san_xuat = scan.nextLine();
        System.out.println("Nhap nam xuat ban: ");
        Nam_xuat_ban = scan.nextInt();
    }

    public void Hien_thi() {
        System.out.format(" Ten cuon sach: %s , Ten tac gia: %s , Ten nha san xuat: %s , Nam xuat ban: %d ", Ten_sach, Tac_gia, Nha_san_xuat, Nam_xuat_ban);
    }

}



vuong huu phu [T2008A]
vuong huu phu

2021-02-22 09:06:35


bai 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 baittt;

import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class bai_2 {

    public static void main(String[] args) {
        ArrayList<Integer> a = new ArrayList<>();
        int n, kt = 0;
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap so phan tu: ");
        n = scan.nextInt();

        for (int i = 1; i <= n; i++) {
            if (i % 2 == 0) {
                System.out.print(i + " ");
                kt++;
            }
        }
        if (kt == 0) {
            System.out.print("Khong co so nao chia het cho 2 ");
        }
    }
}



vuong huu phu [T2008A]
vuong huu phu

2021-02-22 08:54:36


bai 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 baittt;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class bai_1 {

    public static void main(String[] args) {
        // TODO code application logic here
        int n, tong = 0;

        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap so n ");
        n = scan.nextInt();

        if (n > 0) {
            for (int i = 0; i <= n; i++) {
                tong = tong + i;
            }
            System.out.format("Tong tu 0 den n la: %d ", tong);
        } else {
            System.out.println("Nhap lai so n ");
        }
    }
}



Nguyễn Hoàng Anh [C1907L]
Nguyễn Hoàng Anh

2020-04-01 13:29:50



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

/**
 *
 * @author Redmibook 14
 */
public abstract class Vehicle {
    abstract void running();
    abstract void input();
    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 April1Test60m;

/**
 *
 * @author Redmibook 14
 */
public class Car extends Vehicle {

    String name;
    int wheel;

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

    @Override
    void input() {

    }

    void input(String name, int wheel) {
        this.name = name;
        this.wheel = wheel;
    }

    @Override
    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 April1Test60m;

/**
 *
 * @author Redmibook 14
 */
public class Bicycle extends Vehicle {

    String name;
    int wheel;

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

    @Override
    void input() {

    }

    void input(String name, int wheel) {
        this.name = name;
        this.wheel = wheel;
    }

    @Override
    void display() {

    }
}



Vũ Việt Đức [C1907L]
Vũ Việt Đức

2020-04-01 13:24:46



/*
 * 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 lession8.bai4;

import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public class People {
    String name, address;

    public String getName() {
        return name;
    }

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

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public People() {
    }

    public People(String name, String address) {
        this.name = name;
        this.address = address;
    }
    
    public void show() {
        System.out.println("Thông tin: ");
        System.out.println("Tên: " + name);
        System.out.println("Địa chỉ: " + address);
    }
    
    public void input(){
        Scanner scanner = new Scanner(System.in);
        System.out.print("Tên: ");
        name = scanner.nextLine();
        System.out.print("Địa chỉ: ");
        address = scanner.nextLine();
    }
}



/*
 * 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 lession8.bai4;

import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public class Student extends People{
    String rollNo;

    public String getRollNo() {
        return rollNo;
    }

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

    @Override
    public String getName() {
        return name;
    }

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

    @Override
    public String getAddress() {
        return address;
    }

    @Override
    public void setAddress(String address) {
        this.address = address;
    }

    public Student() {
    }

    public Student(String rollNo, String name, String address) {
        super(name, address);
        this.rollNo = rollNo;
    }

    @Override
    public void input() {
        super.input(); 
        Scanner scanner = new Scanner(System.in);
        System.out.print("Nhập rollNo: ");
        rollNo = scanner.nextLine();
    }

    @Override
    public void show() {
        super.show(); 
        System.out.println("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 lession8.bai4;

/**
 *
 * @author ADMIN
 */
public class Test {
    public static void main(String[] args){
        People p = new People();
        Student std = new Student();
        
        System.out.println("Nhập thông tin cho people: ");
        p.input();
        
        System.out.println("Nhập thông tin cho student: ");
        std.input();
        
        p.show();
        std.show();
    }
}



Nguyễn Hoàng Anh [C1907L]
Nguyễn Hoàng Anh

2020-04-01 13:19:45



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

/**
 *
 * @author Redmibook 14
 */
public class People {

    public String name, address;

    public void input(String name, String address) {
        this.name = name;
        this.address = address;
    }

    public void display() {
        System.out.println("Name : " + name);
        System.out.println("address : " + address);
    }
}



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

/**
 *
 * @author Redmibook 14
 */
public class Student extends People {

    public String rollNo;

    public void input(String rollNo, String name, String address) {
        super.input(name, address);
        this.rollNo = rollNo;
    }

    @Override
    public void display() {
        super.display();
        System.out.println("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 April1Test60m;

import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author Redmibook 14
 */
public class TestStudent {
     public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Student student = new Student();
        ArrayList<Student> arrStudent = new ArrayList();
        for (int i = 0; i < 2; i++) {
            System.out.println("Nhap ten :");
            String name = input.nextLine();
            System.out.println("Nhap dia chi : ");
            String address = input.nextLine();
            System.out.println("Nhap rollNo : ");
            String rollNo = input.nextLine();
           
            student.input(name, address, rollNo);
            arrStudent.add(student);
        }
        for (int i = 0; i < 2; i++) {
            arrStudent.get(i).display();
        }
     }
}



hoangkhiem [C1907L]
hoangkhiem

2020-04-01 13:15:54



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

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Book {

    private String bookName;
    private String bookAuthor;
    private String producer;
    private int yearPublishing;

    public Book() {

    }

    public Book(String bookName, String bookAuthor, String producer, int yearPublishing) {
        this.bookName = bookName;
        this.bookAuthor = bookAuthor;
        this.producer = producer;
        this.yearPublishing = yearPublishing;

    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public String getBookAuthor() {
        return bookAuthor;
    }

    public void setBookAuthor(String bookAuthor) {
        this.bookAuthor = bookAuthor;
    }

    public String getProducer() {
        return producer;
    }

    public void setProducer(String producer) {
        this.producer = producer;
    }

    public int getYearPublishing() {
        return yearPublishing;
    }

    public void setYearPublishing(int yearPublishing) {
        this.yearPublishing = yearPublishing;
    }




    public void input() {
        //source code
        Scanner input = new Scanner(System.in);
        System.out.println("Mời nhập tên sách : ");
        bookName = input.nextLine();
        System.out.println("Mời nhập tên tác giả của cuốn sách :  ");
        bookAuthor = input.nextLine();
        System.out.println("Mời nhập nhà xuất bản của cuốn sách :");
        producer = input.nextLine();
        System.out.println("Mời nhập năm xuất bản của cuốn sách : ");
        yearPublishing = Integer.parseInt(input.nextLine());

    }

    public void display() {
        System.out.println("Tên sách : " + bookName);
        System.out.println("Tên tác giả : " + bookAuthor);
        System.out.println("Nhà xuất bản : " + producer);
        System.out.println("Năm xuất bản : " + yearPublishing);

    }
}



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

import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Test {

    public static void main(String[] args) {
        Book sach1 = new Book();
        Book sach2 = new Book("haha", "khiem", "dđ", 222);
        sach1.input();
        sach1.display();
        sach2.display();
    }
}



Đinh Vũ Anh [C1907L]
Đinh Vũ Anh

2020-04-01 13:15:02



package btap;
import java.util.Scanner;
/**
 *
 * @author Admin
 */
public class Bai1 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int t = 0;
        System.out.print("Nhập vào số n: ");
        int n = Integer.parseInt(scan.nextLine());
        for(int i = 1; i <= n; i++){
            t += i;
        }
        System.out.println("Tổng các số nguyên từ 0 đến " + n + " là: " + t );
    }
}



package btap;
import java.util.Scanner;
/**
 *
 * @author Admin
 */
public class Btap2 {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        System.out.print("Nhập vào n: ");
        int n = Integer.parseInt(scan.nextLine());
        int [] t = new int[n];
        for(int i = 0; i < n; i++){
            System.out.print("Nhập phần tử thứ " + (i + 1) +" :");
            t[i] = Integer.parseInt(scan.nextLine());
        }
        System.out.print("Các số chia hết cho 2 là:");
        for(int i = 0; i < n; i++){
            if(t[i] % 2 == 0){
                System.out.print(t[i] + " ");
            }
        }
    }
}