package untitled104;
// example of many TOLS and how to use them
import javax.swing.*;
public class Application1
{
public static void main(String[] args)
{
// DECLARE ALL VARIABLES
//**********************************************
String name,test,one,here,naddress,stuff,temp;
int len,pos_of_5,second_5;
String new_names[]=new String[5];
int a;
String temp_out,temp_name,last_name;
int pos_blank,how_long;
float average,adj_average;
String temp_average;
int final_average;
int b,num_a,count;
int number_of_a[]=new int[5];
//**********************************************
name = "smith";
test = new String("mary");
JOptionPane.showMessageDialog(null,name);
JOptionPane.showMessageDialog(null,test);
len= name.length();
one= "length is " + len;
JOptionPane.showMessageDialog(null,one);
here = name.substring(0,1);
naddress="123,345,3335333";
pos_of_5 = naddress.indexOf('5');
second_5 = naddress.indexOf('5',pos_of_5 + 1);
JOptionPane.showMessageDialog(null,"first letter " + here);
stuff=naddress.substring(pos_of_5+1,second_5);
JOptionPane.showMessageDialog(null,"stuff is " + stuff);
// NOW WE WILL INPUT 5 NAMES INTO AN ARRAY
// THEN CONCATENATE THEM TO A STRING AND PRINT them
// Also
for(a=0;a<5;a++)
{
num_a=0;
new_names[a]=JOptionPane.showInputDialog("Enter name "+(a+1)+" ");
count=new_names[a].length();
for(b=0;b<count;b++) // loop thru the name looking fo a's
{
if((new_names[a].charAt(b) == 'a') || (new_names[a].charAt(b) == 'A'))
{
num_a ++;
}
}
number_of_a[a] = num_a;
}
temp="LISTING of NAMES\n";
for(a=0;a<5;a++)
{
temp=temp+new_names[a]+" "+ number_of_a[a]+"\n";
}
JOptionPane.showMessageDialog(null,temp);
// NOW CONCATENATE THEM AGAIN TO A STRING BUT IN REVERSE ORDER
// AND PRINT THEM AGAIN -- THEY ARE STILL IN THE ARRAY
// SO WE WILL NOT INPUT THE AGAIN
temp="LISTING of NAMES in reverse ORDER\n";
for(a=4;a>=0;a--)
{
temp=temp+new_names[a]+"\n";
}
JOptionPane.showMessageDialog(null,temp);
// NOW WE WILL CONCATENATE THEM TO A STRING SUCH THAT WHEN PRINTED
// THE OUTPUT WILL BE FIRST LAST, SECOND NEXT TO LAST,etc.
// SIDE BY SIDE
temp="LISTING of NAMES regular and reverse ORDER\n";
for(a=0;a<=4;a++)
{
temp=temp+new_names[a]+" "+new_names[4-a]+"\n";
}
JOptionPane.showMessageDialog(null,temp);
// and LAST WE WILL INPUT 3 full names, CONCATENATE ONLY THE LAST
// half of each name to a string and print it all on one line
// --NOT USING ARRAYS THIS TIME
temp_out="";
for(a=0;a<=2;a++)
{
temp_name=JOptionPane.showInputDialog("Enter name FIRST LAST ?");
pos_blank=temp_name.indexOf(" ",0);
how_long=temp_name.length();
last_name=temp_name.substring(pos_blank+1,how_long);
temp_out+=last_name+" --- ";
}
JOptionPane.showMessageDialog(null,temp_out);
// FINALLY INPUT A STUDENT'S AVERAGE, ROUND IT, MAKE IT INTEGER,
// AND PRINT IT
temp_average=JOptionPane.showInputDialog("Enter average ?");
average=Float.parseFloat(temp_average);
adj_average=average + 0.5f;
final_average=(int)adj_average;
temp="original average "+average+"\n";
temp+="Adjusted average "+adj_average+"\n";
temp+="Rounder average "+final_average+"\n";
JOptionPane.showMessageDialog(null,temp);
System.exit(0);
}
}