Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here is my assignment: 1. Declare a Vector to hold the names of courses offered

ID: 3634873 • Letter: H

Question

Here is my assignment:
1. Declare a Vector to hold the names of courses offered in the CSC department for a given semester. Example, "CSC160 Java","CSC126 Game Design", "CSC116 Logic and Design", etc.

2. Let the user do one of the following options:

1. Print back the list of courses offered along with the number of courses offered

(number of elements in Vector).

2. Lookup some courses. The user can enter something like Java and the program will print back any course that has the word Java in it (if any). You might be using some of the String methods such as the ones used in table 10-3 pg.622.

3. Add a course. The user can add a new course name to the end of the list.

4. Remove a course from the list.

Here is my code:
import java.io.*;
import java.util.*;
import java.lang.*;

public class Courses{

public static Vector<String> courses= new Vector<String>();


public static void main(String args[]) {


int input = 0;
do{

System.out.println(" type 1 to print the list of courses type 2to lookup some course " +
" type 3to add a course to the end of the list type 4 to remove a coursefrom the list type 5 to exit the program");
//System.out.print("Enter the number for the opearation you want todo: ");
try{
input = Integer.parseInt (newBufferedReader(new InputStreamReader(System.in)).readLine());
}
catch (Exception e){
e.printStackTrace();
}
//input = Integer.parseInt (new BufferedReader(newInputStreamReader(System.in)).readLine());
System.out.println();
if(input ==1)
{
int length = courses.size();
int c=0;
System.out.println("Printing the courses in the list");
while(c<length)
{
System.out.println(courses.elementAt(c));
c++;
}
System.out.println();

} //end of 1


if(input ==2)
{
String cor="";
System.out.print("Enter the word you want to look in the list:");
try{
cor = (new BufferedReader(newInputStreamReader(System.in)).readLine());
}
catch (Exception e){
e.printStackTrace();
}
System.out.println();
System.out.println();

int length = courses.size();
int c=0;
System.out.println("Looking for the courses in thelist");
while(c<length)
{
String course = courses.elementAt(c);
int j = course.indexOf(cor);
if( j != -1)
System.out.println(course);

c++;
}
System.out.println();
} ///end of 2

if(input ==3)
{
System.out.print("Enter the name of the course: ");
String cor="";
try{
cor = (new BufferedReader(newInputStreamReader(System.in)).readLine());
courses.add(cor);
}
catch (Exception e){
e.printStackTrace();
}
System.out.println();
System.out.println();

} //end of 3

if(input ==4)
{
System.out.print("Enter the name of the course: ");
String cor;
try{
cor = (new BufferedReader(newInputStreamReader(System.in)).readLine());
courses.remove(cor);
}
catch (Exception e){
e.printStackTrace();
}
System.out.println();
System.out.println();
} //end of 4

if(input ==5)
{
//System.out.println("555555555");
}
}
while(input !=5);


}

}
Here are my error messages:

Vector.java:2: 'class' or 'interface' expected
Vector v; // declare a vector object
^
Vector.java:3: 'class' or 'interface' expected
v = new Vector(); // create an empty vector object
^
Vector.java:4: 'class' or 'interface' expected
v = new Vector(5); // create a vector object with initial capacity 5
^
Vector.java:5: 'class' or 'interface' expected
v.addElement(new Integer(1)); // add first vector element
^
Vector.java:6: 'class' or 'interface' expected
v.addElement(new Float(1.9999)); // add another vector element
^
Vector.java:7: 'class' or 'interface' expected
for (int i=2; i<10; i++) {
^
Courses.java:7: cannot access Vector
bad class file: .Vector.java
file does not contain class Vector
Please remove or make sure it appears in the correct subdirectory of the classpath.
public static Vector<String> courses= new Vector<String>();
^
7 errors

Explanation / Answer

Please Rate:Thanks

import java.io.*;
import java.util.*;
import java.lang.*;

public class Courses{

public static Vector<String> courses= newVector<String>();


public static void main(String args[]) {

  
int input = 0;  
do{

System.out.println(" type 1 to print the list of courses type 2to lookup some course " +
           " type 3to add a course to the end of the list type 4 to remove a coursefrom the list type 5 to exit the program");
//System.out.print("Enter the number for the opearation you want todo: ");
try{
   input = Integer.parseInt (newBufferedReader(new InputStreamReader(System.in)).readLine());
}
catch (Exception e){
   e.printStackTrace();
}
//input = Integer.parseInt (new BufferedReader(newInputStreamReader(System.in)).readLine());
System.out.println();
if(input ==1)
{
int length = courses.size();
int c=0;
System.out.println("Printing the courses in the list");
while(c<length)
{
System.out.println(courses.elementAt(c));
c++;
}
System.out.println();

} //end of 1


if(input ==2)
{
String cor="";
System.out.print("Enter the word you want to look in the list:");
try{
cor = (new BufferedReader(newInputStreamReader(System.in)).readLine());
}
catch (Exception e){
   e.printStackTrace();
}
System.out.println();
System.out.println();

int length = courses.size();
int c=0;
System.out.println("Looking for the courses in thelist");
while(c<length)
{
String course = courses.elementAt(c);
int j = course.indexOf(cor);
if( j != -1)
System.out.println(course);

c++;
}
System.out.println();
} ///end of 2

if(input ==3)
{
System.out.print("Enter the name of the course: ");
String cor="";
try{
cor = (new BufferedReader(newInputStreamReader(System.in)).readLine());
courses.add(cor);
}
catch (Exception e){
   e.printStackTrace();
}
System.out.println();
System.out.println();

} //end of 3

if(input ==4)
{
System.out.print("Enter the name of the course: ");
String cor;
try{
cor = (new BufferedReader(newInputStreamReader(System.in)).readLine());
courses.remove(cor);
}
catch (Exception e){
   e.printStackTrace();
}
System.out.println();
System.out.println();
} //end of 4

if(input ==5)
{
//System.out.println("555555555");
}
}
while(input !=5);
          

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote