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 BT997

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)

Liên kết rút gọn:

https://gokisoft.com/997

Bình luận

avatar
Hoàng Thiện Thanh [community,AAHN-C2009G]
2021-09-21 15:22:05


#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();
}


avatar
Nguyễn Việt Hoàng [community,AAHN-C2009G]
2021-09-21 13:52:46


#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();

}


avatar
Hoàng Thiện Thanh [community,AAHN-C2009G]
2021-09-21 11:44:29

#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();
}


avatar
Nam20021608 [community]
2021-09-21 10:46:58

Nguyễn Văn Nam C2009G

avatar
Võ Như Việt [C2010L]
2021-07-16 08:36:48


#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();
    
}


avatar
Đào Mạnh Dũng [C2010L]
2021-07-15 14:02:50


#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 aptech;

import java.util.Scanner;

/**
 *
 * @author 84834
 */
public class bai1 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        System.out.println(n*(n+1)/2);
    }
}


#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 aptech;

import java.util.Scanner;

/**
 *
 * @author 84834
 */
public class bai2 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        
            for (int i = 2; i < n; i++) {
                if (i%2==0) {
                    System.out.println(i);
                }
            }
    }
}


#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 aptech;

import java.util.Scanner;

/**
 *
 * @author 84834
 */
public class BikeCycle extends Vehicle{
    
    String name;
    int wheel_number; 
    
    @Override
    void running() {
        System.out.println("BikeCycle is running");    
    }

    @Override
    void input() {
        Scanner scan = new Scanner(System.in);
            
        name = scan.nextLine();
        wheel_number = Integer.parseInt(scan.nextLine());
        
        
    }

    @Override
    void display() {
        
        System.out.println(name);
        System.out.println(wheel_number);
    
    }
    
}


#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 aptech;

import java.util.Scanner;

/**
 *
 * @author 84834
 */
public class Book {
 
       
    String title,author,producer,year_production;

    public Book() {
    }

    public Book(String title, String author, String producer, String year_production) {
        this.title = title;
        this.author = author;
        this.producer = producer;
        this.year_production = year_production;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getAuthor() {
        return author;
    }

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

    public String getProducer() {
        return producer;
    }

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

    public String getYear_production() {
        return year_production;
    }

    public void setYear_production(String year_production) {
        this.year_production = year_production;
    }
 
    public void input(){
        
        Scanner scan = new Scanner(System.in);
        
        title = scan.nextLine();
        author = scan.nextLine();
        producer =scan.nextLine();
        year_production =scan.nextLine();
                        
   }
    
    public void output(){
        
        System.out.println(title);
        System.out.println(author);
        System.out.println(producer);
        System.out.println(year_production);
        
    }
}


#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 aptech;

import java.util.Scanner;

/**
 *
 * @author 84834
 */
public class Car extends Vehicle{
    
    String name;
    int wheel_number; 
    
    @Override
    void running() {
        System.out.println("Car is running");    
    }

    @Override
    void input() {
        Scanner scan = new Scanner(System.in);
            
        name = scan.nextLine();
        wheel_number = Integer.parseInt(scan.nextLine());
        
        
    }

    @Override
    void display() {
        
        System.out.println(name);
        System.out.println(wheel_number);
    
    }
    
}


#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 aptech;

import java.util.Scanner;

/**
 *
 * @author 84834
 */
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);

           name = scan.nextLine();
           address = scan.nextLine();

    }

       public void output(){

           System.out.println(name);
           System.out.println(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 aptech;

import java.util.Scanner;

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

    public Student() {
        
    }

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

    public String getRollNo() {
        return rollNo;
    }

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

    @Override
    public void output() {
        super.output();
        System.out.println(rollNo);
 
    }

    @Override
    public void input() {
        super.input(); 
        Scanner scan = new Scanner(System.in);

           rollNo = scan.nextLine();
 
    }
    
    
}


#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 aptech;

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

    abstract void running();

    abstract void input();

    abstract void display();
     
}


avatar
Nguyễn Anh Vũ [T2008A]
2021-02-24 07:22: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 bai3.java;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Book {
    String bookName , author , nhaXB,namXB;

    public Book() {
    }

    public Book(String bookName, String author, String nhaXB, String namXB) {
        this.bookName = bookName;
        this.author = author;
        this.nhaXB = nhaXB;
        this.namXB = namXB;
    }

    public String getBookName() {
        return bookName;
    }

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

    public String getAuthor() {
        return author;
    }

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

    public String getNhaXB() {
        return nhaXB;
    }

    public void setNhaXB(String nhaXB) {
        this.nhaXB = nhaXB;
    }

    public String getNamXB() {
        return namXB;
    }

    public void setNamXB(String namXB) {
        this.namXB = namXB;
    }
    public void input(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Book name : ");
        bookName = scan.nextLine();
        System.out.println("Author name : ");
        author = scan.nextLine();
        System.out.println("Nha san xuat : ");
        nhaXB = scan.nextLine();
        System.out.println("nam san xuat : ");
        namXB =  scan.nextLine();
    }
    public void display(){
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "Book{" + "bookName=" + bookName + ", author=" + author + ", nhaXB=" + nhaXB + ", namXB=" + namXB + '}';
    }
}


avatar
Nguyễn Anh Vũ [T2008A]
2021-02-24 07:20:07



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

/**
 *
 * @author Admin
 */
public class Bai3,Java {
    public static void main(String[] args) {
        Book bk = new Book();
        Book bok;
        bok = new Book(bk.bookName, bk.author, bk.nhaXB, bk.namXB);
        bk.input();
        bk.display();
        bok.display();
    }
}


avatar
Do Trung Duc [T2008A]
2021-02-24 04:03:15



/*
 * 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 Bai4People {

    private String Name;
    private String Address;

    public Bai4People() {
    }

    ;

    public Bai4People(String Name, String Address) {
        this.Name = Name;
        this.Address = Address;
    }

    public String getName() {
        return Name;
    }

    public String getAddress() {
        return Address;
    }

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

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

    public void Input() {
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap Ho va ten: ");
        Name = scan.nextLine();

        System.out.println("Nhap Dia chi: ");
        Address = scan.nextLine();
    }

    public void Display() {
        System.out.println("");
        System.out.format("HovaTen: %s, Diachi: %s", Name, Address);
    }
}


avatar
Do Trung Duc [T2008A]
2021-02-24 04:03:04



/*
 * 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 Bai4Student extends Bai4People {

    private String Roolno;

    public Bai4Student() {
    }

    ;


    public Bai4Student(String Roolno, String Name, String Address) {
        super(Name, Address);
        this.Roolno = Roolno;
    }

    @Override
    public void Input() {
        super.Input();
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap ma sinh vien: ");
        Roolno = scan.nextLine();
    }

    @Override
    public void Display() {
        super.Display();
        System.out.format(" MaSV: %s", Roolno);
    }
}