import java.util.Scanner;
public class combinationLock
{
//Sets the combination lock to C O I
public char FIRST_LETTER='C';
public char SECOND_LETTER='O';
public char THIRD_LETTER='I';
//Declare the 3 inputs of the user
public char first_input;
public char second_input;
public char third_input;
public static void main(String args[])
//Start getting their first letter
System.out.println("Please enter in the first letter in the combination: ");
char first_input=numbers.next().charAt(0);
Character.toUpperCase(first_input);
//Start getting their second letter
System.out.println("Please enter in the second letter in the combination: ");
char second_input=numbers.next().charAt(0);
Character.toUpperCase(second_input);
//Start getting their second letter
System.out.println("Please enter in the third letter in the combination: ");
char third_input=numbers.next().charAt(0);
Character.toUpperCase(third_input);
//Begin running the methods to begin lock comparison
lock.lockComparison1(first_input);
lock.lockComparison2(second_input);
lock.lockComparison3(third_input);
//Start the methods for the lock combination testing
public char lockComparison1(char first_input)
{
boolean first;
if(first_input=='C')
{
first=true;
System.out.println("Your first guess, \"C\" is correct.");
}
else if(first_input==SECOND_LETTER || first_input==THIRD_LETTER)
{
System.out.println("Your first guess, \""+first_input+"\" was not the first letter in the combination, yet it is used in the actual combination");
first=false;
}
else if(first_input!=SECOND_LETTER || first_input!=THIRD_LETTER)
{
System.out.println("You entered \""+first_input+"\" but it isn't a letter in any part of this combination.");
}
return first_input;
}
public char lockComparison2(char second_input)
{
boolean second;
if(second_input=='O')
{
second=true;
System.out.println("Your second guess, \"O\" is correct.");
}
else if(second_input==FIRST_LETTER || second_input==THIRD_LETTER)
{
System.out.println("Your second guess, \""+second_input+"\" was not the second letter in the combination, yet it is used in the actual combination");
second=false;
}
else if(second_input!=FIRST_LETTER || second_input!=THIRD_LETTER)
{
System.out.println("You entered \""+second_input+"\" but it isn't a letter in any part of this combination.");
}
return second_input;
}
public char lockComparison3(char third_input)
{
boolean third;
if(third_input=='I')
{
third=true;
System.out.println("Your third guess, \"I\" is correct.");
}
else if(third_input==FIRST_LETTER || third_input==SECOND_LETTER)
{
System.out.println("Your third guess, \""+third_input+"\" was not the third letter in the combination, yet it is used in the actual combination");
third=false;
}
else if(third_input!=SECOND_LETTER || third_input!=FIRST_LETTER)
{
System.out.println("You entered \""+third_input+"\" but it isn't a letter in any part of this combination.");
}
return third_input;
}
}
Friday, March 20, 2009
Exer5: Hello Object
//Programmer:Pacalioga, Mark Jay
//Program Name:Hello Object
//Purpose:
//Date:March 19,2009
//Instructor: Dony Dongiapon
import java.util.Scanner;
public class helloObject { public static void main(String[] args)
{
String text;
Scanner input=new Scanner(System.in);
System.out.println("Please Enter your Text:");
greetings=input.nextLine();
System.out.println();
System.out.println(text);
}
}
//Program Name:Hello Object
//Purpose:
//Date:March 19,2009
//Instructor: Dony Dongiapon
import java.util.Scanner;
public class helloObject { public static void main(String[] args)
{
String text;
Scanner input=new Scanner(System.in);
System.out.println("Please Enter your Text:");
greetings=input.nextLine();
System.out.println();
System.out.println(text);
}
}
Exer4. Name Echo
//programmer: Pacalioga, Mark Jay
//Program Name: Name Echo
//Date:March 19,2009
//Purpose:To enter name in capslock form
//instructor: Dony Dongiapon
import java.util.Scanner;
public class NameEcho{
public static void main(String args[])
{
Scanner scan=new Scanner(System.in);
String username;
String Firtsname;
String Lastname;
System.out.println("Enter name:");
//ask for the user’s name
name=scan.nextLine();
int x=username.indexOf(" ");
fname=username.substring(0,x);
lname=username.substring(x);
System.out.println("\n%s %s\n",Firtsname,Lastname.toUpperCase());
}
}
//Program Name: Name Echo
//Date:March 19,2009
//Purpose:To enter name in capslock form
//instructor: Dony Dongiapon
import java.util.Scanner;
public class NameEcho{
public static void main(String args[])
{
Scanner scan=new Scanner(System.in);
String username;
String Firtsname;
String Lastname;
System.out.println("Enter name:");
//ask for the user’s name
name=scan.nextLine();
int x=username.indexOf(" ");
fname=username.substring(0,x);
lname=username.substring(x);
System.out.println("\n%s %s\n",Firtsname,Lastname.toUpperCase());
}
}
Exer1. Word Reverser
//Programmer:Pacalioga, Mark Jay
//Program Name:Word Reverser
//Purpose:to reverse the entered word
//Date:March 17,2009
//Instructor: Dony Dongiapon
import java.io.*;
public class TestReverse
{
public static void main(String[] args) throws IOException
{
System.out.println("Enter a line to be reversed");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String inData;
inData = br.readLine();
ReverseString rs = new ReverseString();
System.out.println("Reversed: " + rs.reverse(inData));
}
}
//Program Name:Word Reverser
//Purpose:to reverse the entered word
//Date:March 17,2009
//Instructor: Dony Dongiapon
import java.io.*;
public class TestReverse
{
public static void main(String[] args) throws IOException
{
System.out.println("Enter a line to be reversed");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String inData;
inData = br.readLine();
ReverseString rs = new ReverseString();
System.out.println("Reversed: " + rs.reverse(inData));
}
}
Saturday, March 14, 2009
Iterator Arraylist exer.
/*
//ProgrammerName: Pacalioga, Mark Jay
//ProgramName: Iterator_arraylist
//Purpose: to iterate through the elements of java ArrayList object using Iterator.
//Date: March 02,2009
//Subject: Computer Programming 3
//Instructor: Dony Dongiapon
*/
import java.util.ArrayList;
public class MainClass {
public static void main(String args[]) {
ArrayList al = new ArrayList();
System.out.println("Initial size of al: " + al.size());
//Elements of array
al.add("C");
al.add("A");
al.add("E");
al.add("B");
al.add("D");
al.add("F");
al.add(1, "A2");
System.out.println("Size of al after additions: " + al.size());
System.out.println("Contents of al: " + al);
al.remove("F");
al.remove(2);
System.out.println("Size of al after deletions: " + al.size());
System.out.println("Contents of al: " + al);
}
}
Output:
Initial size of al: 0
Size of al after additions: 7
Contents of al: [C, A2, A, E, B, D, F]
Size of al after deletions: 5
Contents of al: [C, A2, E, B, D]
//ProgrammerName: Pacalioga, Mark Jay
//ProgramName: Iterator_arraylist
//Purpose: to iterate through the elements of java ArrayList object using Iterator.
//Date: March 02,2009
//Subject: Computer Programming 3
//Instructor: Dony Dongiapon
*/
import java.util.ArrayList;
public class MainClass {
public static void main(String args[]) {
ArrayList
System.out.println("Initial size of al: " + al.size());
//Elements of array
al.add("C");
al.add("A");
al.add("E");
al.add("B");
al.add("D");
al.add("F");
al.add(1, "A2");
System.out.println("Size of al after additions: " + al.size());
System.out.println("Contents of al: " + al);
al.remove("F");
al.remove(2);
System.out.println("Size of al after deletions: " + al.size());
System.out.println("Contents of al: " + al);
}
}
Output:
Initial size of al: 0
Size of al after additions: 7
Contents of al: [C, A2, A, E, B, D, F]
Size of al after deletions: 5
Contents of al: [C, A2, E, B, D]
Subscribe to:
Posts (Atom)