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)

Do Trung Duc [T2008A]
Do Trung Duc

2021-02-24 04:02: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 Test60Min;

/**
 *
 * @author TrungDuc
 */
public class Bai4Test {

    public static void main(String[] args) {

        Bai4People people1 = new Bai4People();
        people1.Input();
        people1.Display();

        Bai4Student student1 = new Bai4Student();
        student1.Input();
        student1.Display();

    }
}



Do Trung Duc [T2008A]
Do Trung Duc

2021-02-24 04:02:43



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

/**
 *
 * @author TrungDuc
 */
public class bai3Test {
    public static void main (String[] agrs){
        
        bai3Book book1 = new bai3Book();
        book1.setBookName("Doraemon");
        book1.setBookAuthor("Do Trung Duc");
        book1.setBookProducer("Tien Phong");
        book1.setBookYear("1990");
        
        bai3Book book2 = new bai3Book("Conan","Tran Van Diep", "Nhi Dong","2000");
        
        
        book1.Display();
        book2.Display();
        
        
        
        
    }
}



Do Trung Duc [T2008A]
Do Trung Duc

2021-02-24 04:02:30



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

import java.util.Scanner;

/**
 *
 * @author TrungDuc
 */
public class bai3Book {
    private String BookName;
    private String BookAuthor;
    private String BookProducer;
    private String BookYear;
    
    public bai3Book(){};

    public bai3Book(String BookName, String BookAuthor, String BookProducer, String BookYear) {
        this.BookName = BookName;
        this.BookAuthor = BookAuthor;
        this.BookProducer = BookProducer;
        this.BookYear = BookYear;
    }
    
    

    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 getBookProducer() {
        return BookProducer;
    }

    public void setBookProducer(String BookProducer) {
        this.BookProducer = BookProducer;
    }

    public String getBookYear() {
        return BookYear;
    }

    public void setBookYear(String BookYear) {
        this.BookYear = BookYear;
    }
    
    public void Input(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap ten sach");
        BookName = scan.nextLine();
        
        System.out.println("Nhap tac gia sach");
        BookAuthor = scan.nextLine();
        
        System.out.println("Nhap nha xuat ban sach");
        BookProducer = scan.nextLine();
        
        System.out.println("Nhap nam xuat ban sach");
        BookYear = scan.nextLine();
    }
    
    public void Display(){
        System.out.println(this);
    }
    
    @Override
    public String toString(){
        return ("{" + "TenSach: "+ BookName + "TenTacGia: "+ BookAuthor +  "NhaXuatBan: "+ BookProducer +  "NamXuatBanSach: "+ BookYear);
}
}



Do Trung Duc [T2008A]
Do Trung Duc

2021-02-24 04:02:18



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 Test60Min;

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

/**
 *
 * @author TrungDuc
 */
public class Inracacsochiahetcho2 {
    public static void main(String[] agrs){
        int N;
        ArrayList<Integer> listNumber = new ArrayList<>();
        Scanner inputNumber = new Scanner(System.in);
        
        System.out.print("Nhap so phan tu so nguyen N = ");
        N = inputNumber.nextInt();
        
        for (int i = 0; i < N ; i++){
            System.out.format("Nhap phan tu thu %d: ", i+1);
            int number = inputNumber.nextInt();
            listNumber.add(number);
        }
        
        System.out.println("cac so chia het cho la:");
        
         for (int i = 0; i < N ; i++){
            if(listNumber.get(i) %2 ==0){
                System.out.println(listNumber.get(i));
            }
        }
        
        
        
    }
}



Do Trung Duc [T2008A]
Do Trung Duc

2021-02-24 04:02:02



Bai1
/*
 * 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 Test60Min;

import java.util.Scanner;

/**
 *
 * @author TrungDuc
 */
public class TinhTong {
    public static void main(String[] agrs){
        
        int Tong = 0, N;
        
       Scanner inputNumber = new Scanner(System.in);
       System.out.println("Nhap so N = ");
       N = inputNumber.nextInt();
       
       for(int i = 0; i <= N; i++){
           Tong = Tong + i;
       }
        System.out.println("Tong cac so nguyen tu 0 den N = " + Tong);
       
    }
}



Trần Văn Lâm [T2008A]
Trần Văn Lâm

2021-02-23 13:37:43



public class Bai8 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        int i,n,sum;
        sum = 0;
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap so n =");
        n = scan.nextInt();
        for(i = 0;i <= n;i++){
            sum += i;
        }
        System.out.println("Tong =" +sum);
    }
    
}



vuong huu phu [T2008A]
vuong huu phu

2021-02-22 11:42:42


bai 4 ---------- 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_b4 {
    public static void main(String[] args) {
        Student student = new Student();
        student.Nhap();
        student.Hien_thi();
    }
}



vuong huu phu [T2008A]
vuong huu phu

2021-02-22 11:42:09


bai4-------Student


/*
 * 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 Student extends People {

    int RollNo;
    Scanner sc = new Scanner(System.in);

    public Student() {
    }

    public Student(int RollNo) {
        this.RollNo = RollNo;
    }

    public Student(int RollNo, String Ten, String Dia_chi) {
        super(Ten, Dia_chi);
        this.RollNo = RollNo;
    }

    public int getRollNo() {
        return RollNo;
    }

    public void setRollNo(int RollNo) {
        this.RollNo = RollNo;
    }

    @Override
    public void Nhap() {
        super.Nhap();
        System.out.println("Nhap RollNo: ");
        RollNo = sc.nextInt();
    }

    @Override
    public String toString() {
        return super.toString() + " Rollno = "+RollNo;
    }
    

}



vuong huu phu [T2008A]
vuong huu phu

2021-02-22 11:41:12


bai 4-----------People
/*
 * 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 People {
    String Ten,Dia_chi;

    public People() {
    }

    public People(String Ten, String Dia_chi) {
        this.Ten = Ten;
        this.Dia_chi = Dia_chi;
    }

    public String getTen() {
        return Ten;
    }

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

    public String getDia_chi() {
        return Dia_chi;
    }

    public void setDia_chi(String Dia_chi) {
        this.Dia_chi = Dia_chi;
    }
    Scanner scan = new Scanner(System.in);
    public void Nhap(){
    System.out.println("Nhap ten: ");
    Ten = scan.nextLine();
    System.out.println("Nhap dia chi: ");
    Dia_chi = scan.nextLine();
    }

    @Override
    public String toString() {
        return "Ten = " + Ten + ", Dia chi = " + Dia_chi;
    }
    public void Hien_thi(){
    System.out.println(this);
    }
    
}



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

2021-02-22 10:03:56



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

import java.util.Scanner;

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

    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");
            }
        }
    }
}