Question

In: Computer Science

///create a main menu to enter choices such as "Welcome to any college" then please enter...

///create a main menu to enter choices such as "Welcome to any college" then please enter your choice of information when you press a key 1. view students. 2. insert student 3. remove student 4. exit...and student ID#, age, birthday, location, expected gradation date

import java.util.Scanner;

public class CourseCOM666 {
private String courseName;
private String [] students = new String[1];
private int numberOfStudents;

public CourseCOM666(String courseName) {
this.courseName = courseName;
}
public String[] getStudents(){
return students;
}
public int getNumberOfStudents(){
return numberOfStudents;
}
public String getCourseName(){
return courseName;
}

public void addStudent(String student) {
// Automatically increases the array size
if (numberOfStudents == students.length) {
String[] a = new String[students.length + 1];
for (int i = 0; i < numberOfStudents; i++) {
a[i] = students[i];
}
students = a;
}
students[numberOfStudents] = student;
numberOfStudents++;
}
public String[] addStudentByIndex(String student,int index){
String [] a = new String[students.length+1];
if (numberOfStudents == students.length){

for (int i = 0; i < a.length;i++){
if(i < index){
a[i] = students[i];
}
else if (i == index ){
a[i] = student;
}
else{
a[i] = students[i-1];
}}
}
numberOfStudents++;
return a;

}
public static void display(String[]students){
System.out.println("========================");
System.out.print("Now the New students Array is :\n");
for(int i=0; i<students.length; i++)
{
System.out.println("Index: "+(i)+"--> "+ students[i]+" ");
}
}



public String [] removeStudentByIndex(String [] a,int index){
//find the index of student
String [] b = new String[a.length-1];
students = a;
// int position = findStudent(student);
for (int i = 0,k=0; i < a.length;i++){
if (i == index){
continue;
}
else{
b[k++] = a[i];
}
}
numberOfStudents--;


return b;

}
private int findStudent(String student) {
for (int i = 0; i < numberOfStudents; i++) {
if (students[i].equals(student)) {
return i;
}
}
return -1;
}



}
import java.util.Scanner;

public class d {
public static void main(String [] args){
CourseCOM666 com666 = new CourseCOM666("com666");
com666.addStudent("hank");
com666.addStudent("paul");
com666.addStudent("david");
com666.addStudent("ben");
com666.addStudent("jacob");

int sum = 0;
////////create a new array String students1[] to hold all students/////////////////////
String students1[] = com666.getStudents();

sum += com666.getNumberOfStudents();
for(int i =0; i<students1.length; i++) {
System.out.println("Index is: "+(i)+ " --> "+students1[i]);
}

System.out.println("Number of students attending the Course is: " + sum);

Scanner scan = new Scanner(System.in);
System.out.println("Enter the name of student and index:");
String student = scan.nextLine();
students1 = com666.addStudentByIndex(student,3);
com666.display(students1);

sum = com666.getNumberOfStudents();
System.out.println("After student was added the Student number is:" + sum);


System.out.println("remove student by index");
int index = scan.nextInt();
students1=com666.removeStudentByIndex(students1,index);
com666.display(students1);
sum = com666.getNumberOfStudents();
System.out.println("After student drop number is:" + sum);
System.out.println("Number of students attending the Course is: " + sum);
System.out.println("----------------------------");

//use do while loops

Solutions

Expert Solution

import java.util.Scanner;

class CourseCOM666 {
        private String courseName;
        private String [] students = new String[1];
        private int numberOfStudents;
        
        public CourseCOM666(String courseName) {
                this.courseName = courseName;
        }
        public String[] getStudents(){
                return students;
        }
        public int getNumberOfStudents(){
                return numberOfStudents;
        }
        public String getCourseName(){
                return courseName;
        }
        
        public void addStudent(String student) {
                // Automatically increases the array size
                if (numberOfStudents == students.length) {
                String[] a = new String[students.length + 1];
                for (int i = 0; i < numberOfStudents; i++) {
                        a[i] = students[i];
                }
                students = a;
                }
                students[numberOfStudents] = student;
                numberOfStudents++;
        }
        public String[] addStudentByIndex(String student,int index){
                String [] a = new String[students.length+1];
                if (numberOfStudents == students.length){
                        
                        for (int i = 0; i < a.length;i++){
                                if(i < index){
                                        a[i] = students[i];
                                }
                                else if (i == index ){
                                        a[i] = student;
                                }
                        else{
                                a[i] = students[i-1];
                                }
                        }
                }
                numberOfStudents++;
                return a;
        
        }
        public static void display(String[]students){
                System.out.println("========================");
                System.out.print("Now the New students Array is :\n");
                for(int i=0; i<students.length; i++)
                {
                        System.out.println("Index: "+(i)+"--> "+ students[i]+" ");
                }
        }
        
        
        
        public String [] removeStudentByIndex(String [] a,int index){
        //find the index of student
        String [] b = new String[a.length-1];
        students = a;
        // int position = findStudent(student);
        for (int i = 0,k=0; i < a.length;i++){
                if (i == index){
                        continue;
                }
                else{
                        b[k++] = a[i];
                }
        }
        numberOfStudents--;
        
        
        return b;
        
        }
        private int findStudent(String student) {
                for (int i = 0; i < numberOfStudents; i++) {
                        if (students[i].equals(student)) {
                                return i;
                        }
                }
                return -1;
        }
        


}

public class d {
        public static void main(String [] args){
                
                CourseCOM666 com666 = new CourseCOM666("com666");
                com666.addStudent("hank");
                com666.addStudent("paul");
                com666.addStudent("david");
                com666.addStudent("ben");
                com666.addStudent("jacob");
                
                int sum = 0;
                ////////create a new array String students1[] to hold all students/////////////////////
                String students1[] = com666.getStudents();
                
                sum += com666.getNumberOfStudents();
                
                Scanner scan = new Scanner(System.in);
                
                
                
                
                
                //use do while loops
                int choice;
                
                do {
                        System.out.println("Welcome to any college");
                        System.out.println("1. View Student");
                        System.out.println("2. insert student");
                        System.out.println("3. remove student");
                        System.out.println("4. exit");
                        choice = scan.nextInt();
                        if(choice==1) {
                                for(int i =0; i<students1.length; i++) {
                                        System.out.println("Index is: "+(i)+ " --> "+students1[i]);
                                }
                                System.out.println("Number of students attending the Course is: " + sum);
                        }
                        else if(choice == 2) {
                                System.out.println("Enter the name of student and index:");
                                scan.nextLine();
                                String student = scan.nextLine();
                                students1 = com666.addStudentByIndex(student,3);
                                com666.display(students1);
                                
                                sum = com666.getNumberOfStudents();
                                System.out.println("After student was added the Student number is:" + sum);
                        }
                        else if(choice == 3) {
                                System.out.println("remove student by index");
                                int index = scan.nextInt();
                                students1=com666.removeStudentByIndex(students1,index);
                                com666.display(students1);
                                sum = com666.getNumberOfStudents();
                                System.out.println("After student drop number is:" + sum);
                                System.out.println("Number of students attending the Course is: " + sum);
                                System.out.println("----------------------------");
                        }
                }while(choice!= 4);
                
        }
}

Related Solutions

(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main()...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main() function to coordinate the execution of the program. We will need methods: Method for Depositing values into the account. What type of method will it be? Method for Withdrawing values from the account. What type of method will it be? Method to output the balance of the account. What type of method will it be? Method that will output all deposits made to the...
Make a menu for a restaurant using python. Make sure there are choices on the menu....
Make a menu for a restaurant using python. Make sure there are choices on the menu. Give me a little description of how you did it.
Java Programing Display any welcome message at the top of the output screen Create following variables:...
Java Programing Display any welcome message at the top of the output screen Create following variables: Price for a cup of coffee (make it adjustable within the program) Number of cups (response from User) Tax Rate in San Diego is 8%. Define 8% as a CONSTANT variable that never changes Payment Method (Cash, Credit Card, Store Credit, Gold) Ask the customer for their first name, and store it as a String object. Ask the customer (by name) how many cups...
Can you please write a pseudocode for the following: #include <stdio.h> int main(){    printf("Welcome to...
Can you please write a pseudocode for the following: #include <stdio.h> int main(){    printf("Welcome to my Command-Line Calculator (CLC)\n");    printf("Developer: Your name will come here\n");    printf("Version: 1\n");    printf("Date: Development data Will come here\n");    printf("----------------------------------------------------------\n\n");    //choice stores users input    char choice;    //to store numbers    int val1,val2;    //to store operator    char operation;    //flag which leths the loop iterate    //the loop will break once the flag is set to 0...
You must prompt the user to enter a menu selection. The menu will have the following...
You must prompt the user to enter a menu selection. The menu will have the following selections (NOTE: all menu selections by the user should not be case sensitive): 1. ‘L’ – Length a. Assume that a file containing a series of names is called names.txt and exists on the computer’s disk. Read that file and display the length of each name in the file to the screen. Each name’s middle character or characters should be displayed on a line...
Create a menu in Java. A menu is a presentation of options for you to select....
Create a menu in Java. A menu is a presentation of options for you to select. You can do this in the main() method. 1. Create a String variable named menuChoice. 2. Display 3 options for your program. I recommend using 3 System.out.println statements and a 4th System.out.print to show "Enter your Selection:". This needs to be inside the do -- while loop. A. Buy Stock. B. Sell Stock X. Exit Enter your Selection: 3. Prompt for the value menuChoice....
Write a program names EncryptDecrypt.java that has the following menu choices: Print menu and allow user...
Write a program names EncryptDecrypt.java that has the following menu choices: Print menu and allow user to choose options. The program must have a file dialogue box for text file. Output should be based on user choices. Read in a file Print the file to the console Encrypt the file and write it to the console Write out the encrypted file to a text file Clear the data in memory Read in an encrypted file Decrypt the file Write out...
Class, Let's create a menu in Java. A menu is a presentation of options for you...
Class, Let's create a menu in Java. A menu is a presentation of options for you to select. You can do this in the main() method. 1. Create a String variable named menuChoice. 2. Display 3 options for your program. I recommend using 3 System.out.println statements and a 4th System.out.print to show "Enter your Selection:". This needs to be inside the do -- while loop. A. Deposit Cash. B. Withdraw Cash X. Exit Enter your Selection: 3. Prompt for the...
Create a welcome website in html/css for the fictional college elliott university, this website will consist of at least 4 in-page-content-blocks
Create a welcome website in html/css for the fictional college elliott university, this website will consist of at least 4 in-page-content-blocksElliott university welcome block :2-3 pictures with bordersThree paragraphs describing a student experience the collegeAppropriate for the contentGallery page block:Consisting of 8 to 10 imagesFormatted for best loading on the web across all devicesText paragraph under each imageRemaining Two blocks can reflect content that you choose:Consisting of 3 paragraphs of text per blockConsisting of at least one image per blockLook...
Please C++ create a program that will do one of two functions using a menu, like...
Please C++ create a program that will do one of two functions using a menu, like so: 1. Do Catalan numbers 2. Do Fibonacci numbers (recursive) 0. Quit Enter selection: 1 Enter Catalan number to calculate: 3 Catalan number at 3 is 5 1. Do Catalan numbers 2. Do Fibonacci numbers (recursive) 0. Quit Enter selection: 2 Enter Fibonacci number to calculate: 6 Fibonacci number 6 is 8 Create a function of catalan that will take a parameter and return...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT