Exercise 4
Programmer: Mary Grace Cuming
Program Name: Name Echo
Date Started: March 16, 2009
Date Ended: March 19, 2009
Programm Purpose: A program that will ask a for the user name
And then print it back in a caps lock form.
import java.util.Scanner;
public class NameEcho{
public static void main(String args[])
{
Scanner scan=new Scanner(System.in);
String username;
String fname;
String lname;
System.out.println("Enter your name:"); //ask for the user’s name name=scan.nextLine(); //get the name of the user using the scanner
int x=username.indexOf(" ");
fname=username.substring(0,x);
lname=username.substring(x);
System.out.println("\n%s %s\n",fname,lname.toUpperCase());
}
}
********************************************************
Exercise 5
Programmer: Mary Grace Cuming
Program Name: Hello Object Program
Date Started: March 13, 2009
Date Ended: March 18, 2009
Programm Purpose: to Manipulate a String
import java.util.Scanner;
public class helloObject { public static void main(String[] args)
{
String greetings; // variable used for the input string. Scanner input=new Scanner(System.in); // get the string given by the user System.out.println("Please Enter your Greeting:");
greetings=input.nextLine();
System.out.println();
System.out.println(greetings);
}
}
********************************************************
Exercise 1
Programmer: Mary Grace Cuming
Program Name: Word Reverser
Date Started: March 13, 2009
Date Ended: March 18, 2009
Programm Purpose: A program that will ask a
String to the user,then the program will read it and
print it in a reverse form.
import java.util.*;
public class reverseword{
public static void main(String args[])
{
String inputword;
String word;
Scanner scan=new Scanner(System.in);
System.out.println("Enter a sentence:");
input=scan.nextLine();
StringTokenizer st=new StringTokenizer(wordinput) ;
while (st.hasMoreTokens())
{ word=st.nextToken();
word=new StringBuffer(r).reverse().toString(); System.out.println(word+" ");
}
}
}
*************************************************************
Programmer: Mary Grace Cuming
Date Started: March 16, 2009
Date Ended: March 20, 2009
Program Purpose A program that used number buttons from 0-9, and once the user clicked three correct
import java.awt.*;import javax.swing.*;public class CombinationLock extends JFrame {public static void main (String [] args)
{ new CombinationLock().setVisible(true);
}public CombinationLock () { Container od = getContentPane(); od.setLayout(new FlowLayout()); od.add(new JButton("0")); od.add(new JButton("1")); od.add(new JButton("2")); od.add(new JButton("3")); od.add(new JButton("4")); od.add(new JButton("5")); od.add(new JButton("6")); od.add(new JButton("7")); od.add(new JButton("8")); od.add(new JButton("9")); od setBackground(Color.pink); pack(); }}
Friday, March 20, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment