Question

I need to add a method high school student, I couldn't connect high school student to...

I need to add a method high school student, I couldn't connect high school student to student

please help!!!

package chapter.pkg9;


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

public class Main {

public static Student student;
public static ArrayList<Student> students;
public static HighSchoolStudent highStudent;
public static void main(String[] args) {

int choice;
Scanner scanner = new Scanner(System.in);

students = new ArrayList<>();
while (true) {
displayMenu();
choice = scanner.nextInt();
switch (choice) {
case 1:
addCollegeStudent();
break;
case 2:
addHighSchoolStudent();
case 3:
deleteStudent();
break;
case 4:
searchStudent();
break;
case 5:
display();
break;
case 6:
modifyStudentData();
break;
case 7:
System.exit(0);
default:
System.out.println("Invalid choice!");
break;
}
}
}

private static void modifyStudentData() {
Scanner choice = new Scanner(System.in);

System.out.println("Select the option from below");
System.out.println("1. Change student name");
System.out.println("2. Change student ID");
System.out.println("3. Change instructor name");
System.out.println("4. Change course name");

int userChoice = choice.nextInt();

switch (userChoice) {
case 1:
System.out.println("Enter new student name");
String newStudentName = choice.next();
student.setStudentName(newStudentName);
break;

case 2:
System.out.println("Enter new student ID");
int newStudentID = choice.nextInt();
student.setStudentId(newStudentID);
break;

case 3:
System.out.println("Enter new instructor name");
String newInsName = choice.next();
student.setInsName(newInsName);
break;

case 4:
System.out.println("Enter new course name");
String newCourseName = choice.next();
student.setCourseName(newCourseName);
break;
}
}

private static void modifyAgain() {
System.out.println("Do you still need to change anything else?" + "\nPress Y for yes.");
Scanner choice = new Scanner(System.in);
String userChoice = choice.next();
if (userChoice.equalsIgnoreCase("Y")) {
modifyStudentData();
}
}

public static void displayMenu() {
System.out.println("1. Add College Student");
System.out.println("2. Add High School Student");
System.out.println("3. Delete");
System.out.println("4. Search");
System.out.println("5. Display");
System.out.println("6. Modify");
System.out.println("7. Exit");
System.out.print("Enter your choice: ");
}

public static void addCollegeStudent() {
String studentName, instructorName, courseName;
int studentID;

Scanner sName = new Scanner(System.in);
System.out.println("Please enter student name here: ");
studentName = sName.nextLine();
studentName = studentName.substring(0, 1).toUpperCase() + studentName.substring(1);

Scanner sID = new Scanner(System.in);
System.out.println("Please enter student ID here: ");
studentID = sID.nextInt();

Scanner iName = new Scanner(System.in);
System.out.println("Please enter intructor name here: ");
instructorName = iName.nextLine();
instructorName = instructorName.substring(0, 1).toUpperCase() + instructorName.substring(1);
Scanner cName = new Scanner(System.in);

System.out.println("Please enter course name here: ");
courseName = cName.nextLine();
courseName = courseName.substring(0, 1).toUpperCase() + courseName.substring(1);

students.add(new Student(studentName, instructorName, studentID, courseName));
}
public static void addHighSchoolStudent() {
String studentName, instructorName, courseName, highSName, gradeL;
int studentID;

Scanner sName = new Scanner(System.in);
System.out.println("Please enter student name here: ");
studentName = sName.nextLine();
studentName = studentName.substring(0, 1).toUpperCase() + studentName.substring(1);

Scanner sID = new Scanner(System.in);
System.out.println("Please enter student ID here: ");
studentID = sID.nextInt();

Scanner iName = new Scanner(System.in);
System.out.println("Please enter intructor name here: ");
instructorName = iName.nextLine();
instructorName = instructorName.substring(0, 1).toUpperCase() + instructorName.substring(1);

Scanner cName = new Scanner(System.in);
System.out.println("Please enter course name here: ");
courseName = cName.nextLine();
courseName = courseName.substring(0, 1).toUpperCase() + courseName.substring(1);

System.out.println("Please enter High School name here: ");
highSName = highStudent.nameHS;

Scanner hName = new Scanner(System.in);
system.out.println("Please enter High School name here: ");
highSName =

students.add(new HighSchoolStudent(studentName, instructorName, studentID, courseName, highSName, gradeL));
}

public static void deleteStudent() {
int studentID;
Student del = null;
Scanner sID = new Scanner(System.in);
System.out.println("Please enter student ID to delete: ");
studentID = sID.nextInt();
for (Student s : students) {
if (s.getStudentID() == studentID) {
del = s;
break;
}
}
if (del != null)
students.remove(del);
}

public static void searchStudent() {
String studentName;
Scanner sName = new Scanner(System.in);
System.out.println("Please enter student name here: ");
studentName = sName.nextLine();
studentName = studentName.substring(0, 1).toUpperCase() + studentName.substring(1);
for (Student s : students) {
if (s.getStudentName().equals(studentName)) {
System.out.println(studentName + " found");
return;
}
}
System.out.println(studentName + " not found");
}

public static void display() {
System.out.format("|%20s|%10s|%20s|%20s|\n", "Student ", "ID","Instructor", "Course");
System.out.println("---------------------------------------------------------------------------");
for (Student s : students) {
System.out.format("|%20s|%10s|%20s|%20s|\n",s.getStudentName(), s.getStudentID(),s.getInsName(), s.getCourseName());
}
}
}

package chapter.pkg9;

public class HighSchoolStudent extends Student {
String gradeLevel, nameHS;

public HighSchoolStudent(String sName, String iName, int sID, String cName, String hName, String gradeL) {
super(sName, iName, sID, cName);
this.nameHS = hName;
this.gradeLevel = gradeL;
}


public String getHSName(){
return nameHS;
}
public String getGrade(){
return gradeLevel;
}
public void setHSName(String HSName){
this.nameHS = HSName;
}
public void setGradeLevel(String gradeLev){
this.gradeLevel = gradeLev;
}
}


package chapter.pkg9;

public class Student {

private String studentName;
private Instructor instructorName;
private Course courseName;
private int studentID;
  
public Student (String sName, String iName, int sID, String cName) {
this.studentName = sName;
this.instructorName = new Instructor(iName);
this.courseName = new Course(cName);
this.studentID = sID;
}
public String getStudentName(){
return studentName;
}
public Instructor getInsName(){
return instructorName;
}
public Course getCourseName(){
return courseName;
}
public int getStudentID(){
return studentID;
}

public void setStudentName(String name) {
this.studentName = name;
}
public void setStudentId(int Identi) {
this.studentID = Identi;
}
public void setInsName(String insName) {
this.instructorName.setInsName(insName);
}
public void setCourseName(String courseName) {
this.courseName.setCourseName(courseName);
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

java code:

studentMain.java


package studentmain;

import java.util.ArrayList;
import java.util.Scanner;
public class StudentMain {

//classes
public static Student student;
public static ArrayList<Student> students;
public static HighSchoolStudent highStudent;
  
public static void main(String[] args) {
  
int choice;
Scanner scanner = new Scanner(System.in);

students = new ArrayList<>();
  
//loop starts
while (true) {
displayMenu();
choice = scanner.nextInt(); //disply menu
switch (choice) {
case 1:
addCollegeStudent();//call add function
break;
case 2:
addHighSchoolStudent(); //call add to high school function
break;
case 3:
deleteStudent(); //delet student
break;
case 4:
searchStudent();//search
break;
case 5:
display(); //display
break;
case 6:
modifyStudentData(); //modify function
break;
case 7:
System.exit(0); //stop the program
default:
System.out.println("Invalid choice!");
break;
}
}
}

//modfiy the details entered
private static void modifyStudentData() {
Scanner choice = new Scanner(System.in);

System.out.println("Select the option from below");
System.out.println("1. Change student name");
System.out.println("2. Change student ID");
System.out.println("3. Change instructor name");
System.out.println("4. Change course name");

int userChoice = choice.nextInt();

//get user choice and call the neccessary function
switch (userChoice) {
case 1:
System.out.println("Enter new student name");
String newStudentName = choice.next();

student.setStudentName(newStudentName);
break;

case 2:
System.out.println("Enter new student ID");
int newStudentID = choice.nextInt();
student.setStudentId(newStudentID);
break;

case 3:
System.out.println("Enter new instructor name");
String newInsName = choice.next();
student.setInsName(newInsName);
break;

case 4:
System.out.println("Enter new course name");
String newCourseName = choice.next();
student.setCourseName(newCourseName);
break;
}
}
//if change details again
private static void modifyAgain() {
System.out.println("Do you still need to change anything else?" + "\nPress Y for yes.");
Scanner choice = new Scanner(System.in);
String userChoice = choice.next();
if (userChoice.equalsIgnoreCase("Y")) {
modifyStudentData();
}
}

//display the menu
public static void displayMenu() {
System.out.println("1. Add College Student");
System.out.println("2. Add High School Student");
System.out.println("3. Delete");
System.out.println("4. Search");
System.out.println("5. Display");
System.out.println("6. Modify");
System.out.println("7. Exit");
System.out.print("Enter your choice: ");
}

//add details to college student
public static void addCollegeStudent() {
String studentName, instructorName, courseName;
int studentID;

//get details from user
Scanner sName = new Scanner(System.in);
System.out.println("Please enter student name here: ");
studentName = sName.nextLine();
studentName = studentName.substring(0, 1).toUpperCase() + studentName.substring(1);

Scanner sID = new Scanner(System.in);
System.out.println("Please enter student ID here: ");
studentID = sID.nextInt();

Scanner iName = new Scanner(System.in);
System.out.println("Please enter intructor name here: ");
instructorName = iName.nextLine();
instructorName = instructorName.substring(0, 1).toUpperCase() + instructorName.substring(1);
Scanner cName = new Scanner(System.in);

System.out.println("Please enter course name here: ");
courseName = cName.nextLine();
courseName = courseName.substring(0, 1).toUpperCase() + courseName.substring(1);

//add to student class
students.add(new Student(studentName, instructorName, studentID, courseName));
}
  
//add high school details
public static void addHighSchoolStudent() {
String studentName, instructorName, courseName, highSName, gradeL = null;
int studentID;

//get data from user
Scanner sName = new Scanner(System.in);
System.out.println("Please enter student name here: ");
studentName = sName.nextLine();
studentName = studentName.substring(0, 1).toUpperCase() + studentName.substring(1);

Scanner sID = new Scanner(System.in);
System.out.println("Please enter student ID here: ");
studentID = sID.nextInt();

Scanner iName = new Scanner(System.in);
System.out.println("Please enter intructor name here: ");
instructorName = iName.nextLine();
instructorName = instructorName.substring(0, 1).toUpperCase() + instructorName.substring(1);

Scanner cName = new Scanner(System.in);
System.out.println("Please enter course name here: ");
courseName = cName.nextLine();
courseName = courseName.substring(0, 1).toUpperCase() + courseName.substring(1);

System.out.println("Please enter High School name here: ");
Scanner hName = new Scanner(System.in);
highSName =hName.nextLine();// highStudent.nameHS;

System.out.println("Please enter grade Level here: ");
gradeL =hName.nextLine();// highStudent.nameHS;

//add to student class
students.add(new HighSchoolStudent(studentName, instructorName, studentID, courseName, highSName, gradeL));
}

//delete a student details
public static void deleteStudent() {
int studentID;
Student del = null;
Scanner sID = new Scanner(System.in);
//get id from user
System.out.println("Please enter student ID to delete: ");
studentID = sID.nextInt();
for (Student s : students) {
if (s.getStudentID() == studentID) {
del = s;
break;
}
}
if (del != null)
students.remove(del);
}
//search a student
public static void searchStudent() {
String studentName;
Scanner sName = new Scanner(System.in);
System.out.println("Please enter student name here: ");
studentName = sName.nextLine();
studentName = studentName.substring(0, 1).toUpperCase() + studentName.substring(1);
for (Student s : students) {
if (s.getStudentName().equals(studentName)) {
System.out.println(studentName + " found");
return;
}
}
System.out.println(studentName + " not found");
}

//display function
public static void display() {
System.out.format("|%20s|%10s|%20s|%20s|\n", "Student ", "ID","Instructor", "Course");
System.out.println("---------------------------------------------------------------------------");
for (Student s : students) {
System.out.format("|%20s|%10s|%20s|%20s|\n",s.getStudentName(), s.getStudentID(),s.getInsName(), s.getCourseName());
}

}
  
}

Student.java


package studentmain;


public class Student {
private String studentName;
private Instructor instructorName;
private Course courseName;
private int studentID;

public Student (){} //constructor
  
//constructor with parameter
public Student (String sName, String iName, int sID, String cName) {
this.studentName = sName;
this.instructorName = new Instructor(iName);
this.courseName = new Course(cName);
this.studentID = sID;
}
//return student name
public String getStudentName(){
return studentName;
}
//return instructor name
public String getInsName(){
return instructorName.IName;
}
//return course name
public String getCourseName(){
return courseName.cName;
}
//return student ID
public int getStudentID(){
return studentID;
}

//set name
void setStudentName(String name) {
this.studentName = name;
}
//set ID
public void setStudentId(int Identi) {
this.studentID = Identi;
}
//set instructor name
public void setInsName(String insName) {
this.instructorName.setInsName(insName);
}
  
//set course name
public void setCourseName(String courseName) {
this.courseName.setCourseName(courseName);
}

  
}

HighSchoolStudent.java


package studentmain;


public class HighSchoolStudent extends Student {
String gradeLevel, nameHS;

//constructor with paramtere
public HighSchoolStudent(String sName, String iName, int sID, String cName, String hName, String gradeL) {
super(sName, iName, sID, cName);
this.nameHS = hName;
this.gradeLevel = gradeL;
}

//return name
public String getHSName(){
return nameHS;
}
//return grade
public String getGrade(){
return gradeLevel;
}
  
//set hs name
public void setHSName(String HSName){
this.nameHS = HSName;
}
  
//set grade level
public void setGradeLevel(String gradeLev){
this.gradeLevel = gradeLev;
}
}

Instructor.java


package studentmain;


public class Instructor extends Student{
String IName;
  
//constructor
Instructor(String iName) {
this.IName=iName;
}

//set instructor name
public void setInsName(String insName) {
this.IName=insName;
}
  
}

Course.java


package studentmain;


public class Course extends Student {

String cName;
//constructor
Course(String cName) {
this.cName=cName;
}

//set course name
public void setCourseName(String courseName) {
this.cName=courseName;
}
  
}

output:

<default config Output StudentMain (run) X run: 1. Add College Student 2. Add High School Student 3. Delete 4. Search 5. Disp

//i have given code course.java and Instructor.java as per the output needed. modified the code as per requirements. if you need any help please do comments.

Add a comment
Know the answer?
Add Answer to:
I need to add a method high school student, I couldn't connect high school student to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • java programming how would i modify the code below to add a GUI (with a main menu with graphics and buttons, etc...) and include an option to print a list of all students added in a grid format and sh...

    java programming how would i modify the code below to add a GUI (with a main menu with graphics and buttons, etc...) and include an option to print a list of all students added in a grid format and short by name, course, instructor, and location. ///main public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList<Student>students = new ArrayList<>(); int choice; while(true) { displayMenu(); choice = in.nextInt(); switch(choice) { case 1: in.nextLine(); System.out.println("Enter Student Name"); String name...

  • Please make the following code modular. Therefore contained in a package with several classes and not...

    Please make the following code modular. Therefore contained in a package with several classes and not just one. import java.util.*; public class Q {    public static LinkedList<String> dogs = new LinkedList<String> ();    public static LinkedList<String> cats = new LinkedList<String> ();    public static LinkedList<String> animals = new LinkedList<String> ();    public static void enqueueCats(){        System.out.println("Enter name");        Scanner sc=new Scanner(System.in);        String name = sc.next();        cats.addLast(name);        animals.addLast(name);    }   ...

  • Java. Java is a new programming language I am learning, and so far I am a...

    Java. Java is a new programming language I am learning, and so far I am a bit troubled about it. Hopefully, I can explain it right. For my assignment, we have to create a class called Student with three private attributes of Name (String), Grade (int), and CName(String). In the driver class, I am suppose to have a total of 3 objects of type Student. Also, the user have to input the data. My problem is that I can get...

  • (How do I remove the STATIC ArrayList from the public class Accounts, and move it to...

    (How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts { static ArrayList<String> accounts = new ArrayList<>(); static Scanner scanner = new Scanner(System.in);    public static void main(String[] args) { Scanner scanner = new Scanner(System.in);    int option = 0; do { System.out.println("0->quit\n1->add\n2->overwirte\n3->remove\n4->display"); System.out.println("Enter your option"); option = scanner.nextInt(); if (option == 0) { break; } else if (option == 1) { add(); } else...

  • Need Help ASAP!! Below is my code and i am getting error in (public interface stack)...

    Need Help ASAP!! Below is my code and i am getting error in (public interface stack) and in StackImplementation class. Please help me fix it. Please provide a solution so i can fix the error. thank you.... package mazeGame; import java.io.*; import java.util.*; public class mazeGame {    static String[][]maze;    public static void main(String[] args)    {    maze=new String[30][30];    maze=fillArray("mazefile.txt");    }    public static String[][]fillArray(String file)    {    maze = new String[30][30];       try{...

  • There is a problem in the update code. I need to be able to update one...

    There is a problem in the update code. I need to be able to update one attribute of the students without updating the other attributes (keeping them empty). package dbaccessinjava; import java.sql.DriverManager; import java.sql.Connection; import java.sql.SQLException; import java.sql.*; import java.io.*; import java.util.Scanner; public class DBAccessInJava { public static void main(String[] argv) {    System.out.println("-------- Oracle JDBC Connection Testing ------"); Connection connection = null; try{ Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con= DriverManager.getConnection("jdbc:oracle:thin:@MF057PC16:1521:ORCL", "u201303908","pmu"); String sql="select * from student"; Statement st; PreparedStatement ps; ResultSet rs;...

  • I need the following java code commented import java.util.Scanner; public class Main { public static void...

    I need the following java code commented import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner (System.in); int productNo=0; double product1; double product2; double product3; double product4; double product5; int quantity; double totalsales=0; while(productNo !=0) System.out.println("Enter Product Number 1-5"); productNo=input.nextInt(); System.out.println("Enter Quantity Sold"); quantity=input.nextInt(); switch (productNo) { case 1: product1=1.00; totalsales+=(1.00*quantity); break; case 2: product2=2.00; totalsales+=(2.00*quantity); break; case 3: product3=6.00; totalsales+=(6.00*quantity); break; case 4: product4=23.00; totalsales+=(23.00*quantity); break; case 5: product5=17.00; totalsales+=(17.00*quantity); break;...

  • How would you make it hold both the student's name and their teacher? then be able...

    How would you make it hold both the student's name and their teacher? then be able to sort based on either the students name or who their teacher is? import java.util.Scanner; //for taking user input public class StudentName{ //you can change class name public static void main(String[] args); { Scanner in = new Scanner(System.in); //finding length of array studentNames System.out.print("how many students? :") ; int totalStudents = in. nextInt() ; String[] studentNames = new String[totalStudents] ; //input user name for(int...

  • In this same program I need to create a new method called “int findItem(String[] shoppingList, String...

    In this same program I need to create a new method called “int findItem(String[] shoppingList, String item)” that takes an array of strings that is a shopping list and a string for an item name and searches through the “shoppingList” array for find if the “item” exists. If it does exist print a confirmation and return the item index. If the item does not exist in the array print a failure message and return -1. import java.util.Scanner; public class ShoppingList...

  • I have this java program that I need to add an abstract method and polymorphism to...

    I have this java program that I need to add an abstract method and polymorphism to it : import java.util.Scanner; //class and encapsulation class BookTheTicket { private String movieName; private String theatreName; private int ticketCost; void myAllmovies() { System.out.println("-------Listing the movies:------"); System.out.println(" 1.DDLJ ------------ $40 \n 2.kkr---------$.50 \n 3.game-movie --------$60 \n 4.fun movie ----- $.70 "); } } // inheritence class theater extends BookTheTicket{ private int numOfTickets; void theater() { System.out.println("*******Listing the theatre:******* \n 1.coco cola tld \n 2.koi gandhi...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT