IMG-LOGO
×

Tài Liệu Học

Khoá học lập trình Java Core căn bản (OOP)

Hướng Dẫn Cài Đặt Môi Trường

[Video] - Hướng dẫn cài đặt môi trường [Video] - Hướng dẫn tạo dự án Hello World [Video] Hướng dẫn phát hành dự án java - Lập trình Java căn bản

Khai Báo Biến & Mệnh Đề Điều Kiện & Vòng Lặp

[Video] - Khai báo biến & Toán tử trong Java [Video] - Tìm hiểu về Scanner, mệnh đề điều kiền if, else, switch trong java [Video] Tìm hiểu Loop (for, while, do while) - Lập trình Java căn bản

Array

[Video] Tìm hiểu về mảng (array) và List, ArrayList trong Java - Lập trình Java căn bản [Video] Hướng dẫn Collections Java | List & ArrayList Java | Vector Java | Map & Hashmap Java | String Java [Video] Test - Tìm kiếm chuỗi trong chuỗi

OOP - Tích Chất Đóng Gói & Kế Thừa

[Video] Tìm hiểu về Class và Object trong lập trình Java - Lập trình Java căn bản [Video] OOP - Tích chất bao đóng - Kế thừa trong Java - Lập trình Java căn bản [Video] Kế thừa OOP - Lập trình java - Lập trình Java căn bản [Video] OOP - Tính Chất Đa Hình - Tính Chất Trừu Tượng - Lập Trình Java Căn Bản [Video] Chu vi + Diện tích hình tròn và hình chữ nhật - lập trình Java căn bản [Video] Chữa bài tập kế thừa hình tròn + hình chữ nhật - lập trình Java căn bản - Đề 2 [Video] Quản Lí Cán Bộ [Video] Chũa bài tập Employee & StudentMark & Product trong lập trình OOP- lập trình Java căn bản [Video] Quản lý bể bơi bằng Java - Swimming Pool in Java [Video] Quản lý phòng tập GYM - Java basic [Video] Hướng dẫn chữa bài tập quản lý sách - lập trình java [Video] Chữa bài tập quản lý sinh viên - lập trình hướng đối tượng java [Video] Java Basic- OOP - Tổng hợp - Quản lý sinh viên - giáo viên bằng java - Phần 2

OOP - Interface

[Video] Interface - OOP lập trình java - Lập trình Java căn bản [Video] Java Basic- OOP - Tổng hợp - Quản lý sở thú [Video] Java Basic- OOP - Interface - Quản lý mèo (cat) trong java [Video] TEST- Chương trình quản lý rạp chiếu film bằng java [Video] Java basic- Overview - viết chương trình điều khiển TIVI bằng java [Video] Java basic- Overview - Viết chương trình quản lý xe car bằng java [Video] Hướng dẫn cú pháp Lambda Java | Tạo anonymous class Java | Interface Java & Abstract Java [Video] Chuyển DateTime sang String Java|Chuyển String sang DateTime Java | Base64 Java|MD5 Java|Cipher Java [Video] Hướng dẫn tìm hiểu Singleton Design Pattern Java | Singleton Object Java | OOP Java cho người mới

Examination & Test

[Video] Java Basic- Overview - Tổng hợp bài tập ôn luyện java basic - Kiểm tra 60 phút [Video] Exam - Kiểm tra 60 phút lập trình OOP - Quản lý thiết bị máy tính - Lập trình OOP

Java Swing

[Video] Hướng dẫn học Java Swing | Ví du quản lý sinh viên Java | Java Swing cho người mới bắt đầu

Ôn Tập Tổng Quát Java Basic

[Video] Phần mềm quản lý trường học - giảng dạy [Video] Optimize (Tối ưu code) - Phần mềm quản lý trường học - giảng dạy [Video] Java Basic- Test 60 phút lập trình java căn bản - Phần mềm quản lý bệnh nhân COVID-19 (2020 - TOOANG) [Video] bài tập quản lý xe cộ + quản lý bãi đỗ xe - lập trình java [Video] Java Basic - Quản lý ATM - Quản lý tài khoản ngân hàng




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

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

by GokiSoft.com - 15:57 21/09/2021 43,034 Lượt Xem

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)


Bình luận



Chia sẻ từ lớp học

Hoàng Thiện Thanh [community,AAHN-C2009G]

Ngày viết: 22:22 21/09/2021


#Bai1.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 test60;

import java.util.Scanner;

/**
 *
 * @author anhoa
 */
public class Bai1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int sum = 0;
        
        for (int i = 0; i <= n; i++){
            sum += i;
        }
        
        System.out.println(sum);
    }
}


#Bai2.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 test60;

import java.util.Scanner;

/**
 *
 * @author anhoa
 */
public class Bai2 {
    public static void main(String[] args) {
        Scanner sc;
        int i;
        //Bai1
        
        //Bai2
        
        int[] n2 = new int[5];
        for(i = 0; i < n2.length - 1; i++){
            sc = new Scanner(System.in);
            n2[i] = sc.nextInt();
            if (n2[i] % 2 == 0){
                System.out.println(n2[i] + "can be divided by 2, result to 0");
            } else {
                System.out.println(n2[i] + "if divide by 2 will not result to 0");
            }
        }
        
        
    }
}


#Bai3.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 test60;

/**
 *
 * @author anhoa
 */
public class Bai3 {
    public static void main(String[] args) {
        Book b = new Book();
        
        b.input();
        b.show();
    }
}


#Bai4.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 test60;

/**
 *
 * @author anhoa
 */
public class Bai4 {
    public static void main(String[] args) {
        People std = new People();
        
        std.input();
        std.show();
        
        
    }
}


#Bai5.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 test60;

/**
 *
 * @author anhoa
 */
public class Bai5 {
    public static void main(String[] args) {
        Car c = new Car();
        
        c.input();
        c.display();
        
        Vehicle bk = new BikeCycle();
        
        bk.input();
        bk.display();
    }
}


#BikeCycle.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 test60;

import java.util.Scanner;

/**
 *
 * @author anhoa
 */
public class BikeCycle extends Vehicle{
    
    private String name;
    private int wheels;
    
    public BikeCycle(){
        
    }
    
    public BikeCycle(String name, int wheels){
        this.name = name;
        this.wheels = wheels;
    }
    
    public String getName(){
        return this.name;
    }
    
    public int getWheels(){
        return this.wheels;
    }
    
    public void setName(String name){
        this.name = name;
    }
    
    public void setWheels(int wheels){
        this.wheels = wheels;
    }

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

    @Override
    public void input() {
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        sc = new Scanner(System.in);
        int wheels = sc.nextInt();
        
        setName(name);
        setWheels(wheels);
    }

    @Override
    public void display() {
        System.out.println("Name: " + this.name);
        System.out.println("Wheels: " + this.wheels);
    }
    
}


#Book.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 test60;

import java.util.Scanner;

/**
 *
 * @author anhoa
 */
public class Book {
    private String author;
    private String name;
    private String producer;
    private int mfgYear;
    
    public Book(){
        
    }
    
    public Book(String name, String author, String producer, int mfgYear){
        this.name = name;
        this.author = author;
        this.producer = producer;
        this.mfgYear = mfgYear;
    }
    
    public String getName(){
        return this.name;
    }
    
    public String getAuthor(){
        return this.name;
    }
    
    public String getProducer(){
        return this.name;
    }
    
    public int getReleaseYear(){
        return this.mfgYear;
    }
    
    public void setName(String name){
        this.name = name;
    }
    
    public void setAuthor(String author){
        this.author = author;
    }
     
    public void setProducer(String producer){
        this.producer = producer;
    }
     
    public void setReleaseYear(int year){
        this.mfgYear = year;
    }
    
    public void input(){
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        sc = new Scanner(System.in);
        String author = sc.nextLine();
        sc = new Scanner(System.in);
        String producer = sc.nextLine();
        sc = new Scanner(System.in);
        int year = sc.nextInt();
        
        setName(name);
        setAuthor(author);
        setProducer(producer);
        setReleaseYear(year);
    }
    
    public void show(){
        System.out.println("Name: " + this.name);
        System.out.println("Author: " + this.author);
        System.out.println("Producer: " + this.producer);
        System.out.println("Release Year: " + this.mfgYear);
    }
}


#Car.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 test60;

import java.util.Scanner;

/**
 *
 * @author anhoa
 */
public class Car extends Vehicle{
    
    private String name;
    private int wheels;
    
    public Car(){
        
    }
    
    public Car(String name, int wheels){
        this.name = name;
        this.wheels = wheels;
    }
    
    public String getName(){
        return this.name;
    }
    
    public int getWheels(){
        return this.wheels;
    }
    
    public void setName(String name){
        this.name = name;
    }
    
    public void setWheels(int wheels){
        this.wheels = wheels;
    }

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

    @Override
    public void input() {
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        sc = new Scanner(System.in);
        int wheels = sc.nextInt();
        
        setName(name);
        setWheels(wheels);
    }

    @Override
    public void display() {
        System.out.println("Name: " + this.name);
        System.out.println("Wheels: " + this.wheels);
    }
    
    
}


#People.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 test60;

import java.util.Scanner;

/**
 *
 * @author anhoa
 */
public class People {
    private String name;
    private String address;
    
    public People(){
        
    }
    
    public People(String name, String address){
        this.name = name;
        this.address = address;
    }
    
    public String getName(){
        return this.name;
    }
    
    public String getAddress(){
        return this.address;
    }
    
    public void setName(String name){
        this.name = name;
    }
    
    public void setAddress(String address){
        this.address = address;
    }
    
    public void input(){
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        sc = new Scanner(System.in);
        String address = sc.nextLine();
        
        setName(name);
        setAddress(address);
    }
    
    public void show(){
        System.out.println("Name: " + this.name);
        System.out.println("Address: " + this.address);
    }
   
}


#Student.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 test60;

import java.util.Scanner;

/**
 *
 * @author anhoa
 */
public class Student extends People{
    public String rollNo;
    
    public Student(){
        
    }
    
    public Student(String name, String address, String rollNo){
        super(name, address);
        this.rollNo = rollNo;
    }
    
    public void setRollNo(String rollNo){
        this.rollNo = rollNo;
    }
    
    @Override
    public void input(){
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        sc = new Scanner(System.in);
        String address = sc.nextLine();
        sc = new Scanner(System.in);
        String rollNo = sc.nextLine();
         
        setName(name);
        setAddress(address);
        setRollNo(rollNo);
    }
    
    @Override
    public void show(){
        System.out.println("Name: " + this.getName());
        System.out.println("Address: " + this.getAddress());
        System.out.println("Roll Number: " + this.rollNo);
    }
    
}


#Vehicle.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 test60;

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


Nguyễn Việt Hoàng [community,AAHN-C2009G]

Ngày viết: 20:52 21/09/2021


#BikeCyrcle.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 B2;

import java.util.Scanner;

/**
 *
 * @author DELL
 */
public class BikeCyrcle extends Vehical {

    private String name;
    private int numWheel;

    public BikeCyrcle() {

    }

    public String getName() {
        return this.name;
    }

    public int getnumWheel() {
        return this.numWheel;
    }

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

    public void setnumWheel(int numWheel) {
        this.numWheel = numWheel;
    }

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

    @Override
    public void input() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter name :");
        String name = sc.nextLine();
        System.out.println("Enter numWheel :");
        int numWheel = sc.nextInt();
        setName(name);
        setnumWheel(numWheel);

    }

    @Override
    public void display() {
        System.out.println("Name :" + this.getName() + ", numWheel :" + this.getnumWheel());
    }

}


#Book.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 B2;

import java.util.Scanner;

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

    private String name;
    private String author;
    private String producer;
    private int year;

    public Book() {

    }

    public Book(String name, String author, String producer, int year) {
        this.name = name;
        this.author = author;
        this.producer = producer;
        this.year = year;
    }

    public String getName() {
        return this.name;
    }

    public String getAuthor() {
        return this.author;
    }

    public String getProducer() {
        return this.producer;
    }

    public int getYear() {
        return this.year;
    }

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

    public void setAuthor(String author) {
        this.author = author;
    }

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

    public void setYear(int year) {
        this.year = year;
    }

    public void input() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter name :");
        String name = sc.nextLine();
        System.out.println("Enter author :");
        String author = sc.nextLine();
        System.out.println("Enter producer :");
        String producer = sc.nextLine();
        System.out.println("Enter year :");
        int year = sc.nextInt();
        setName(name);
        setAuthor(author);
        setProducer(producer);
        setYear(year);
    }

    @Override
    public String toString() {
        return "Name :" + this.getName() + ", Author :" + this.getAuthor()
                + ", Producer :" + this.getProducer()
                + ", Year :" + this.getYear();
    }

}


#Car.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 B2;

import java.util.Scanner;

/**
 *
 * @author DELL
 */
public class Car extends Vehical {

    private String name;
    private int numWheel;
    public Car(){
        
    }
    public String getName(){
        return this.name;
    }
    public int getnumWheel(){
        return this.numWheel;
    }
    public void setName(String name){
        this.name = name;
    }
    public void setnumWheel(int numWheel){
        this.numWheel = numWheel;
    }
    

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

    @Override
    public void input() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter name :");
        String name = sc.nextLine();
        System.out.println("Enter numWheel :");
        int numWheel = sc.nextInt();
        setName(name);
        setnumWheel(numWheel);
        
    }

    @Override
    public void display() {
        System.out.println("Name :" + this.getName() + ", numWheel :" + this.getnumWheel());
    }
}


#findSum.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 B2;

import java.util.Scanner;

/**
 *
 * @author DELL
 */
public class findSum {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

////        B1
//        System.out.println("PLease enter your number :");
//        int number = sc.nextInt();
//        while(number < 0){
//            System.out.println("Number must be >= 0 ");
//            System.out.println("PLease enter your number :");
//            number = sc.nextInt();
//        }
//        int sum = 0;
//        for (int i = 0; i <= number; i++) {
//            sum += i;
//        }
//        System.out.println("Sum :" + sum);



        //B2
//        int count = 0, i = 0;
//        System.out.println("Enter Sum number :");
//        int num = sc.nextInt();
//        while (num <= 0) {
//            System.out.println("Sum number must be > 0 ");
//            System.out.println("Enter Sum number :");
//            num = sc.nextInt();
//        }
//        int[] sumNum = new int[num];
//        do {
//            count = i + 1;
//            System.out.println("Enter number " + count + " :");
//            sumNum[i] = sc.nextInt();
//            i++;
//        } while (i < num);
//        for (int j = 0; j < sumNum.length; j++) {
//            if (sumNum[j] % 2 == 0) {
//                System.out.println("Result numbers  % 2 :" + sumNum[j]);
//            }
//        }

    }
}


#People.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 B2;

import java.util.Scanner;

/**
 *
 * @author DELL
 */
public class People {

    private String name;
    private String address;

    public People() {

    }

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

    public String getName() {
        return this.name;
    }

    public String getAddress() {
        return this.address;
    }

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

    public void setAddress(String address) {
        this.address = address;
    }
    public void input(){
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter name :");
        String name = sc.nextLine();
        System.out.println("Enter address :");
        String address = sc.nextLine();
        setName(name);
        setAddress(address);
    }

    @Override
    public String toString() {
        return "Name :" + this.getName() + ", Address :" + this.getAddress();
    }
}


#Student.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 B2;

import java.util.Scanner;

/**
 *
 * @author DELL
 */
public class Student extends People {

    private int rollNo;

    public Student() {

    }

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

    public int getrollNo() {
        return this.rollNo;
    }

    public void setrollNo(int rollNo) {
        this.rollNo = rollNo;
    }

    @Override
    public void input() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter name :");
        String name = sc.nextLine();
        System.out.println("Enter address :");
        String address = sc.nextLine();
        System.out.println("Enter rollNo :");
        int rollNo = sc.nextInt();
        setName(name);
        setAddress(address);
        setrollNo(rollNo);
    }
}


#test.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 B2;

/**
 *
 * @author DELL
 */
public class test {

    public static void main(String[] args) {
        Book b1 = new Book();
        b1.input();
        System.out.println(b1);

        People p1 = new People();
        p1.input();
        System.out.println(p1);
    }
}


#Vehical.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 B2;

/**
 *
 * @author DELL
 */
public abstract class Vehical {

    public Vehical() {

    }

    public abstract void running();

    public abstract void input();

    public abstract void display();

}


Hoàng Thiện Thanh [community,AAHN-C2009G]

Ngày viết: 18:44 21/09/2021

#Bai2.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 test60;

import java.util.Scanner;

/**
 *
 * @author anhoa
 */
public class Bai2 {
    public static void main(String[] args) {
        Scanner sc;
        int i;
        //Bai1
        
        //Bai2
        
        int[] n2 = new int[5];
        for(i = 0; i < n2.length - 1; i++){
            sc = new Scanner(System.in);
            n2[i] = sc.nextInt();
            if (n2[i] % 2 == 0){
                System.out.println(n2[i] + "can be divided by 2, result to 0");
            } else {
                System.out.println(n2[i] + "if divide by 2 will not result to 0");
            }
        }
        
        
    }
}


#Bai3.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 test60;

/**
 *
 * @author anhoa
 */
public class Bai3 {
    public static void main(String[] args) {
        Book b = new Book();
        
        b.input();
        b.show();
    }
}


#Bai4.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 test60;

/**
 *
 * @author anhoa
 */
public class Bai4 {
    
}


#Bai5.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 test60;

/**
 *
 * @author anhoa
 */
public class Bai5 {
    public static void main(String[] args) {
        
    }
}


#BikeCycle.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 test60;

import java.util.Scanner;

/**
 *
 * @author anhoa
 */
public class BikeCycle extends Vehicle{
    
    private String name;
    private int wheels;
    
    public BikeCycle(){
        
    }
    
    public BikeCycle(String name, int wheels){
        this.name = name;
        this.wheels = wheels;
    }
    
    public String getName(){
        return this.name;
    }
    
    public int getWheels(){
        return this.wheels;
    }
    
    public void setName(String name){
        this.name = name;
    }
    
    public void setWheels(int wheels){
        this.wheels = wheels;
    }

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

    @Override
    public void input() {
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        sc = new Scanner(System.in);
        int wheels = sc.nextInt();
        
        setName(name);
        setWheels(wheels);
    }

    @Override
    public void display() {
        System.out.println("Name: " + this.name);
        System.out.println("Wheels: " + this.wheels);
    }
    
}


#Book.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 test60;

import java.util.Scanner;

/**
 *
 * @author anhoa
 */
public class Book {
    private String author;
    private String name;
    private String producer;
    private int mfgYear;
    
    public Book(){
        
    }
    
    public Book(String name, String author, String producer, int mfgYear){
        this.name = name;
        this.author = author;
        this.producer = producer;
        this.mfgYear = mfgYear;
    }
    
    public String getName(){
        return this.name;
    }
    
    public String getAuthor(){
        return this.name;
    }
    
    public String getProducer(){
        return this.name;
    }
    
    public int getReleaseYear(){
        return this.mfgYear;
    }
    
    public void setName(String name){
        this.name = name;
    }
    
    public void setAuthor(String author){
        this.author = author;
    }
     
    public void setProducer(String producer){
        this.producer = producer;
    }
     
    public void setReleaseYear(int year){
        this.mfgYear = year;
    }
    
    public void input(){
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        sc = new Scanner(System.in);
        String author = sc.nextLine();
        sc = new Scanner(System.in);
        String producer = sc.nextLine();
        sc = new Scanner(System.in);
        int year = sc.nextInt();
        
        setName(name);
        setAuthor(author);
        setProducer(producer);
        setReleaseYear(year);
    }
    
    public void show(){
        System.out.println("Name: " + this.name);
        System.out.println("Author: " + this.author);
        System.out.println("Producer: " + this.producer);
        System.out.println("Release Year: " + this.mfgYear);
    }
}


#Car.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 test60;

import java.util.Scanner;

/**
 *
 * @author anhoa
 */
public class Car extends Vehicle{
    
    private String name;
    private int wheels;
    
    public Car(){
        
    }
    
    public Car(String name, int wheels){
        this.name = name;
        this.wheels = wheels;
    }
    
    public String getName(){
        return this.name;
    }
    
    public int getWheels(){
        return this.wheels;
    }
    
    public void setName(String name){
        this.name = name;
    }
    
    public void setWheels(int wheels){
        this.wheels = wheels;
    }

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

    @Override
    public void input() {
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        sc = new Scanner(System.in);
        int wheels = sc.nextInt();
        
        setName(name);
        setWheels(wheels);
    }

    @Override
    public void display() {
        System.out.println("Name: " + this.name);
        System.out.println("Wheels: " + this.wheels);
    }
    
    
}


#People.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 test60;

import java.util.Scanner;

/**
 *
 * @author anhoa
 */
public class People {
    private String name;
    private String address;
    
    public People(){
        
    }
    
    public People(String name, String address){
        this.name = name;
        this.address = address;
    }
    
    public String getName(){
        return this.name;
    }
    
    public String getAddress(){
        return this.address;
    }
    
    public void setName(String name){
        this.name = name;
    }
    
    public void setAddress(String address){
        this.address = address;
    }
    
    public void input(){
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        sc = new Scanner(System.in);
        String address = sc.nextLine();
        
        setName(name);
        setAddress(address);
    }
    
    public void show(){
        System.out.println("Name: " + this.name);
        System.out.println("Address: " + this.address);
    }
   
}


#Student.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 test60;

import java.util.Scanner;

/**
 *
 * @author anhoa
 */
public class Student extends People{
    public String rollNo;
    
    public Student(){
        
    }
    
    public Student(String name, String address, String rollNo){
        super(name, address);
        this.rollNo = rollNo;
    }
    
    public void setRollNo(String rollNo){
        this.rollNo = rollNo;
    }
    
    @Override
    public void input(){
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        sc = new Scanner(System.in);
        String address = sc.nextLine();
        sc = new Scanner(System.in);
        String rollNo = sc.nextLine();
         
        setName(name);
        setAddress(address);
        setRollNo(rollNo);
    }
    
    @Override
    public void show(){
        System.out.println("Name: " + this.getName());
        System.out.println("Address: " + this.getAddress());
        System.out.println("Roll Number: " + this.rollNo);
    }
    
}


#Vehicle.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 test60;

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


Nam20021608 [community]

Ngày viết: 17:46 21/09/2021

Võ Như Việt [C2010L]

Ngày viết: 15:36 16/07/2021


#Bai1.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 BT997Overview60phut;

import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public class Bai1 {

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
       Scanner scan = new Scanner(System.in);
        System.out.println("Nhap so N: ");
       int n = scan.nextInt();
       int sum = 0;
       for(int i = 0; i <= n;i++){
           sum+= i;
       }
        System.out.println("Tong so tu 0 -> N = " + sum);
    }
}


#Bai2.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 BT997Overview60phut;

import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public class Bai2 {

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap so phan tu cua mang:");
        int n = scan.nextInt();
        int[] arr = new int[n];
        
        for (int i = 0; i < n; i++) {
            System.out.println("Nhap so:" + (i+1));
            arr[i] = scan.nextInt();
        }
        System.out.println("Nhung so chia het cho 2 o trong mang la:");
        for (int i = 0; i < n; i++) {
            if(arr[i] % 2 == 0){
                System.out.print(arr[i] + " ");
            }
        }
    }
}


#Bai3Book.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 BT997Overview60phut;

import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public class Bai3Book {
    String nameBook,nameAuthor,producer;
    int year;

    public Bai3Book() {
    }

    public Bai3Book(String nameBook, String nameAuthor, String producer, int year) {
        this.nameBook = nameBook;
        this.nameAuthor = nameAuthor;
        this.producer = producer;
        this.year = year;
    }

    public String getNameBook() {
        return nameBook;
    }

    public void setNameBook(String nameBook) {
        this.nameBook = nameBook;
    }

    public String getNameAuthor() {
        return nameAuthor;
    }

    public void setNameAuthor(String nameAuthor) {
        this.nameAuthor = nameAuthor;
    }

    public String getProducer() {
        return producer;
    }

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

    public int getYear() {
        return year;
    }

    public boolean setYear(int year) {
        if(year > 0 && year <= 2021){
            this.year = year;
            return true;
        }else{
            System.out.println("Gia tri nam san xuat > 0");
        }
        return false;
    }
   
    public void input(){
        Scanner scan = new Scanner(System.in);
        System.out.println("==============");
        System.out.println("Nhap ten sach:");
        nameBook = scan.nextLine();
        System.out.println("Nhap tac gia:");
        nameAuthor = scan.nextLine();
        System.out.println("Nhap NXB:");
        producer = scan.nextLine();
        System.out.println("Nhap nam XB:");
        while (!setYear(Integer.parseInt(scan.nextLine()))) {            
            System.out.println("Yeu cau nhap lai Year > 0 && Year <=2021");
        }  
    }
    
    public void display(){
        System.out.printf("\nTen Sach: %s,\nTac Gia: %s,\nNXB: %s,\nNamXB: %d\n", nameBook,nameAuthor,producer,year);
    }
}


#Test.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 BT997Overview60phut;

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

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        Bai3Book book = new Bai3Book();
        
        
        System.out.println("=============");
        book.input();
        book.display();
        
        System.out.println("=============");
        Bai3Book book2 = new Bai3Book();
        book2.setNameBook("Sach Toan");
        book2.setNameAuthor("Thay Toan");
        book2.setProducer("BGD");
        book2.setYear(1986);
        book2.display();
    }
}


#People.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 BT997Overview60phut.BT997Bai4;

import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public class People {

    String name,address;

    public People() {
    }

    public People(String name, String address) {
        this.name = name;
        this.address = 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 void input(){
        Scanner scan = new Scanner(System.in);
        System.out.println("----------------");
        System.out.println("Nhap Ho va Ten: ");
        name = scan.nextLine();
        System.out.println("Nhap Dia chi: ");
        address = scan.nextLine();
    }
    
    public void display(){
        System.out.printf("\nTen: %s, \nDia Chi: %s\n", name,address);
    }
}


#Student.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 BT997Overview60phut.BT997Bai4;

import java.util.Scanner;

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

    public Student() {
    }

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

    public int getRollNo() {
        return rollNo;
    }

    public void setRollNo(int rollNo) {
        this.rollNo = rollNo;
    }
    
    @Override
    public void input(){
        super.input();
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap MSV: ");
        rollNo = scan.nextInt();
    }
    
    @Override
    public void display(){
        super.display();
        System.out.printf("MSV: %d", rollNo);
    }
}


#Test.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 BT997Overview60phut.BT997Bai4;

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

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        Student std1 = new Student();
        
        std1.input();
        std1.display();
        
        System.out.println("\n--------------");
        
        Student std2 = new Student(02,"Nguyen Van B","Ha NOi");
        std2.display();
       
    }
}


#BikeCycle.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 BT997Overview60phut.BT997Bai4.BT997Bai5;

import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public class BikeCycle extends Vehicle{
    String name;
    int wheelsBike;

    public BikeCycle() {
    }

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

    public String getName() {
        return name;
    }

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

    public int getWheelsBike() {
        return wheelsBike;
    }

    public boolean setWheelsBike(int wheelsBike) {
        if(wheelsBike > 1  && wheelsBike <=2 ){
        this.wheelsBike = wheelsBike;
        return true;
        }else{
            System.out.println("Nhap sai de so banh xe.....");
        }return false;
    }
    
    
    @Override
    void running() {
        System.out.println("BikeCycle is Running... ");
    }

    @Override
    void input() {
        Scanner scan = new Scanner(System.in);
         System.out.println("Nhap ten xe: ");
         name = scan.nextLine();
         System.out.println("Nhap so banh xe: ");
         while (!setWheelsBike(Integer.parseInt(scan.nextLine()))) {            
             System.out.println("So banh xe = 2 ");
         }
    }

    @Override
     void display(){
        System.out.printf("\nTen xe BikeCycle: %s , So Banh Xe: %d",name,wheelsBike);
    }
    
}


#Car.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 BT997Overview60phut.BT997Bai4.BT997Bai5;

import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public class Car  extends Vehicle{
    String name;
    int wheelsCar;

    public Car() {
    }

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

    public String getName() {
        return name;
    }

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

    public int getWheelsCar() {
        return wheelsCar;
    }

    public boolean setWheelsCar(int wheelsCar) {
        if( wheelsCar <= 4 && wheelsCar > 3 ){
        this.wheelsCar = wheelsCar;
        return true;
        }else{
            System.out.println("Sai so luong banh xe....");
        }return false;
        
    }
    
    
    @Override
     public void input(){   
         Scanner scan = new Scanner(System.in);
         System.out.println("Nhap ten xe OTO: ");
         name = scan.nextLine();
         System.out.println("Nhap so banh xe: ");
         while (!setWheelsCar(Integer.parseInt(scan.nextLine()))) {            
             System.out.println("So banh xe phai = 4 ");
        }
     }
     
    @Override
    public void display(){
        System.out.printf("\nTen xe: %s , So Banh Xe: %d",name,wheelsCar);
    }
    
    @Override
    public void running(){
        System.out.println("Car is Running....");
    }
}


#testVe.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 BT997Overview60phut.BT997Bai4.BT997Bai5;

/**
 *
 * @author ADMIN
 */
public class testVe {

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        Car car = new Car();
        car.input();
        car.display();
        System.out.println("\n---------------\n");
        BikeCycle bike = new BikeCycle();
        bike.input();
        bike.display();
    }
}


#Vehicle.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 BT997Overview60phut.BT997Bai4.BT997Bai5;

/**
 *
 * @author ADMIN
 */
public abstract class Vehicle {

    
    abstract void running();
    abstract void input(); 
    abstract void display();
    
}


Phân Loại Bài Viết

Tài Liệu Tham Khảo

Đã sao chép!!!