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);
}
}
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:

//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.
I need to add a method high school student, I couldn't connect high school student to...
Could you help me pleas , this is my code I want change it to insert student by user , and i have problem when i want append name it just one time i can't append or present more one. >>>>>>>>>>>>>>>>>>>. import java.util.Iterator; import java.util.Scanner; public class studentDLLTest { static int getChoice() { Scanner in = new Scanner(System.in); int choice; do { System.out.print("\nYour choice? : "); choice = in.nextInt(); } while (choice < 1 || choice > 9); return choice;...
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 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 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...
Language Java Step 1: Design a class called Student. The Student class should contain the following data: firstName lastName studentID totalCredits gpa Your class should implement the “sets” and “gets” for the class. Include methods: equals, compareTo, toString. Change the toString method (from class) to put each member variable on a new line. Step 2: Write a driver program to test that Student works correctly. Test is with 3 students as given in class. Step 3: Write a “registration” program...
When I invoke the forward or backward method the current_number isnt being changed. Not sure if its something in my switch case or my methods.. package project4; import java.awt.image.BufferedImage; import java.net.URL; import java.util.Scanner; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class PictureViewer { final static int MIN_NUMBER = 0; final static int MAX_NUMBER = 8; static int image_number = 1; public static int forward(int current_number) { if (current_number < MAX_NUMBER) { return current_number ++; }...
(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) 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{...
I am gettting error saying that I need to initialize variable but I want to get inputs from the user and want to print them out. (using "for" loop) public static void main(String[] args) { String input; int i; Scanner sc = new Scanner(System.in); for (i=1; i < 5; i++) { System.out.print(i+ ". Please enter a name: "); input = sc.nextLine(); } System.out.println("All names are here:" + input); } }
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;...