Purchase Solution

Write an application that stores at least four different course names and meeting days and times in a two-dimensional string array. Allow the user to enter a course name (such as CIS 110) and display the day of the week and times that the course is held (such as Th 330). If the course does not exist, display an error message.

Not what you're looking for?

Ask Custom Question

The application as written does not display certain class names included in the instructions as written.

Write an application that stores at least four different course names and meeting days and times in a two-dimensional string array. Allow the user to enter a course name (such as CIS 110) and display the day of the week and times that the course is held (such as Th 330). If the course does not exist, display an error message.

import javax.swing.JOptionPane;
import java.util.Scanner;

public class Schedule {
public static void main(String[] args) {
//declare variables and arrays
final int NUM_RANGES = 4;
int sub = NUM_RANGES - 1;

String[][] classNames = {
{"COM 209", "MAT 201", "MAT 141", "ENG 220"},
{"Mon 1:00","Tue 8:30","Thu 7:30","Fri 9:15",}
};

//get input
String classInput = JOptionPane.showInputDialog("Please input a class name: ");

//match to output and print
while(sub >= 0)
--sub;

if (classInput.equals(classNames[0])) {
JOptionPane.showMessageDialog(null, "Class time is: " + classNames[0][0]);
System.exit(0);
}
else if (classInput.equals("COM 209")) {
JOptionPane.showMessageDialog(null, "Class time is: " + classNames[1][1]);
System.exit(0);
}
else if (classInput.equals("MAT 201")) {
JOptionPane.showMessageDialog(null, "Class time is: " + classNames[2][2]);
System.exit(0);
}
else if (classInput.equals("MAT 141")) {
JOptionPane.showMessageDialog(null, "Class time is: " + classNames[3][3]);
System.exit(0);
}
else if (classInput.equals("ENG 220")) {
JOptionPane.showMessageDialog(null, "Class time is: " + classNames[4][4]);
System.exit(0);
}

else {
JOptionPane.showMessageDialog(null, "Please enter a valid class name.");
System.exit(0);
}
}
}

Purchase this Solution

Solution Summary

The expert writes an application that stores at least four different course names.

Solution Preview

This solution deals with both initializing and accessing 2 dimensional
arrays in Java. The first key point is how the arrays are
initialized. Consider this form:

<pre>
String [][] arr1 = {{"a","b"c"},
{"1","2","3"}};
</pre>

This creates an array variable, arr1, that has two rows and three
columns. This means that all of the valid index values are
arr1[0][0] (first row, first column) through arr1[1][2] (second row
third column. Another form with the same data is:

<pre>
String [][] arr2 = {{"a","1"},
{"b","2"},
{"c","3"}};
</pre>

This creates an array variable, arr2, that has three rows and two
columns. The valid indeces here are arr2[0][0] through ...

Purchase this Solution


Free BrainMass Quizzes
C# variables and classes

This quiz contains questions about C# classes and variables.

Javscript Basics

Quiz on basics of javascript programming language.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.