Skip to content

Commit 3a6f600

Browse files
committed
update
1 parent ba34dd6 commit 3a6f600

File tree

8 files changed

+469
-6
lines changed

8 files changed

+469
-6
lines changed

src/kevinGates/CalendarExample.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package kevinGates;
2+
3+
import java.text.DateFormat;
4+
import java.text.SimpleDateFormat;
5+
import java.util.Calendar;
6+
import java.util.Date;
7+
import java.util.List;
8+
import java.util.Map;
9+
10+
public class CalendarExample {
11+
12+
private static final DateFormat dateFormatMinute = new SimpleDateFormat("HH:mm");
13+
14+
public static void main(String[] args) {
15+
// int currentMinute = getCurrentMinute();
16+
//
17+
// int i=currentMinute-15;
18+
//
19+
// while(i<1440) {
20+
// String each15Minutes = getDateTimePlusMinute(-i);
21+
// System.out.print(each15Minutes+" ");
22+
// i=i+15;
23+
// }
24+
25+
ArrayList minutesArray = new ArrayList();
26+
int currentMinute = getCurrentMinute();
27+
28+
int k=currentMinute-15;
29+
30+
while(k<1440) {
31+
String each15Minutes = getDateTimePlusMinute(-k);
32+
minutesArray.add(each15Minutes);
33+
34+
k = k + 15;
35+
}
36+
Collections.reverse(minutesArray);
37+
//Map<String, ArrayList> mapMinutes = new HashMap<String, ArrayList>();
38+
//mapMinutes.put("minutes", minutesArray);
39+
40+
//return mapMinutes;
41+
42+
}
43+
44+
public static String getDateTimePlusMinute(int minutes) {
45+
46+
Date currentDate = new Date();
47+
48+
Calendar calendar = Calendar.getInstance();
49+
calendar.setTime(currentDate);
50+
51+
calendar.add(Calendar.MINUTE, minutes);
52+
53+
return dateFormatMinute.format(calendar.getTime());
54+
}
55+
56+
public static int getCurrentMinute() {
57+
Date currentDate = new Date();
58+
59+
Calendar calendar = Calendar.getInstance();
60+
calendar.setTime(currentDate);
61+
62+
return calendar.get(Calendar.MINUTE);
63+
}
64+
}

src/kevinGates/DataType.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package kevinGates;
2+
3+
import java.text.DecimalFormat;
4+
import java.util.Random;
5+
6+
public class DataType {
7+
8+
public static void main(String[] args) {
9+
// TODO Auto-generated method stub
10+
double qyt = 0.0000000389283283;
11+
double qytOne = 800.0000000389283283;
12+
13+
System.out.println(qyt);
14+
15+
DecimalFormat decimalFormat = new DecimalFormat("#.########");
16+
System.out.println(decimalFormat.format(qyt));
17+
System.out.println(decimalFormat.format(qytOne));
18+
19+
Random random = new Random();
20+
21+
// create a big random number - maximum is ffffff (hex) = 16777215 (dez)
22+
23+
// format it as hexadecimal string (with hashtag and leading zeros)
24+
String colorCode = String.format("#%06x", random.nextInt(256*256*256));
25+
26+
// print it
27+
System.out.println(colorCode);
28+
29+
}
30+
}

src/kevinGates/HashMap.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package kevinGates;
2+
3+
import java.util.*;
4+
5+
public class HashMap {
6+
7+
public static void main(String args[]) {
8+
// Map<Integer, String> hm = new HashMap<Integer, String>();
9+
//
10+
// //HashMap<Integer,String> hm=new HashMap<Integer,String>();
11+
// hm.put(100,"Amit");
12+
// hm.put(101,"Vijay");
13+
// hm.put(102,"Rahul");
14+
15+
}
16+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package kevinGates;
2+
3+
import java.io.BufferedReader;
4+
import java.io.DataOutputStream;
5+
import java.io.InputStreamReader;
6+
import java.net.HttpURLConnection;
7+
import java.net.URL;
8+
9+
import javax.net.ssl.HttpsURLConnection;
10+
11+
public class HttpURLConnectionExample {
12+
13+
private final String USER_AGENT = "Mozilla/5.0";
14+
15+
public static void main(String[] args) throws Exception {
16+
17+
HttpURLConnectionExample http = new HttpURLConnectionExample();
18+
19+
String url = "https://api.coinmarketcap.com/v2/ticker/1/";
20+
String data= http.httpGet(url);
21+
System.out.println(data);
22+
}
23+
24+
private String httpGet(String apiUrl) throws Exception {
25+
URL url = new URL(apiUrl);
26+
HttpURLConnection request = (HttpURLConnection) url.openConnection();
27+
28+
request.setRequestMethod("GET");
29+
30+
BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream()));
31+
32+
String inputLine;
33+
StringBuffer response = new StringBuffer();
34+
35+
while ((inputLine = in.readLine()) != null) {
36+
response.append(inputLine);
37+
}
38+
in.close();
39+
40+
return response.toString();
41+
}
42+
43+
// HTTP GET request
44+
private void sendGetOne() throws Exception {
45+
//https://api.coinmarketcap.com/v2/ticker/1/
46+
String url = "https://api.coinmarketcap.com/v2/ticker/1/";
47+
48+
URL obj = new URL(url);
49+
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
50+
51+
// optional default is GET
52+
con.setRequestMethod("GET");
53+
54+
//add request header
55+
con.setRequestProperty("User-Agent", USER_AGENT);
56+
57+
int responseCode = con.getResponseCode();
58+
System.out.println("\nSending 'GET' request to URL : " + url);
59+
System.out.println("Response Code : " + responseCode);
60+
61+
BufferedReader in = new BufferedReader(
62+
new InputStreamReader(con.getInputStream()));
63+
String inputLine;
64+
StringBuffer response = new StringBuffer();
65+
66+
while ((inputLine = in.readLine()) != null) {
67+
response.append(inputLine);
68+
}
69+
in.close();
70+
71+
//print result
72+
System.out.println(response.toString());
73+
}
74+
75+
}

src/kevinGates/ListExample.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package kevinGates;
2+
3+
import java.util.*;
4+
class Book {
5+
int id;
6+
String name,author,publisher;
7+
int quantity;
8+
public Book(int id, String name, String author, String publisher, int quantity) {
9+
this.id = id;
10+
this.name = name;
11+
this.author = author;
12+
this.publisher = publisher;
13+
this.quantity = quantity;
14+
}
15+
}
16+
17+
public class ListExample {
18+
public static void main(String[] args) {
19+
//Creating list of Books
20+
List<Book> books=new ArrayList<Book>();
21+
//Creating Books
22+
Book b1=new Book(101,"kevin gates","Yashwant Kanetkar","BPB",8);
23+
Book b2=new Book(102,"bill gates","Forouzan","Mc Graw Hill",4);
24+
Book b3=new Book(103,"obama","Galvin","Wiley",6);
25+
//Adding Books to list
26+
books.add(b1);
27+
books.add(b2);
28+
books.add(b3);
29+
30+
for(Book book:books) {
31+
System.out.println(book.id+" "+book.name+" "+book.author+" "+book.publisher+" "+book.quantity);
32+
}
33+
}
34+
}

src/kevinGates/Md5Example.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package kevinGates;
2+
3+
import java.security.MessageDigest;
4+
import java.security.NoSuchAlgorithmException;
5+
6+
public class Md5Example {
7+
8+
public static void main(String[] args) {
9+
10+
System.out.println(md5String("data"));
11+
}
12+
13+
public static String md5String(String stringToHash) {
14+
String generatedString = null;
15+
try {
16+
MessageDigest md = MessageDigest.getInstance("MD5");
17+
18+
md.update(stringToHash.getBytes());
19+
20+
byte[] bytes = md.digest();
21+
22+
StringBuilder sb = new StringBuilder();
23+
for(int i=0; i< bytes.length ;i++)
24+
{
25+
sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1));
26+
}
27+
28+
generatedString = sb.toString();
29+
} catch (NoSuchAlgorithmException e) {
30+
e.printStackTrace();
31+
}
32+
33+
return generatedString;
34+
}
35+
}

0 commit comments

Comments
 (0)