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

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

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

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

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

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

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

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

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

Bài 4 :

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

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

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

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

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

Bài 5:

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

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

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

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

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

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

5

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

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

2020-04-01 12:39:41



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lession8.bai2;

import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public class Bai2 {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        
        System.out.print("Nhâp số phần tử của mảng: ");
        int n = Integer.parseInt(scanner.nextLine());
        int[] intArr = new int[n];
        
        for(int i = 0; i < n; i++){
            System.out.print("Nhập phần tử [" + i + "]: ");
            intArr[i] = Integer.parseInt(scanner.nextLine());
        }
        
        System.out.println("Các phần tử chia hết cho 2 là: ");
        for(int i = 0; i < n; i++){
            if(intArr[i] % 2 == 0){
                System.out.println(intArr[i]);
            }
        }
    }
}



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

2020-04-01 12:31:06



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lession8.bai1;

import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public class Bai1 {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int sum = 0;
        
        System.out.print("Nhập N = ");
        int N = Integer.parseInt(scanner.nextLine());
        
        for(int i = 0; i <= N; i++){
            sum += i;
        }
        
        System.out.format("Tổng các số nguyên từ 0 đến %d là : %d", N, sum);
    }
}



Trần Mạnh Dũng [T1907A]
Trần Mạnh Dũng

2020-03-16 13:09:35


package Bai1;

import java.util.Scanner;
public class Bai1 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int tong = 0;
        System.out.print("Nhap vao n:");
        int n = Integer.parseInt(scan.nextLine());
        for (int i = 1; i <= n; i++){
            tong += i;
        }
        System.out.println("Tong cac so tu 0 den " + n + " = " + tong);   
    } 
}


package Bai2;

import java.util.Scanner;
public class Bai2 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print("Nhap vao n:");
        int n = Integer.parseInt(scan.nextLine());
        int[] t = new int[n];
        for (int i = 0; i < n; i++){
            System.out.print("Nhap vao so thu " + (i+1) + ":" );
            t[i] = Integer.parseInt(scan.nextLine());
        }
        System.out.print("Cac so chia het cho 2 la: " ); 
        for (int i = 0; i < n; i++){
          if (t[i] % 2 == 0)
              System.out.print(t[i] + " ");
        }
    } 
}


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

import java.util.Scanner;

/**
 *
 * @author admin
 */
public class Book {
    String BookName;
    String Author;
    String NhaSanXuat;
    String NamSanXuat;

    public Book() {
    }

    public Book(String BookName, String Author, String NhaSanXuat, String NamSanXuat) {
        this.BookName = BookName;
        this.Author = Author;
        this.NhaSanXuat = NhaSanXuat;
        this.NamSanXuat = NamSanXuat;
    }

    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 getNhaSanXuat() {
        return NhaSanXuat;
    }

    public void setNhaSanXuat(String NhaSanXuat) {
        this.NhaSanXuat = NhaSanXuat;
    }

    public String getNamSanXuat() {
        return NamSanXuat;
    }

    public void setNamSanXuat(String NamSanXuat) {
        this.NamSanXuat = NamSanXuat;
    }
    
    public void input(){
        Scanner input = new Scanner(System.in);
        System.out.println("Nhap ten sach: ");
        BookName = input.nextLine();
        
        System.out.println("Nhap ten tac gia: ");
        Author = input.nextLine();
        
        System.out.println("Nhap nha san xuat: ");
        NhaSanXuat = input.nextLine();
                
        System.out.println("Nhap nam san xuat: ");
        NamSanXuat= input.nextLine();
    }
 
    @Override
    public String toString() {
        return "Book{" + "BookName=" + BookName + ", Author=" + Author + ", NhaSanXuat=" + NhaSanXuat + ", NamSanXuat=" + NamSanXuat + '}';
    }
    
}



package Bai3;

public class Tesst {
    public static void main(String[] args) {
        Book book = new Book();
        book.input();
        System.out.println(book.toString());
    }
}

Bai4



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

import java.util.Scanner;

/**
 *
 * @author admin
 */
public class People {
    String ten;
    String diachi;

    public People() {
    }

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

    public String getTen() {
        return ten;
    }

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

    public String getDiachi() {
        return diachi;
    }

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

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

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



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Bai4;
import java.util.Scanner;

public class Student extends People{
    int rollNo;
    
    
    @Override
    public void input(){
        super.input();
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap so tt: ");
        rollNo = sc.nextInt();
    }
    @Override
    public void output(){
        super.output();
        System.out.println("rollNo"+rollNo);
    }

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

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

    public int getRollNo() {
        return rollNo;
    }

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

    @Override
    public String getTen() {
        return ten;
    }

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

    @Override
    public String getDiachi() {
        return diachi;
    }

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

    public Student() {
    }

}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Bai4;

public class Test {
    public static void main(String[] args) {
        
        People people = new People();
        people.input();
        System.out.println(people.toString());
    }
    
}
Bai5




package Bai5;

/**
 *
 * @author admin
 */
public class BikecCycle extends Vehicle{
    
    public void running(){
        System.out.println("BikeCycle is running");
    }
}



package Bai5;

/**
 *
 * @author admin
 */
public class Car extends Vehicle{

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



package Bai5;

/**
 *
 * @author admin
 */
public abstract class Vehicle {
     String name;
     String SoBanhXe;

    public Vehicle() {
    }

    public Vehicle(String name, String SoBanhXe) {
        this.name = name;
        this.SoBanhXe = SoBanhXe;
    }

    public String getName() {
        return name;
    }

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

    public String getSoBanhXe() {
        return SoBanhXe;
    }

    public void setSoBanhXe(String SoBanhXe) {
        this.SoBanhXe = SoBanhXe;
    }

    
}



package Bai5;

/**
 *
 * @author admin
 */
public class Test {
    public static void main(String[] args) {
        Car car = new Car();
        car.running();
        
        BikecCycle Bc = new BikecCycle();
        Bc.running();
    }
}



Lê Minh Bắc [T1907A]
Lê Minh Bắc

2020-03-16 12:52:33

Bài 1:

package BT997.Bai1;
import java.util.Scanner;
public class B1 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int tong = 0;
        System.out.print("Nhap vao n:");
        int n = Integer.parseInt(scan.nextLine());
        for (int i = 1; i <= n; i++){
            tong += i;
        }
        System.out.println("Tong cac so tu 0 den " + n + " = " + tong);   
    } 
}

Bài 2:
package BT997.Bai2;
import java.util.Scanner;
public class B2 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print("Nhap vao n:");
        int n = Integer.parseInt(scan.nextLine());
        int[] t = new int[n];
        for (int i = 0; i < n; i++){
            System.out.print("Nhap vao so thu " + (i+1) + ":" );
            t[i] = Integer.parseInt(scan.nextLine());
        }
        System.out.print("Cac so chia het cho 2 la: " ); 
        for (int i = 0; i < n; i++){
          if (t[i] % 2 == 0)
              System.out.print(t[i] + " ");
        }
    } 
}

Bài 3:
package BT997.Bai3;

import java.util.Scanner;

public class Book {
    String bookName;
    String authorName;
    String producer;
    int year;

    public Book() {
    }

    public Book(String bookName, String authorName, String producer, int year) {
        this.bookName = bookName;
        this.authorName = authorName;
        this.producer = producer;
        this.year = year;
    }

    public String getBookName() {
        return bookName;
    }

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

    public String getAuthorName() {
        return authorName;
    }

    public void setAuthorName(String authorName) {
        this.authorName = authorName;
    }

    public String getProducer() {
        return producer;
    }

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

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }
    
    public void input(){
        Scanner scan = new Scanner(System.in);
        System.out.print("Nhập tên sách: ");
        bookName = scan.nextLine();
        System.out.print("Nhập tên tác giả: ");
        authorName = scan.nextLine();
        System.out.print("Nhập tên nhà xuất bản: ");
        producer = scan.nextLine();
        System.out.print("Năm sản xuất: ");
        year = Integer.parseInt(scan.nextLine());
        
    }
    
    public void display() {
        System.out.println("Tên sách: " + bookName);
        System.out.println("Tác Giả: " + authorName);
        System.out.println("Nhà xuất bản: " + producer);
        System.out.println("Năm sản xuất: " + year);
    }
}




package BT997.Bai3;
public class Test {
    public static void main(String[] agrs) {
        Book book1 = new Book();
        Book book2 = new Book("Lập trình C", "Lê Minh Bắc", "Kim Đồng",120000);
        
        System.out.println("Nhập thông tin sách:");
        book1.input();
        System.out.println("Thông tin sách 1:");
        book1.display();
        System.out.println("Thông tin sách 2:");
        book2.display();  
    }
}

Bài 4:
package BT997.Bai4;
import java.util.Scanner;
public class People {
    String name, address;
    
    public void input(){
        Scanner scan = new Scanner(System.in);
        System.out.print("Nhập tên : ");
        name = scan.nextLine();
        System.out.print("Nhập địa chỉ: ");
        address = scan.nextLine();
    }
    
    public void display() {
        System.out.println("Tên: " + name);
        System.out.println("Địa chỉ: " + address);
    }
}



package BT997.Bai4;
import java.util.Scanner;
public class Student extends People {
    String rollNo;
    
    @Override
    public void input(){
        Scanner scan = new Scanner(System.in);
        super.input();
        System.out.print("Nhập RollNo: ");
        rollNo = scan.nextLine();
    }
    
    @Override
    public void display() {
        super.display();
        System.out.println("RollNo: " + rollNo);
    }
}



package BT997.Bai4;
public class Test {
    public static void main(String[] agrs) {
        People peo = new People();
        Student std = new Student();
        System.out.println("Nhập thông tin People:");
        peo.input();
        System.out.println("Nhập thông tin Student:");
        std.input();
        System.out.println("Thông tin của People:");
        peo.display();
        System.out.println("Thông tin của Student:");
        std.display();  
    }
}

Bài 5:
package BT997.Bai5;
import java.util.Scanner;
public class BikeCycle extends Vehicle {
    String name;
    int soBanhXe;

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

    @Override
    public void input() {
        Scanner scan = new Scanner(System.in);
        System.out.print("Nhập tên xe: ");
        name = scan.nextLine();
        System.out.print("Nhập số bánh xe: ");
        soBanhXe = Integer.parseInt(scan.nextLine());
    }

    @Override
    public void display() {
        System.out.println("Tên xe: " + name);
        System.out.println("Số bánh xe: " + soBanhXe);
    }
}



package BT997.Bai5;
import java.util.Scanner;
public class Car extends Vehicle {
    String name;
    int soBanhXe;

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

    @Override
    public void input() {
        Scanner scan = new Scanner(System.in);
        System.out.print("Nhập tên xe: ");
        name = scan.nextLine();
        System.out.print("Nhập số bánh xe: ");
        soBanhXe = Integer.parseInt(scan.nextLine());
    }

    @Override
    public void display() {
        System.out.println("Tên xe: " + name);
        System.out.println("Số bánh xe: " + soBanhXe);
    }
}



package BT997.Bai5;
public class Test { 
    public static void main(String[] agrs) {
        Car car = new Car();
        BikeCycle bike = new BikeCycle();
        System.out.println("Nhập thông tin Car:");
        car.input();
        System.out.println("Nhập thông tin BikeCycle:");
        bike.input();
        System.out.println("Thông tin của Car:");
        car.display();
        System.out.println("Thông tin của BikeCycle:");
        bike.display();  
    }
}



package BT997.Bai5;
public abstract class Vehicle {
    public abstract void running();
    public abstract void input();
    public abstract void display();
}



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

2020-03-12 14:56:22

bài 2


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Nhap.mang.so.nguyenN;
import java.util.Scanner;
/**
 *
 * @author Administrator
 */
public class Main {
    public static void main(String[] agrs){
        int n;
        Scanner scanner = new Scanner(System.in);
        
        do{
            System.out.println("Nhập vào số phần tử của mảng:");
            n = scanner.nextInt();
        } while ( n <= 0);
        
        int A[] = new int[n];
        
        System.out.println("Nhập các phần  tủ cho mảng");
        for (int i = 0; i < n; i++){
            System.out.println("Nhập phần tử thứ" + i + ":");
            A[i] = scanner.nextInt();
        }
        
        
        System.out.println("Các phàn tử chia hết cho 2:");
        for (int i = 0; i < n; i++){
            if (A[i] % 2 == 0){
                System.out.println(A[i] + "/t");
            }
        }
        
    }
    
}
bài 3


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

/**
 *
 * @author Administrator
 */
public class main {
    public static void main(String[] args) {
        Book book1 = new Book();
        Book book2 = new Book();
        
        book1.input();
        book1.display();
        
        book2.input();
        book2.display();
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Book;

import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class Book {
    String bookName;
    String auThor;
    String producer;
    String year;

    public Book() {
    }

    public Book(String bookName, String auThor, String producer, String year) {
        this.bookName = bookName;
        this.auThor = auThor;
        this.producer = producer;
        this.year = year;
    }

    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 getProducer() {
        return producer;
    }

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

    public String getYear() {
        return year;
    }

    public void setYear(String year) {
        this.year = year;
    }
     public void input(){
         Scanner scanner = new Scanner(System.in);
         System.out.println("===============");
         System.out.println("Nhập tên sách");
         bookName = scanner.nextLine();
         System.out.println("Nhập tên tác giả ");
         auThor = scanner.nextLine();
         System.out.println("Nhập nhà sản xuất");
         producer = scanner.nextLine();
         System.out.println("Nhập năm sản xuất");
         year = scanner.nextLine();
     }
     public void display(){
         System.out.println(toString());
     }

    @Override
    public String toString() {
        return "Book{" + "bookName=" + bookName + ", auThor=" + auThor + ", producer=" + producer + ", year=" + year + '}';
    }
     
}

bài 5


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

/**
 *
 * @author Administrator
 */
public class Test {
      public static void main(String[] args) {
        Car car = new Car();
        BikeCycle BC = new BikeCycle();
        
        car.runnimg();
        car.input();
        car.display();
        
        BC.running();
        BC.input();
        BC.display();
        
    }
    
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Bai4;

import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class Car {
      String name;
    int numberOfWheel;

    public Car() {
    }

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

    public String getName() {
        return name;
    }

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

    public int getNumberOfWheel() {
        return numberOfWheel;
    }

    public void setNumberOfWheel(int numberOfWheel) {
        this.numberOfWheel = numberOfWheel;
    }
    
    
    public void runnimg() {
        System.out.println("Car is running");
    }

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

    public void display() {
        System.out.println("Ten : " + name);
        System.out.println("So banh xe :" + numberOfWheel);
    }
}



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

import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class BikeCycle {
    String name;
    int numberOfWheel;

    public BikeCycle() {
    }

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

    public String getName() {
        return name;
    }

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

    public int getNumberOfWheel() {
        return numberOfWheel;
    }

    public void setNumberOfWheel(int numberOfWheel) {
        this.numberOfWheel = numberOfWheel;
    }
     
    public void running() {
        System.out.println("BikeCycle is running");
    }

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

    public void display() {
        System.out.println("Ten :  " + name);
        System.out.println("So banh xe :" + numberOfWheel);
    }
}



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

/**
 *
 * @author Administrator
 */
public abstract class Vehicle {
    public abstract void running();
    public abstract void input();
    public abstract void display();
    
}
bài 4


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

import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class People {
     String name;
    String 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("Nhap ten:");
        name = scan.nextLine();
        System.out.println("Nhap dia chi:");
        address = scan.nextLine();
    }
    public void display(){
        System.out.println(toString());
    }

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



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Bai4;

/**
 *
 * @author Administrator
 */
public class main {
     public static void main(String[] args) {
        People p = new People();
        Student t = new Student();
        
        p.input();
        p.display();
        
        t.input();
        t.display();
        
        p.input();
        p.display();
        
        t.input();
        t.display();
    }  
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Bai4;

import java.util.Scanner;

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

    public Student() {
    }

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

    public String getRollNo() {
        return rollNo;
    }

    public void setRollNo(String rollNo) {
        this.rollNo = rollNo;
    }
    public void input(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap rollNo");
        rollNo = scan.nextLine();
    }
    public void display(){
        System.out.println("rollNo : " + rollNo);
    }
}



Trần Anh Quân [T1907A]
Trần Anh Quân

2020-03-11 16:32:46

b5


package kt60p;

public class Test1 { 
    public static void main(String[] agrs) {
        Car car = new Car();
        BikeCycle bike = new BikeCycle();
        System.out.println("Nhập thông tin Car:");
        car.input();
        System.out.println("Nhập thông tin BikeCycle:");
        bike.input();
        System.out.println("Thông tin của Car:");
        car.display();
        System.out.println("Thông tin của BikeCycle:");
        bike.display();  
    }
}




package kt60p;
import java.util.Scanner;
public class Car extends Vehicle {
    String name;
    int soBanhXe;
    @Override
    public void running() {
        System.out.print("Car is running!!!");
    }

    @Override
    public void input() {
        Scanner scan = new Scanner(System.in);
        System.out.print("Nhập tên xe: ");
        name = scan.nextLine();
        System.out.print("Nhập số bánh xe: ");
        soBanhXe = Integer.parseInt(scan.nextLine());
    }
    @Override
    public void display() {
        System.out.println("Tên xe: " + name);
        System.out.println("Số bánh xe: " + soBanhXe);
    }
}



package kt60p;
import java.util.Scanner;
public class BikeCycle extends Vehicle {
    String name;
    int soBanhXe;
    @Override
    public void running() {
        System.out.print("BikeCycle is running!!!");
    }

    @Override
    public void input() {
        Scanner scan = new Scanner(System.in);
        System.out.print("Nhập tên xe: ");
        name = scan.nextLine();
        System.out.print("Nhập số bánh xe: ");
        soBanhXe = Integer.parseInt(scan.nextLine());
    }

    @Override
    public void display() {
        System.out.println("Tên xe: " + name);
        System.out.println("Số bánh xe: " + soBanhXe);
    }
}






package kt60p;

public abstract class Vehicle {
    public abstract void running();
    public abstract void input();
    public abstract void display();
}






Minh Nghia [T1907A]
Minh Nghia

2020-03-11 15:43:58

Bai1



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Overview60P;

import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class Bai1 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);    
           
        System.out.println("Nhap so nguyen can tinh tong:");
        int n = Integer.parseInt(scan.nextLine());
        int sum = 0;
        while(n != 0){
            sum += n%10;
            n/=10;
        }
        System.out.println("SUM = " + sum);
    }
}

bai 2:




/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Overview60P;

import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class Bai2 {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n;
        
        do{
            System.out.println("Nhap phan tu cho mang: ");
            n = scan.nextInt();
        }while(n < 0);
        int arr[] = new int[n];
        System.out.println("Nhap cac phan tu cho mang:");
        for (int i = 0; i < n; i++) {
            System.out.println("Nhap phan tu thu : " + i);
            arr[i] = scan.nextInt();
        }
        for (int j = 0; j < n; j++) {
            if(arr[j] % 2 ==0){
                System.out.println("Cac so chia het cho 2: " + arr[j]);
            }
        }
        
    }
}
bai 3:




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

import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class Book {
    String nameBook;
    String author;
    String nsx;
    int namSX;

    public Book() {
    }

    public Book(String nameBook, String author, String nsx, int namSX) {
        this.nameBook = nameBook;
        this.author = author;
        this.nsx = nsx;
        this.namSX = namSX;
    }

    public String getNameBook() {
        return nameBook;
    }

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

    public String getAuthor() {
        return author;
    }

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

    public String getNsx() {
        return nsx;
    }

    public void setNsx(String nsx) {
        this.nsx = nsx;
    }

    public int getNamSX() {
        return namSX;
    }

    public void setNamSX(int namSX) {
        this.namSX = namSX;
    }
    
    public void input(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap ten sach");
        nameBook = scan.nextLine();
        System.out.println("Nhap ten tac gia:");
        author = scan.nextLine();
        System.out.println("Nhap nha san xuat:");
        nsx = scan.nextLine();
        System.out.println("Nhap nam san xuat:");
        namSX = Integer.parseInt(scan.nextLine());
    }
    public void display(){
        System.out.println(toString());
    }
    @Override
    public String toString() {
        return "Book{" + "nameBook=" + nameBook + ", author=" + author + ", nsx=" + nsx + ", namSX=" + namSX + '}';
    }
    
}



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

/**
 *
 * @author Administrator
 */
public class Test {
    public static void main(String[] args) {
        Book book1 = new Book();
        Book book2 = new Book();
        
        book1.input();
        book1.display();
        
        book2.input();
        book2.display();
    }
}

bai 4:



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

import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class People {
    String name;
    String 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("Nhap ten:");
        name = scan.nextLine();
        System.out.println("Nhap dia chi:");
        address = scan.nextLine();
    }
    public void display(){
        System.out.println(toString());
    }

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



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Overview60P;

import java.util.Scanner;

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

    public Student() {
    }

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

    public String getRollNo() {
        return rollNo;
    }

    public void setRollNo(String rollNo) {
        this.rollNo = rollNo;
    }
    @Override
    public void input(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap rollNo");
        rollNo = scan.nextLine();
    }
    @Override
    public void display(){
        System.out.println("rollNo : " + rollNo);
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Overview60P;

/**
 *
 * @author Administrator
 */
public class Test4 {
    public static void main(String[] args) {
        People p = new People();
        Student t = new Student();
        
        p.input();
        p.display();
        
        t.input();
        t.display();
    }
}
bai 5:




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

import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class BikeCycle extends Vehicle{
    String name;
    int numberOfWheel;

    public BikeCycle() {
    }

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

    public String getName() {
        return name;
    }

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

    public int getNumberOfWheel() {
        return numberOfWheel;
    }

    public void setNumberOfWheel(int numberOfWheel) {
        this.numberOfWheel = numberOfWheel;
    }
     
    
    @Override
    public void runnimg() {
        System.out.println("BikeCycle is running");
    }

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

    @Override
    public void display() {
        System.out.println("Nhap ten:" + name);
        System.out.println("Nhap so banh xe:" + numberOfWheel);
    }
    
}



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

import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class Car extends Vehicle{
    String name;
    int numberOfWheel;

    public Car() {
    }

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

    public String getName() {
        return name;
    }

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

    public int getNumberOfWheel() {
        return numberOfWheel;
    }

    public void setNumberOfWheel(int numberOfWheel) {
        this.numberOfWheel = numberOfWheel;
    }
    
    
    @Override
    public void runnimg() {
        System.out.println("Car is running");
    }

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

    @Override
    public void display() {
        System.out.println("Ten : " + name);
        System.out.println("So banh xe :" + numberOfWheel);
    }
}



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

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



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Overview60P;

/**
 *
 * @author Administrator
 */
public class Test5 {
    public static void main(String[] args) {
        Car car = new Car();
        BikeCycle BC = new BikeCycle();
        
        car.runnimg();
        car.input();
        car.display();
        
        BC.runnimg();
        BC.input();
        BC.display();
        
    }
}



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

2020-03-11 15:10:37

bài 5 :

main :

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

/**
 *
 * @author Nong
 */
public class Main {
    public static void main(String[] args) {
        Car car = new Car();
        BikeCycle BC = new BikeCycle();
        
        car.runnimg();
        car.input();
        car.display();
        
        BC.runnimg();
        BC.input();
        BC.display();
        
    }
}

vehicle:

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

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

car:

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

import java.util.Scanner;

/**
 *
 * @author NoLg
 */
public class Car extends Vehicle{
    String name;
    int numberOfWheel;

    public Car() {
    }

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

    public String getName() {
        return name;
    }

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

    public int getNumberOfWheel() {
        return numberOfWheel;
    }

    public void setNumberOfWheel(int numberOfWheel) {
        this.numberOfWheel = numberOfWheel;
    }
    
    
    @Override
    public void runnimg() {
        System.out.println("Car is running");
    }

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

    @Override
    public void display() {
        System.out.println("Ten : " + name);
        System.out.println("So banh xe :" + numberOfWheel);
    }
}

bikecycle: 

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

import java.util.Scanner;

/**
 *
 * @author Long
 */
public class BikeCycle extends Vehicle{
    String name;
    int numberOfWheel;

    public BikeCycle() {
    }

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

    public String getName() {
        return name;
    }

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

    public int getNumberOfWheel() {
        return numberOfWheel;
    }

    public void setNumberOfWheel(int numberOfWheel) {
        this.numberOfWheel = numberOfWheel;
    }
     
    
    @Override
    public void runnimg() {
        System.out.println("BikeCycle is running");
    }

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

    @Override
    public void display() {
        System.out.println("Ten :  " + name);
        System.out.println("So banh xe :" + numberOfWheel);
    }
    
}


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

2020-03-11 14:47:26

bài 4 :

main:

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

/**
 *
 * @author Nong
 */
public class Main {
    public static void main(String[] args) {
        People p = new People();
        Student t = new Student();
        
        p.input();
        p.display();
        
        t.input();
        t.display();
        
        p.input();
        p.display();
        
        t.input();
        t.display();
    }
}

student:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Bai4_javabasic;

import java.util.Scanner;

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

    public Student() {
    }

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

    public String getRollNo() {
        return rollNo;
    }

    public void setRollNo(String rollNo) {
        this.rollNo = rollNo;
    }
    @Override
    public void input(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap rollNo");
        rollNo = scan.nextLine();
    }
    @Override
    public void display(){
        System.out.println("rollNo : " + rollNo);
    }
}

people:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Bai4_javabasic;

import java.util.Scanner;

/**
 *
 * @author Nongnek
 */
public class People { 
    String name;
    String 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("Nhap ten:");
        name = scan.nextLine();
        System.out.println("Nhap dia chi:");
        address = scan.nextLine();
    }
    public void display(){
        System.out.println(toString());
    }

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


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

2020-03-11 14:39:18

bài 3 :

book: 

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Bai3_javabasic;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Book {
    String bookName;
    String auThor;
    String producer;
    String year;

    public Book() {
    }

    public Book(String bookName, String auThor, String producer, String year) {
        this.bookName = bookName;
        this.auThor = auThor;
        this.producer = producer;
        this.year = year;
    }

    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 getProducer() {
        return producer;
    }

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

    public String getYear() {
        return year;
    }

    public void setYear(String year) {
        this.year = year;
    }
     public void input(){
         Scanner scanner = new Scanner(System.in);
         System.out.println("===============");
         System.out.println("Nhập tên sách");
         bookName = scanner.nextLine();
         System.out.println("Nhập tên tác giả ");
         auThor = scanner.nextLine();
         System.out.println("Nhập nhà sản xuất");
         producer = scanner.nextLine();
         System.out.println("Nhập năm sản xuất");
         year = scanner.nextLine();
     }
     public void display(){
         System.out.println(toString());
     }

    @Override
    public String toString() {
        return "Book{" + "bookName=" + bookName + ", auThor=" + auThor + ", producer=" + producer + ", year=" + year + '}';
    }
     
}

main:

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

/**
 *
 * @author Nong
 */
public class Main {
    public static void main(String[] args) {
        Book book1 = new Book();
        Book book2 = new Book();
        
        book1.input();
        book1.display();
        
        book2.input();
        book2.display();
    }
}