1. Trang chủ
  2. » Luận Văn - Báo Cáo

bài tập assignments môn học et4430 lập trình nâng cao

40 0 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Bài tập (Assignments)
Tác giả Nguyễn Hoàng Hà
Chuyên ngành ET4430 – Lập trình nâng cao
Thể loại Assignments
Năm xuất bản 2021
Định dạng
Số trang 40
Dung lượng 2,62 MB

Nội dung

Ket qua bai 1---*/ System.out.println"---Ket qua bai --"; Rectangle rectangle = new Rectangle; rectangle.setHeight ; 2 System.out.println"Height use setHeight function: " + rectangle.g

Trang 1

System.out.println("Hello World");

// TODO Auto-generated method stub

double x1,y1,x2,y2,d,d2;

Scanner scanner = new Scanner (System.in);

System.out.println ("Nhap toa do diem thu nhat");

Trang 2

3

package b3;

// TODO Auto-generated method stub

double x1,y1,x2,y2,r1,r2,d,d2;

Scanner scanner = new Scanner (System.in);

System.out.println ("Nhap toa do tam duong tron 1:");

Trang 3

publicclass Rectangle {

public void setWidth(double width) {

this.width = width;

public double getPerimeter() {

return getHeight() + getWidth();

Trang 4

public void turnOn() {

public void setChannel (int newChanel) {

this.channel = newChanel;

System.out.println("Set "+ this.channel +" for this TV"); }

public void setVolume (int newVolumeLevel) {

this.volumeLevel = newVolumeLevel;

System.out.println("Set "+ this.volumeLevel+" for this TV"); }

public void channelUp() {

Trang 5

public static void main(String[] args) {

// TODO Auto-generated method stub

// TODO Auto-generated method stub

System.out.println(" -Ket qua bai 4: -"); Random random = new Random(1000);

int count = ; 0

for int( i = ; i < 0 50; i++) {

/* After 10 numbers go to the next line */

Trang 6

public Date getStartTime() {

return startTime;

}

public void setStartTime(Date startTime) {

this.startTime = startTime;

}

public Date getEndTime() {

return endTime;

}

public void setEndTime(Date endTime) {

this.endTime = endTime;

}

public stopWatch() {

startTime = new Date();

}

public void start() {

startTime = new Date();

}

public void stop() {

endTime = new Date();

}

public double getElapsedTime() {

return endTime.getTime() - startTime.getTime();

// TODO Auto-generated method stub

/* -1 Ket qua bai 1 -*/

System.out.println(" -Ket qua bai ");

Rectangle rectangle = new Rectangle();

rectangle.setHeight( ); 2

System.out.println("Height use setHeight function: " +

rectangle.getHeight());

Trang 7

System.out.println("Width after use setWidth function: " +

rectangle.getWidth());

rectangle = new Rectangle(4 5, );

System.out.println("Height use contrusctor have argument function: "+ rectangle.getHeight() );

System.out.println("Width use contrusctor have argument function: "+ rectangle.getWidth() );

System.out.println("The area of rectangle use contrusctor have argument function: " + rectangle.getArea());

System.out.println("The Perimeter of rectangle use contrusctor have argument function: " + rectangle.getPerimeter());

/* -2.Ket qua bai 2 -*/

System.out.println(" -Ket qua bai ");

/* -3.Ket qua bai 3 -*/

System.out.println(" -Ket qua bai -");

Date date = new Date((long) pow(10 2, ));

date = new Date((long) pow(10 4,));

System.out.println("date after 10000ms: " + date.toString());

date = new Date((long) pow(10 5,));

System.out.println("date after 100000ms: " + date.toString());

date = new Date((long) pow(10 6,));

System.out.println("date after 1000000ms: " + date.toString());

date = new Date((long) pow(10 7,));

System.out.println("date after 10000000ms: " + date.toString());

date = new Date((long) pow(10 8,));

System.out.println("date after 100000000ms: " + date.toString());

Trang 8

System.out.println("date after 1000000000ms: " + date.toString());

date = new Date((long) pow(10 10, ));

System.out.println("date after 10000000000ms: " + date.toString()); /* -3.Ket qua bai 4 -*/

System.out.println(" -Ket qua bai -");

Random random = new Random(1000);

int count = ; 0

for int( i = ; i < 0 50; i++) {

/* After 10 numbers go to the next line */

/* -5 Ket qua bai 5 -*/

System.out.println(" -Ket qua bai -");

stopWatch stopwatch = new stopWatch();

System.out.println("Start time after constructor: " +

stopwatch.setStartTime(new Date(1000));

System.out.println("Start time after use setStartTime function: "+ stopwatch.getStartTime());

stopwatch.setEndTime(new Date(100000));

System.out.println("End time after use setEndTime function: "+ stopwatch.getEndTime());

System.out.println("Time elapsed: " + stopwatch.getElapsedTime()); }

Trang 9

public int SLOW = ; 1

public int MEDIUM = ; 2

public int FAST = ; 3

this.speed = speed;

}

return on;

}

this.on = on;

}public double getRadius() {

return radius;

}

this.radius = radius;

}public String getColor() {

Trang 10

public void setColor(String color) {

this.color = color;

}

return ( "Fan is "+ this.color + " and the radius of the fan is " + this.radius);

public MyInteger(int value1) {

this.value= value1;

for (int i = 2; i < value; i++) {

if (value % i == ) 0 return false;

Trang 11

if (this.value == value2) return true; return false;

}

if (this.value == value3.value) return true; return false;

}

String newString = String.valueOf(arrayChar); int newValue = Integer.valueOf(newString); return newValue;

}

int newValue = Integer.valueOf(newString); return newValue;

private int id;

privatedouble balance;

Trang 12

public Account(int id, double balance) {

this.id = id;

this.balance = balance;

dateCreated = new Date();

}

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public double getBalance() {

return balance;

}

public void setBalance(double balance) {

this.balance = balance;

public double getMonthlyInterest() {

return balance * getAnnualInterestRate();

}

Trang 13

Scanner scanner = new Scanner(System.in);

double withdrawMoney = scanner.nextDouble();

balance -= withdrawMoney;

}

public void deposit() {

System.out.print("Enter an amount to deposit: ");

Scanner scanner = new Scanner(System.in);

double depositMoney = scanner.nextDouble();

System.out.println(" -Ket qua bai 4 -");

Account[] accountList = new Account[10];

for int( i = ; i < accountList.length; i++) { 0

accountList[i] = new Account(i, 1000000);

System.out.println("Main menu");

System.out.println("1: check balance");

System.out.println("2: withdraw");

System.out.println("3: deposit");

System.out.println("4: exit");

System.out.print("Enter a choice: ");

int choice = scanner.nextInt();

switch(choice) {

Trang 14

// TODO Auto-generated method stub

/* -Bai1 -*/

System.out.println(" -Ket qua bai 1 -");

Fan fan1 = new Fan();

Fan fan2 = new Fan();

Trang 15

/* -Bai2 -*/

System.out.println(" -Ket qua bai 2 -");

MyInteger value = new MyInteger( ); 0

MyInteger value1 = new MyInteger( ); 2

MyInteger value2 = new MyInteger(23);

MyInteger value3 = new MyInteger(25);

System.out.println("Gia tri 1 = "+ value1.getValue());

System.out.println("Gia tri 2 = "+ value2.getValue());

System.out.println("Gia tri 3 = "+ value3.getValue());

System.out.println("Gia tri 1 la so chan: " + value1.isEven());

System.out.println("Gia tri 1 la so le: " + value1.isOdd());

System.out.println("Gia tri 1 la so nguyen to: " + value1.isPrime());

System.out.println("Gia tri 2 la so chan: " + value2.isEven());

System.out.println("Gia tri 2 la so le: " + value2.isOdd());

System.out.println("Gia tri 2 la so nguyen to: " + value2.isPrime());

System.out.println("Gia tri 3 la so chan: " + value3.isEven());

System.out.println("Gia tri 3 la so le: " + value3.isOdd());

System.out.println("Gia tri 3 la so nguyen to: " + value3.isPrime());

MyInteger newMyInteger = new MyInteger( ); 9

System.out.println("newMyInteger chan: " +

System.out.print("Nhap so can kiem tra: ");

Scanner scanner = new Scanner(System.in);

int newNumber = scanner.nextInt();

System.out.println(newNumber + "= gia tri 1: " +

int convertNum = value.parseInt(charArray);

System.out.println("Mang chuyen thanh so: " + convertNum);

Trang 16

System.out.println("So chuyen thanh mang: " + convertNum); /* -Bai3 -*/

System.out.println(" -Ket qua bai 3 -");

Account account = new Account(1012, 20000000);

System.out.println(" -Ket qua bai 4 -");

Account[] accountList = new Account[10];

for int( i = ; i < accountList.length; i++) { 0

accountList[i] = new Account(i, 1000000);

System.out.println("Main menu");

System.out.println("1: check balance");

System.out.println("2: withdraw");

System.out.println("3: deposit");

System.out.println("4: exit");

System.out.print("Enter a choice: ");

int choice = scanner.nextInt();

Trang 17

this.color = color;

this.filled = filled;

this.dateCreated = new Date();

}

return color;

}

this.color = color;

}

Trang 18

}

this.filled = filled;

}

return dateCreated;

}

return ("Color: "+ this.color + " IsFilled: "+ this.filled + " Date:" + this.dateCreated );

public Circle2(double radius) {

this.radius = radius;

public void setRadius(double radius) {

this.radius = radius;

}

public double getArea(){

return Math.PI * Math.pow(this.radius,2);

}

public double getPerimeter(){

return * Math.PI * this.radius;

Trang 19

public double getDiameter(){

return * this.radius;

}

public String printCircle(){

return super.toString() + " Radius:"+this.radius;

}

}

2

this.name = name;

this.address = address;

this.phoneNumber = phoneNumber;

this.emailAddress = emailAddress;

}

this.name = name;

}

return name;

}

this.address = address;

}

Trang 20

return sum;

}

public String toString () {

return ("Color: "+ this.color + " ,IsFilled: "+ this.filled + " ,Date:" + this.dateCreated );

}

}

package assigment6_b1;

public class Rectangle extends GeometricObject {

private double width ;

private double height;

public Rectangle() {

}

public Rectangle(double width, double height) {

this.width = width;

this.height = height;

}

public Rectangle(double width, double height, String color, boolean

filled) {

super();

this.width = width;

this.height = height;

}

public double getWidth() {

return width;

}

public void setWidth(doublewidth) {

this.width = width;

}

public double getHeight() {

return height;

}

public void setHeight(doubleheight) {

this.height = height;

}

@Override

public double getArea() {

return width*height;

}

public double getPerimeter() {

return 2*(width height + );

}

public void printRectangle() {

System.out.println(super.toString() + " - Width: "

+ width + " - Height: " + height + " - Area: " + getArea() +

Trang 21

public class Square extends GeometricObject{

private doubleside;

public Square() {

}

public Square(double side) {

this.side = side;

public void setSide(doubleside) {

this.side = side;

public double getArea() {

return side*side;

public String toString() {

return super.toString() + " - Side: "

+ side + " - Area: " + getArea() + " - Perimeter: " + getPerimeter();

}

}

public class TestAss6_1 {

public static void main(String[] args) {

GeometricObject[] listGeometricObject = new GeometricObject[3];

listGeometricObject[0] = new Circle(1);

listGeometricObject[1] = new Rectangle(2, 4);

listGeometricObject[2] = new Square(7);

for( inti = 0; i < listGeometricObject.length; i++) {

System.out.println(" -GeometricObject " + ( + 1) + i "

Trang 22

public class Circle extends GeometricObject{

private doubleradius;

public Circle() {

}

public Circle(double radius) {

this.radius = radius;

public void setRadius(doubleradius) {

this.radius = radius;

}

@Override

public double getArea(){

return Math * Math.PI pow(this.radius,2);

}

public double getPerimeter(){

return 2* Math * PI this.radius;

}

public double getDiameter(){

return 2 * this.radius;

}

public String printCircle(){

return super.toString() + " Radius:" + getRadius() + ",Area: "

+ getArea() + ",Perimeter: "

+ getPerimeter() + ",Diameter: " + getDiameter(); }

@Override

public String toString() {

return super.toString() + ",Radius: "

+ getRadius() + ",Area: " + getArea() + ",Perimeter: " + getPerimeter() + ",Diameter: " + getDiameter(); }

}

Trang 23

public class GeometricObject {

private String color="white";

private boolean filled = true;

private Date dateCreated = new Date();

this.dateCreated = new Date();

}

public String getColor() {

return color;

}

public void setColor (String color) {

this.color = color;

}

public boolean isFilled() {

return this.filled;

}

public void setFilled(booleanfilled) {

; this.filled = filled

public String toString () {

return ("Color: "+ this.color + " ,IsFilled: "+ this.filled + " ,Date:" + this.dateCreated );

}

}

package assigment6_b2;

import java.util.Arrays;

public class SortCircles {

public static void main(String[] args) {

Circle[] circleList = new Circle[3];

circleList[0] = new Circle(1);

circleList[1] = new Circle(2);

circleList[2] = new Circle(3);

for(int = 0; < 3; ++) { i i

Ngày đăng: 11/06/2024, 17:41

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w