- Create a text file named “IS study plan.txt” using Word or Notepad to include
ID: 3691306 • Letter: #
Question
- Create a text file named “IS study plan.txt” using Word or Notepad to include the following data:
MGT201 Principles of Management
MATH206 Selected Topics in Mathematics MATH203
CS112 Programming CS111
IS 102 Information Systems
ENG104 Technical CommunicationENG 103
CS211 Algorithms and Data Structures CS112
IS203 Information Technology Infrastructure IS102
IS251 Database Management Systems CS211, CS103
GS112 Arabic Language Skills GS111
ENG214 Technical Writing ENG104
IS242 Web Application Development1 IS251
IS244 Information Systems Analysis and Design IS251
- Create a super class named Students that includes the following:
Data fields: name, student number, email, and mobile number. All data fields are of string type. Student name and number are private data fields
Two constructors: the first constructor with no-arg, and the second constructor with the above-mentioned arguments
A method that appends the details of a new student including: name, student number, email, and mobile number.
A method that searches for the contact details of a student by his student number and then prints his name, email, and mobile number. The method has try-catch block for verifying the student number to be of 7 digits.
- Create a subclass that extends the Students class and includes the following:
Data fields: specialization (CS/IS), and semester serial number. Specialization of string type and semester serial number is of integer type. Both fields are of public type
Two constructors: the first with no-arg and the second constructor with both specialization (CS/IS), and semester serial number
A method that reads data from a text file “IS study plan.txt” and then stores data in ArrayList named “ISStudyPlan”.
A method that has three arguments: student number, specialization, and semester. The method has a try-catch block for verifying if the semester is between 1 and 10 only. It displays an error message if the entry is not within the range. The method then searches the ArrayList for the subjects in which the student should enroll for a given semester. It then prints student name, student number, and subjects for a semester. Print data with left alignment.The student is scheduled to do four subject per semester. Referring to “IS study plan.txt” file the first four subjects are for semester 1, the second four subjects are for semester 2, and the third four subjects are for semester 3.
A method that searches the ArrayList for a specific subject name and prints its full details as follows.
Subject code subject name subject prerequisite
Explanation / Answer
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package test;
/**
*
* @author Shivakumar
*/
public class Students { // Base class students
private String name; // private fields
private String number; // name and number
String email;
String mNumber; // other fields
public Students() // constructor with no argumetns
{
}
public Students(String name,String number,String email,String mNumber) // construcor to initialize the above //fields
{
this.email=email;
this.mNumber=mNumber;
this.name=name;
this.number=number; // this is the object of current class
}
public void append() // append method to append the data
{
String ap;
ap=name+" "+number+" "+email+" "+mNumber;
System.out.println(ap);
}
public String searh(String number)
{
char[] arr=number.toCharArray(); // converting string to char array to check the numbers
try
{
if(arr.length>7 || arr.length<7)
{
arr[12]='c'; // exeption occurs so leaves try block
}
System.out.println(name+" "+number+" "+email+" "+mNumber); // otherwise prints results
}
catch(Exception e) // catch for try
{
System.out.println("Number should be 7 digits");
}
return name;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package test;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner; // importing the required files
/**
*
* @author Shivakumar
*/
public class Test extends Students { // Test class extends Students
public String spec;
public int semNo;
Scanner s;
ArrayList<String> ISStudyplan=new ArrayList<String>(); // array list creation
public Test() // no arguments constructor
{
}
public Test(String spec,int semNo) // constructor with arguments
{
this.semNo=semNo;
this.spec=spec;
}
public void read() throws FileNotFoundException // read method with file not found exception if method //does not find a file
{
s=new Scanner(new File("IS study plan.txt")); // initializing scanner object
while(s.hasNext()) // loading file data into arraylislt
{
ISStudyplan.add(s.next()); // adding String object ot the array lislt
}
}
public void searchS(String number,String spec,int semNo) // method to search and print
{
try // try block for sem no in range 1 to 10
{
if(semNo==1) // printing for different semesters
{
System.out.println(super.searh(number)+" "+number+" "+ISStudyplan.get(0));
System.out.println(super.searh(number)+" "+number+" "+ISStudyplan.get(1));
System.out.println(super.searh(number)+" "+number+" "+ISStudyplan.get(2));
System.out.println(super.searh(number)+" "+number+" "+ISStudyplan.get(3));
}
else if(semNo==2)
{
System.out.println(super.searh(number)+" "+number+" "+ISStudyplan.get(4));
System.out.println(super.searh(number)+" "+number+" "+ISStudyplan.get(5));
System.out.println(super.searh(number)+" "+number+" "+ISStudyplan.get(6));
System.out.println(super.searh(number)+" "+number+" "+ISStudyplan.get(7));
}
else
{
System.out.println(super.searh(number)+" "+number+" "+ISStudyplan.get(8));
System.out.println(super.searh(number)+" "+number+" "+ISStudyplan.get(9));
System.out.println(super.searh(number)+" "+number+" "+ISStudyplan.get(10));
System.out.println(super.searh(number)+" "+number+" "+ISStudyplan.get(11));
}
}
catch(Exception e) // catch if range does not satisfies
{
System.out.println("Error");
}
}
public void print(String subname) // printing the last subcode, sub name , sub prerequisite
{
for(int i=0;i<ISStudyplan.size();i++)
{
if(subname.matches(ISStudyplan.get(i)))
{
System.out.println(ISStudyplan.get(i));
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException { // main starts here
// TODO code application logic here
Students std1=new Students("Smith","1236548","smith@sample.com","52214-562"); // object creation
Students std2=new Students("adele","5214638","adele@yahoo.com","362-562");
Test t1=new Test("CS",1);
Test t2=new Test("IS",3);
t1.append();
t1.read();
t1.searh("1236548");
t1.searchS("1236548", "CS", 3);
t1.print("alogorithms");
t2.append();
t2.read();
t2.searh("1236548");
t2.searchS("1236548", "CS", 3);
t2.print("English");
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.