You are on page 1of 9

NAMA : Zulfa Ikhsanuddin Hakim

NIM : 1202210317

SI-45-09

Practices 1 :

Task :

public class Practice1 {


public static void main(String args[]) {
System.out.println("Hello World!");
}
}

Practices 2 :

Task 1 :

public class Practice1 {


public static void main(String args[]) {
{
System.out.println (" XXXXXXXXX");
System.out.println (" X X");
System.out.println ("X X X X");
System.out.println ("X X");
System.out.println ("X X X X");
System.out.println ("X xxx X");
System.out.println (" X X");
System.out.println (" XXXXXXXXX");
}
}
}

Task 2 :

public class Practice1 {


public static void main(String args[]) {
System.out.println (" /\\ /\\");
System.out.println (" / \\_______/ \\");
System.out.println (" / \\");
System.out.println ("( /\\ /\\ )");
System.out.println ("===== V =====");
System.out.println ("======(__|__)======");
System.out.println (" ( )");
System.out.println (" (______________)");

}
}
Practice 3 :

Task :

import java.util.Scanner;
class games {
public static void main(String[] args) throws Exception {
try (// import java.util.Scanner;
Scanner input = new Scanner(System.in)) {
System.out.print("Enter name: ");
String codename = input.nextLine();
System.out.print("Enter location: ");
String location = input.nextLine();
System.out.print("Enter day: ");
String day = input.nextLine();
System.out.print("Enter mission: ");
String mission = input.nextLine();
System.out.print("Enter number: ");
int number = input.nextInt();
System.out.print("Enter coordinate: ");
double coordinate = input.nextDouble();
if (mission.length() <= 10 ) {
System.out.println("mission must be more 10 inputs");
}
if (mission.length() >= 10 ) {
System.out.println("the ministry of internal affair has appointed you
"+ number +" codename " + codename + " to infiltrate the " + location + " located
at southern part from the zone of alienation");
System.out.println("you will be deployed at coordinate "+ coordinate
+ " with any nesecities for " + day +" days" );
System.out.println("your mission is to " + mission +" i hope you
goodluck agent");
}
}
}
}

Practice 4 :

Task 1 :

import java.util.Scanner;
public class Practice4 {
public static void main(String[]args){
convertFToC();

Scanner input = new Scanner(System.in);


double side1, side2, hypo;
System.out.print("Enter a value for Side 1: ");
side1 = input.nextDouble();
System.out.print("Enter a value for Side 2: ");
side2 = input.nextDouble();
hypo =hypoCal(side1,side2);
System.out.println("The length of the hypotenuse is: " + hypo);
int dice = (int)(Math.random()*12)+1;
System.out.println("The sum of the dice values is " + dice);
}
/*gets input representing fahrenheit and displays celsius equivalent*/
public static void convertFToC(){
Scanner scan = new Scanner(System.in);
System.out.println("Enter Fahrenheit temperature");
double fahrenheit = scan.nextInt();
System.out.println(fahrenheit + " degrees Fahrenheit is " +
toCelsius(fahrenheit) + " degrees Celsius");
}
/* calculates and returns the celsius equivalent */
public static double toCelsius(double fahr){
int BASE = 32;
double CONVERSION_FACTOR = 9.0/ 5.0;
double celsius = ((fahr-BASE)/(CONVERSION_FACTOR));
return celsius;
}
static double hypoCal(double s1,double s2){
return Math.sqrt(Math.pow(s1, 2) + Math.pow(s2, 2));}
}
Task 2 :

import java.util.Scanner;
class name {
public static void main(String[] args) throws Exception {
Scanner scan = new Scanner ( System.in);
System.out.println(" Enter Name : ");
String name = scan.nextLine();
System.out.println("Input: " + name);
System.out.println("Formated: " + formatName(name));
}

public static String formatName ( String name ) throws Exception {


String[] nameTokenized = name.split(" ");
if (nameTokenized.length!=2){
throw new Exception("Incorrect Name");
}
String firstName = nameTokenized[0];
String lastName = nameTokenized[1];
char firstChar = firstName.charAt(0);

return lastName + ", " + firstChar;


}//end formatName
}
Practice 5 :

Task 1 :

import java.util.Scanner;
class task2 {
public static void main(String[] args) {
System.out.print("Enter a color code : ");
Scanner myObj = new Scanner(System.in);
int color = myObj.nextInt();
if (color >= 380 && color <= 450 ) {
System.out.print("violet");
}
if (color >= 450 && color <= 495 ) {
System.out.print("blue");
}
if (color >= 495 && color <= 570 ) {
System.out.print("Green");
}
if (color >= 570 && color <= 590 ) {
System.out.print("Yellow");
}
if (color >= 590 && color <= 620 ) {
System.out.print("Orange");
}
if (color >= 620 && color <= 750 ) {
System.out.print("Red");
}
else {
System.out.print("The entered wavelength is not a part of the visible
spectrum");
}
}
}
Task 2 :

import java.util.Scanner;
class traffic {
public static void main(String[] args) {
System.out.print("Enter a color code : ");
Scanner myObj = new Scanner(System.in);
int color = myObj.nextInt();
if (color == 1 ) {
System.out.print("Next Traffic Light is green");
}
if (color == 2 ) {
System.out.print("Next Traffic Light is yellow");
}
if (color == 3 ) {
System.out.print("Next Traffic Light is red");
}
if (color <= 1) {
System.out.print("Invalid color");
}
if (color >= 3) {
System.out.print("Invalid color");
}
}
}

You might also like