Results 1 to 1 of 1
Thread: Array for time table
- 03-06-2010, 03:47 PM #1
Member
- Join Date
- Jan 2010
- Posts
- 7
- Rep Power
- 0
Array for time table
[code]
import static javax.swing.JOptionPane.*;
public class TTable {
String timeTable[][][] = new String[7][8][2];
String day_name[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
String time_name[] = {"8am", "9am", "10am", "11am", "12pm", "1pm", "2pm", "3pm"};
String name = "a";
public int new_tt(){
String temp = "a";
for(int day=0; day<=6; day++){
for(int time=0; time<=7; time++){
temp = showInputDialog("Type 0 to finish \n Subject Code for "+day_name[day] +" "+ time_name[time]);
if( temp.equals("0")){
return 0;
}
timeTable[day][time][0] = temp;
temp = showInputDialog("Type 0 to finsih \n Venue for " + day_name[day] + " " + time_name[time]);
if( temp.equals("0")){
return 0;
}
timeTable[day][time][1] = temp;
}
}
showMessageDialog(null,"New Time Table Created");
return 1;
}
public void edit(String day,String time){
boolean found = false, found1 = false;
int loc = -1, loc1 = -1;
for(int i=0; i<=6; i++) {
if (day_name[i].equals(day)) {
found = true;
loc = i;
}
}
for(int j=0; j<=7; j++){
if (time_name[j].equals(time)) {
found1 = true;
loc1 = j;
}
}
timeTable[loc][loc1][0] = showInputDialog("Subject Code for "+day_name[loc] +" "+ time_name[loc1]);
timeTable[loc][loc1][1] = showInputDialog("Venue for "+day_name[loc] +" "+ time_name[loc1]);
}
public void delete(String day, String time) {
boolean found = false, found1 = false;
int loc = -1, loc1 = -1;
for(int i=0; i<=6; i++) {
if (day_name[i].equals(day)) {
found = true;
loc = i;
}
}
for(int j=0; j<=7; j++){
if (time_name[j].equals(time)) {
found1 = true;
loc1 = j;
}
}
showMessageDialog(null, "Subject Code and Venue for "+ day_name[loc] + " " + time_name[loc1] + " is deleted.");
timeTable[loc][loc1][0] = "";
timeTable[loc][loc1][1] = "";
}
public void display_tt(){
/* //Print day
String output = " \t";
boolean first_block = true;
//print days
for(int day=0; day<=6; day++){
output = output + day_name[day] + " \t";
}
output = output + "\n";
for(int time=0; time<=7; time++){
first_block = true;
for(int day=0; day<=6; day++){
if (first_block == true){
output = output + time_name[time] + " \t";
first_block = false;
}
output = output + timeTable[day][time][0] + "\t";
}
output = output + "\n";
first_block = true;
for(int day=0; day<=6; day++){
if (first_block == true){
output = output + " \t";
first_block = false;
}
output = output + timeTable[day][time][1] + " \t";
}
output = output + "\n";
}
showMessageDialog(null,output);
}*/
String name = showInputDialog("Whose time table is this?");
for( int i = 0; i < time_name.length; i++) {
System.out.println("\n"+ time_name[i]);
}
//System.out.println("\t" +
System.out.print("\t" + timeTable[0][0][0]+ timeTable[1][0][0]+timeTable[2][0][0]+timeTable[3][0][0]+timeTable[4][0][0]+timeTable[5][0][0]+timeTable[6][0][0]+ "\n");
System.out.print("\t" + timeTable[0][0][1]+ timeTable[1][0][1]+timeTable[2][0][1]+timeTable[3][0][1]+timeTable[4][0][1]+timeTable[5][0][1]+timeTable[6][0][1]+ "\n");
System.out.print("\t" + timeTable[0][1][0]+ timeTable[1][1][0]+timeTable[2][1][0]+timeTable[3][1][0]+timeTable[4][1][0]+timeTable[5][1][0]+timeTable[6][1][0]+ "\n");
System.out.print("\t" + timeTable[0][1][1]+ timeTable[1][1][1]+timeTable[2][1][1]+timeTable[3][1][1]+timeTable[4][1][1]+timeTable[5][1][1]+timeTable[6][1][1]+ "\n");
System.out.print("\t" + timeTable[0][2][0]+ timeTable[1][2][0]+timeTable[2][2][0]+timeTable[3][2][0]+timeTable[4][2][0]+timeTable[5][2][0]+timeTable[6][2][0]+ "\n");
System.out.print("\t" + timeTable[0][2][1]+ timeTable[1][2][1]+timeTable[2][2][1]+timeTable[3][2][1]+timeTable[4][2][1]+timeTable[5][2][1]+timeTable[6][2][1]+ "\n");
System.out.print("\t" + timeTable[0][3][0]+ timeTable[1][3][0]+timeTable[2][3][0]+timeTable[3][3][0]+timeTable[4][3][0]+timeTable[5][3][0]+timeTable[6][3][0]+ "\n");
System.out.print("\t" + timeTable[0][3][1]+ timeTable[1][3][1]+timeTable[2][3][1]+timeTable[3][3][1]+timeTable[4][3][1]+timeTable[5][3][1]+timeTable[6][3][1]+ "\n");
System.out.print("\t" + timeTable[0][4][0]+ timeTable[1][4][0]+timeTable[2][4][0]+timeTable[3][4][0]+timeTable[4][4][0]+timeTable[5][4][0]+timeTable[6][4][0]+ "\n");
System.out.print("\t" + timeTable[0][4][1]+ timeTable[1][4][1]+timeTable[2][4][1]+timeTable[3][4][1]+timeTable[4][4][1]+timeTable[5][4][1]+timeTable[6][4][1]+ "\n");
System.out.print("\t" + timeTable[0][5][0]+ timeTable[1][5][0]+timeTable[2][5][0]+timeTable[3][5][0]+timeTable[4][5][0]+timeTable[5][5][0]+timeTable[6][5][0]+ "\n");
System.out.print("\t" + timeTable[0][5][1]+ timeTable[1][5][1]+timeTable[2][5][1]+timeTable[3][5][1]+timeTable[4][5][1]+timeTable[5][5][1]+timeTable[6][5][1]+ "\n");
System.out.print("\t" + timeTable[0][6][0]+ timeTable[1][6][0]+timeTable[2][6][0]+timeTable[3][6][0]+timeTable[4][6][0]+timeTable[5][6][0]+timeTable[6][6][0]+ "\n");
System.out.print("\t" + timeTable[0][6][1]+ timeTable[1][6][1]+timeTable[2][6][1]+timeTable[3][6][1]+timeTable[4][6][1]+timeTable[5][6][1]+timeTable[6][6][1]+ "\n");
System.out.print("\t" + timeTable[0][7][0]+ timeTable[1][7][0]+timeTable[2][7][0]+timeTable[3][7][0]+timeTable[4][7][0]+timeTable[5][7][0]+timeTable[6][7][0]+ "\n");
System.out.print("\t" + timeTable[0][7][1]+ timeTable[1][7][1]+timeTable[2][7][1]+timeTable[3][7][1]+timeTable[4][7][1]+timeTable[5][7][1]+timeTable[6][7][1]+ "\n");
}
}
[\code]
[code]
import static javax.swing.JOptionPane.*;
public class Test1 {
static TTable tt = new TTable();
public static void main(String args[]) {
int choice = -1;
int number = -1;
do {
number = Integer.parseInt(showInputDialog("Enter your choice of time table"));
switch(number) {
case 1 :
do {
choice = Integer.parseInt(showInputDialog(
"Enter the choice"));
switch(choice) {
case 1 :
//new
tt.new_tt();
break;
case 2 :
tt.edit(showInputDialog(
"Enter the day"),showInputDialog(
"Enter the time"));
//edit
break;
case 3 :
tt.delete(showInputDialog(
"Enter the day"),showInputDialog(
"Enter the time"));
break;
case 4 :
tt.display_tt();
break;
}
}while(choice!=0);
break;
case 2 :
do {
choice = Integer.parseInt(showInputDialog(
"Enter the choice"));
switch(choice) {
case 1 :
//new
tt.new_tt();
break;
case 2 :
tt.edit(showInputDialog(
"Enter the day"),showInputDialog(
"Enter the time"));
//edit
break;
case 3 :
tt.delete(showInputDialog(
"Enter the day"),showInputDialog(
"Enter the time"));
break;
case 4 :
tt.display_tt();
break;
}
}while(choice!=0);
break;
case 3 :
do {
choice = Integer.parseInt(showInputDialog(
"Enter the choice"));
switch(choice) {
case 1 :
//new
tt.new_tt();
break;
case 2 :
tt.edit(showInputDialog(
"Enter the day"),showInputDialog(
"Enter the time"));
//edit
break;
case 3 :
tt.delete(showInputDialog(
"Enter the day"),showInputDialog(
"Enter the time"));
break;
case 4 :
tt.display_tt();
break;
}
}while(choice!=0);
break;
case 4 :
do {
choice = Integer.parseInt(showInputDialog(
"Enter the choice"));
switch(choice) {
case 1 :
//new
tt.new_tt();
break;
case 2 :
tt.edit(showInputDialog(
"Enter the day"),showInputDialog(
"Enter the time"));
//edit
break;
case 3 :
tt.delete(showInputDialog(
"Enter the day"),showInputDialog(
"Enter the time"));
break;
case 4 :
tt.display_tt();
break;
}
}while(choice!=0);
break;
case 5 :
do {
choice = Integer.parseInt(showInputDialog(
"Enter the choice"));
switch(choice) {
case 1 :
//new
tt.new_tt();
break;
case 2 :
tt.edit(showInputDialog(
"Enter the day"),showInputDialog(
"Enter the time"));
//edit
break;
case 3 :
tt.delete(showInputDialog(
"Enter the day"),showInputDialog(
"Enter the time"));
break;
case 4 :
tt.display_tt();
break;
}
}while(choice!=0);
break;
case 6 :
do {
choice = Integer.parseInt(showInputDialog(
"Enter the choice"));
switch(choice) {
case 1 :
//new
tt.new_tt();
break;
case 2 :
tt.edit(showInputDialog(
"Enter the day"),showInputDialog(
"Enter the time"));
//edit
break;
case 3 :
tt.delete(showInputDialog(
"Enter the day"),showInputDialog(
"Enter the time"));
break;
case 4 :
tt.display_tt();
break;
}
}while(choice!=0);
break;
case 7 :
do {
choice = Integer.parseInt(showInputDialog(
"Enter the choice"));
switch(choice) {
case 1 :
//new
tt.new_tt();
break;
case 2 :
tt.edit(showInputDialog(
"Enter the day"),showInputDialog(
"Enter the time"));
//edit
break;
case 3 :
tt.delete(showInputDialog(
"Enter the day"),showInputDialog(
"Enter the time"));
break;
case 4 :
tt.display_tt();
break;
}
}while(choice!=0);
break;
case 8 :
do {
choice = Integer.parseInt(showInputDialog(
"Enter the choice"));
switch(choice) {
case 1 :
//new
tt.new_tt();
break;
case 2 :
tt.edit(showInputDialog(
"Enter the day"),showInputDialog(
"Enter the time"));
//edit
break;
case 3 :
tt.delete(showInputDialog(
"Enter the day"),showInputDialog(
"Enter the time"));
break;
case 4 :
tt.display_tt();
break;
}
}while(choice!=0);
break;
case 9 :
do {
choice = Integer.parseInt(showInputDialog(
"Enter the choice"));
switch(choice) {
case 1 :
//new
tt.new_tt();
break;
case 2 :
tt.edit(showInputDialog(
"Enter the day"),showInputDialog(
"Enter the time"));
//edit
break;
case 3 :
tt.delete(showInputDialog(
"Enter the day"),showInputDialog(
"Enter the time"));
break;
case 4 :
tt.display_tt();
break;
}
}while(choice!=0);
break;
case 10 :
do {
choice = Integer.parseInt(showInputDialog(
"Enter the choice"));
switch(choice) {
case 1 :
//new
tt.new_tt();
break;
case 2 :
tt.edit(showInputDialog(
"Enter the day"),showInputDialog(
"Enter the time"));
//edit
break;
case 3 :
tt.delete(showInputDialog(
"Enter the day"),showInputDialog(
"Enter the time"));
break;
case 4 :
tt.display_tt();
break;
}
}while(choice!=0);
break;
}
}while(number!=0);
}
}
[\code]
Is my way correct? I would like to switch between the time table, but by using this way, it would work, because when I choose to print time table two, it will include time table one's information too. Can someone please teach?
My display method is not correct yet.
Your help is much appreciated.
Thank you very much.
Similar Threads
-
How to repaint.refresh the table (table model) with combo box selection envent
By man4ish in forum AWT / SwingReplies: 1Last Post: 01-08-2010, 06:19 AM -
NFL 2D array standings table
By ber1023 in forum New To JavaReplies: 5Last Post: 01-07-2010, 04:45 AM -
Drawing 3d graph from array table
By Mekonom in forum Java 2DReplies: 3Last Post: 12-26-2009, 09:42 AM -
Class Time - represents time of day
By verbazon in forum New To JavaReplies: 1Last Post: 04-13-2009, 01:06 AM -
i click on it,then first time error page comes,second time click then product page co
By 82rathi.angara in forum New To JavaReplies: 21Last Post: 08-01-2008, 11:13 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks