Skip to content

Instantly share code, notes, and snippets.

View letrongtanbs's full-sized avatar
😅
I may be slow to respond.

Lê Trọng Tân letrongtanbs

😅
I may be slow to respond.
View GitHub Profile
@letrongtanbs
letrongtanbs / calculateTheAreaOfCircle
Created October 6, 2016 10:53
Excercise 2:: /**To declare one variable is constant, we have the structure: *final datatype Name = value; *example: *final double Pi = 3.14159 ; /*Pi will remain unchanged during class ... :) Write a main method to require the user to enter the radius , then print out the area of a circle based on the radius.. P / s: use the constant pi constan…
/**
* Write a description of class CalArea here.
*
* @author (Tom)
* @version (a version number or a date)
*/
import java.util.Scanner;
public class CalArea{
// instance variables - replace the example below with your own
@letrongtanbs
letrongtanbs / monthlyPayment
Last active December 10, 2024 16:33
The output is the monthly payment and total payment, which can be obtained using the following formulas: monthlyPayment = loanAmount * monthlyInterestRate /(1 - 1 / Math.pow(1 + monthlyInterestRate, numberOfYears * 12)); totalPayment = monthlyPayment * numberOfYears * 12 So, the input needed for the program is the monthly interest rate, the leng…
/**
* The output is the monthly payment and total payment,
* which can be obtained using the following formulas:
* monthlyPayment = loanAmount * monthlyInterestRate /(1 - 1 / Math.pow(1 + monthlyInterestRate, numberOfYears * 12));
* totalPayment = monthlyPayment * numberOfYears * 12
* So, the input needed for the program is the monthly interest rate, the length of the loan in years, and the loan amount.
*
* @author Tom
* @version (a version number or a date)
@letrongtanbs
letrongtanbs / countyear
Created October 7, 2016 11:15
/** * (Find the number of years) Write a program that prompts the user to enter the * minutes (e.g., 1 billion), and displays the number of years and days for the minutes. * For simplicity, assume a year has 365 days. * * @author Tom * @Version (a version number or a date) */
/**
* (Find the number of years) Write a program that prompts the user to enter the
* minutes (e.g., 1 billion), and displays the number of years and days for the minutes.
* For simplicity, assume a year has 365 days.
*
* @author Tom
* @version (a version number or a date)
*/
import java.util.Scanner;
import java.util.Scanner;
import java.util.Random;
/**
*Candygame
*
*/
public class CandyGame {
public static void main(String[] args) {
System.out.println("Welcome to Candy Game");
@letrongtanbs
letrongtanbs / validPassword
Created February 7, 2017 18:27
(Check password ) Some websites impose certain rules for passwords. Write a method that checks whether a string is a valid password. Suppose the password rules are as follows: ■ A password must have at least eight characters. ■ A password consists of only letters and digits. ■ A password must contain at least two digits.
package intro;
import userlib.TextIO;
import java.util.*;
import java.lang.String;
import java.lang.Character;
public class CheckPassWord {
public static void main(String[] args){
String pwd;
TextIO.putln("Enter your password: ");
@letrongtanbs
letrongtanbs / hexNumber
Created February 7, 2017 18:29
Write a program that prompts the user to enter an integer between 0 and 15 and displays its corresponding hex number
package intro;
import userlib.TextIO;
public class intro {
public static void main(String[] args){
int x,y;
System.out.println("Enter a number to convert: ");
x = TextIO.getInt();
while(x<0||x>=16){
TextIO.putln("Wrong input, it must be lower than 15 and greater than 0");
@letrongtanbs
letrongtanbs / linearEquation
Created February 8, 2017 05:02
Use Cramer’s rule to solve the following 2 * 2 system of linear equation: ax + by = e cx + dy = f Write a program that solves the following equation and displays the value
package intro;
import userlib.TextIO;
public class LinearEquation {
public static void main(String[] args){
double x,y;
double a,b,c,d,e,f;
double d0, dx, dy;
TextIO.putln("We going to solve a linear Equation with form:");
package intro;
import java.util.Scanner;
public class AmbiguousOverloading {
public static void main(String[] args) {
Scanner ip= new Scanner(System.in);
int years;
System.out.println("Enter year to check is leaf year or not!");
years = ip.nextInt();
@letrongtanbs
letrongtanbs / isPalindrome
Created March 3, 2017 09:02
A string is a palindrome if it reads the same forward and backward.The words “mom,” “dad,” and “noon,” for instance, are all palindromes
package intro;
import java.util.Scanner;
public class Palindrome {
public static void main(String[] args) {
Scanner ip= new Scanner(System.in);
@letrongtanbs
letrongtanbs / DeckOfCards.java
Created March 7, 2017 08:57
Card numbers 0to 12, 13to 25, 26to 38, and 39to 51represent 13 Spades, 13 Hearts, 13 Diamonds, and 13 Clubs, respectively, as shown in Figure 7.2. cardNumber / 13determines the suit of the card and cardNumber % 13determines the rank of the card, as shown in Figure 7.3. After shuffling the array deck, pick the first four cards from deck. The prog…
package intro;
import userlib.TextIO;
public class DeckOfCards {
public static void main(String[] args) {
int[]deck = new int[52];
String[] suits = {"Spades", "Hearts", "Diamons", "Clubs"};
String[] ranks = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};