Question

In: Computer Science

create a public class and a main class to deletebyStudentID number with get ID and getStudentByName...

create a public class and a main class to deletebyStudentID number with get ID and getStudentByName in public class. when the user is prompted to search for the student and delete them by their. ID has seven digits and 6 students each.
Ex. Delete student by their ID
        Enter students name and their ID
        Vanessa,
        1111-111
        Vanessa is now deleted

Solutions

Expert Solution

Solution :

Steps :

1.Create Model class for student with name and id in it

2.Make getter and setter for studentId and studentName;

3 .In main class declare arraylist for student class and add them in student arraylist.

4.ask user for name and id.

5 . use if loop for matching the student details.

Java Class for Student :


public class Students
{

/* public constructor for Student */
public Students (String studentId, String studentName)
{
this.studentId = studentId;
this.studentName = studentName;
}

/* getter and setter for student */
public String getStudentId ()
{
return studentId;
}

public String getStudentName ()
{
return studentName;
}

/* declaring the private variable for student name and student id*/
private String studentId;
private String studentName;
}

Main Class :


import java.util.ArrayList;
import java.util.Scanner;

/* creating main class*/
public class Main
{
public static void main (String[]args)
{
/* declaring the student arraylist for storing the student data */
ArrayList < Students > students = new ArrayList <> ();
/* adding student data in the form of student object */
Students s = new Students ("11", "Student1");
Students s1 = new Students ("1111-111", "Vanessa");
Students s2 = new Students ("111", "Student2");
Students s3 = new Students ("1111", "Student3");
Students s4 = new Students ("11111", "Student4");
/* adding student data in thr arraylist */
students.add (s);
students.add (s1);
students.add (s2);
students.add (s3);
students.add (s4);
System.out.println ("Enter students name and their ID");
Scanner sc = new Scanner (System.in);
/* taking input from the user to delete the student details */
String name = sc.nextLine ();
String id = sc.nextLine ();
/* using the temporary variable for checking that record is deleted or not */
int temp = 0;
for (int i = 0; i < students.size (); i++)
{
   /* checking that details is matched with the inserted student details */
   if (students.get (i).getStudentId ().equals (id)
   && students.get (i).getStudentName ().equals (name))
   {
   /* if found simply remove the student data from arraylist */
   students.remove (i);
   System.out.println (name + " is now deleted");
   //changing the temporary varianble value
   temp = 1;
   break;
   }
}
/* if no student is found with that name and id */
if (temp == 0)
System.out.println ("NO record found");


}
}

Code ScreenShot :

Output ScreenShots :


Related Solutions

Question 1 - Create a class named Student that has fields for an ID number, number...
Question 1 - Create a class named Student that has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method to compute the grade point...
Create a class named Student. Student has fields for an ID number, number of credit hours...
Create a class named Student. Student has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. Student also has a field for grade point average. Include a method to compute the grade point average field by dividing...
public class GreeterTest {    public static void main(String[] args)    { // create an object...
public class GreeterTest {    public static void main(String[] args)    { // create an object for Greeter class Greeter greeter = new Greeter("Jack"); // create two variables Greeter var1 = greeter; Greeter var2 = greeter; // call the sayHello method on the first Greeter variable String res1 = var1.sayHello(); System.out.println("The first reference " + res1); // Call the setName method on the secod Grreter variable var2.setName("Mike"); String res2 = var2.sayHello(); System.out.println("The second reference " + res2);    } }...
Create an Automobile class for a dealership. Include fields for an ID number, make, model, color,...
Create an Automobile class for a dealership. Include fields for an ID number, make, model, color, year, vin number, miles per gallon, and speed. Include get and set methods for each field. Do not allow the ID to be negative or more than 9999; if it is, set the ID to 0. Do not allow the year to be earlier than 2000 or later than 2017; if it is, set the year to 0. Do not allow the miles per...
Create a class named Salesperson. Data fields for Salesperson include an integer ID number and a...
Create a class named Salesperson. Data fields for Salesperson include an integer ID number and a doubleannual sales amount. Methods include a constructor that requires values for both data fields, as well as get and set methods for each of the data fields. Write an application named DemoSalesperson that declares an array of 10 Salesperson objects. Set each ID number to 9999 and each sales value to zero. Display the 10 Salesperson objects. public class DemoSalesperson { public static void...
Create a new Java file, containing this code public class DataStatsUser { public static void main...
Create a new Java file, containing this code public class DataStatsUser { public static void main (String[] args) { DataStats d = new DataStats(6); d.append(1.1); d.append(2.1); d.append(3.1); System.out.println("final so far is: " + d.mean()); d.append(4.1); d.append(5.1); d.append(6.1); System.out.println("final mean is: " + d.mean()); } } This code depends on a class called DataStats, with the following API: public class DataStats { public DataStats(int N) { } // set up an array (to accept up to N doubles) and other member...
Create a PoemDriver.java class with a main method. In the main method, create an ArrayList of...
Create a PoemDriver.java class with a main method. In the main method, create an ArrayList of Poem objects, read in the information from PoemInfo.txt and create Poem objects to populate the ArrayList. After all data from the file is read in and the Poem objects added to the ArrayList- print the contents of the ArrayList. Paste your PoemDriver.java text (CtrlC to copy, CtrlV to paste) into the open space before. You should not change Poem.java or PoemInfo.txt. Watch your time...
For Java Let's get some practice with maps! Create a public class CountLetters providing a single...
For Java Let's get some practice with maps! Create a public class CountLetters providing a single static method countLetters. countLetters accepts an array of Strings and returns a Map from Strings to Integers. (You can reject null arguments using assert.) The map should contain counts of the passed Strings based on their first letter. For example, provided the array {"test", "me", "testing"} your Map should be {"t": 2, "m": 1}. You should ignore empty Strings and not include any zero...
Create a class called employee which has the following instance variables: Employee ID number Salary Years...
Create a class called employee which has the following instance variables: Employee ID number Salary Years at the company Your class should have the following methods: New employee which reads in an employee’s ID number, salary and years of service Anniversary which will up the years of service by 1 You got a raise which will read in how much the raise was (a percent) and then calculate the new salary You get a bonus which gives a yearly bonus...
Let's get some practice with maps! Create a public class CountLetters providing a single static method...
Let's get some practice with maps! Create a public class CountLetters providing a single static method countLetters. countLetters accepts an array of Strings and returns a Map from Strings to Integers. (You can reject null arguments using assert.) The map should contain counts of the passed Strings based on their first letter. For example, provided the array {"test", "me", "testing"} your Map should be {"t": 2, "m": 1}. You should ignore empty Strings and not include any zero counts. As...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT