Question

Implement the following class in interface and imp
0 0
Add a comment Improve this question Transcribed image text
Answer #1

// Student.java

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

public class Student {
   public Student(String name, int numClasses) {
       this.name = name;
       this.numClasses = numClasses;
   }

   public Student() {}
   String name;
   int numClasses;
   List<String> classList = new ArrayList<String>(100);
  

   public void input()
   {
       Scanner sc = new Scanner(System.in);
       System.out.print("Enter your name: ");
       this.name = sc.nextLine();
      
       System.out.print("Enter number of classes: ");
       this.numClasses = sc.nextInt();
      
       sc.nextLine();
       for(int i = 0; i < this.numClasses; i++)
       {
           String className;
           System.out.print("Enter class(" + (i + 1) + ") name: ");
           className = sc.nextLine();
           this.classList.add(className);
       }
   }
  
   public void reset()
   {
       this.numClasses = 0;
       this.classList = null;
       this.classList = new ArrayList<>(100);
   }
  
  
   public void output()
   {
       System.out.println("Student name: "+ getName());
      
       List<String> classes = getClassList();
       for(String className : classes)
       {
           System.out.println("Class name is " + className);
       }
   }
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public int getNumClasses() {
       return numClasses;
   }
   public void setNumClasses(int numClasses) {
       this.numClasses = numClasses;
   }
   public List<String> getClassList() {
       return classList;
   }
   public void setClassList(List<String> classList) {
       this.classList = classList;
   }
  
  
}

// StduentTest.java to test code


public class StudentTest {
   public static void main(String[] args)
   {
       Student student = new Student();
      
       System.out.println("Starting student input method");
       student.input();
      
       System.out.println("Outputing student details");
       student.output();
      
       System.out.println("Reseting student detail");
       student.reset();
      
       System.out.println("Outputing student details after reset");
       student.output();
   }
}

/*

Sample run

Starting student input method
Enter your name: StudentA
Enter number of classes: 5
Enter class(1) name: CourseA
Enter class(2) name: CourseB
Enter class(3) name: CourseC
Enter class(4) name: CourseD
Enter class(5) name: CourseE
Outputing student details
Student name: StudentA
Class name is CourseA
Class name is CourseB
Class name is CourseC
Class name is CourseD
Class name is CourseE
Reseting student detail
Outputing student details after reset
Student name: StudentA

*/

Add a comment
Know the answer?
Add Answer to:
Implement the following class in interface and implementation files. A separate file (the main project file)...
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
  • in C++: Create a class named Student that has three member variables: name - string that...

    in C++: Create a class named Student that has three member variables: name - string that stores the name of the student numClasses - integer that tracks how many courses the student is currently enrolled in, this number must be between 1 and 100. classList - an array of strings of size 100 used to store the names of the classes that the student is enrolled in Write the appropriate constructor(s), mutator and accessor functions for the class along with...

  • The class declaration (interface) and the function definitions (implementation) must be in separate files - the...

    The class declaration (interface) and the function definitions (implementation) must be in separate files - the interface or "header" file has a .hpp extension and the implementation has a .cpp extension. As usual, all data members should be private. Write a class called BankAccount that has: a string data member called customerName, a string data member called customerID, and a double data member called customerBalance a constructor that takes two strings and a double (name, ID, balance) and uses them...

  • In C++, Step 1: Implement the Student Class and write a simple main() driver program to...

    In C++, Step 1: Implement the Student Class and write a simple main() driver program to instantiate several objects of this class, populate each object, and display the information for each object. The defintion of the student class should be written in an individual header (i.e. student.h) file and the implementation of the methods of the student class should be written in a corresponding source (i.e. student.cpp) file. Student class - The name of the class should be Student. -...

  • 1a. Create a class named Inventory - Separate declaration from implementation (i.e. Header and CPP files)...

    1a. Create a class named Inventory - Separate declaration from implementation (i.e. Header and CPP files) 1b. Add the following private member variables - a int variable named itemNumber - an int variable named quantity - a double variable named cost - a double variable named totalCost. Total cost is defined as quantity X cost. - updateTotalCost() which takes no arguments and sets the values of the variable totalCost. 1c. Add the following public functions: - Accessor and Mutators for...

  • 3. Design and implement a class called ClassStats, in a file called stats.py, that includes: •...

    3. Design and implement a class called ClassStats, in a file called stats.py, that includes: • private attributes for a student number and status (pass or fail), • private class variables to keep track of the total number of students with status pass and the total number of students with status fail, • a constructor with default values (empty strings) for all instance variables, • an accessor method for each instance variable and also for the class vari- ables, •...

  • please help Write a simple program with Student class having STL list of Record's structure as...

    please help Write a simple program with Student class having STL list of Record's structure as a member. 1. Records of the Students are not accessible to the outside world. 2. Student shall output its standing (Freshman, Sophomore etc). 3. A Student can only be created with the name 4. A class can only be added if there is a class name and the passing grade. Driver program creates a Student, adds few classes to the Student's records, then prints...

  • C++ Lab 9A Inheritance Employee Class Create a project C2010Lab9a; add a source file Lab9a.cpp to...

    C++ Lab 9A Inheritance Employee Class Create a project C2010Lab9a; add a source file Lab9a.cpp to the project. Copy and paste the code is listed below: Design a class named Employee. The class should keep the following information in member variables: Employee name Employee number Hire date // Specification file for the Employee class #ifndef EMPLOYEE_H #define EMPLOYEE_H #include <string> using namespace std; class Employee { private:        // Declare the Employee name string variable here. // Declare the Employee...

  • Objectives: 1. Classes and Data Abstraction?2. User-defined classes?3. Implementation of a class in separate files Part...

    Objectives: 1. Classes and Data Abstraction?2. User-defined classes?3. Implementation of a class in separate files Part 1: In this assignment, you are asked: Stage1:?Design and implement a class named memberType with the following requirements: An object of memberType holds the following information: • Person’s first name (string)?• Person’s last name (string)?• Member identification number (int) • Number of books purchased (int)?• Amount of money spent (double)?The class memberType has member functions that perform operations on objects of memberType. For the...

  • // Client application class and service class Create a NetBeans project named StudentClient following the instructions...

    // Client application class and service class Create a NetBeans project named StudentClient following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. Add a class named Student to the StudentClient project following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. After you have created your NetBeans Project your application class StudentC lient should contain the following executable code: package studentclient; public class...

  • Please write a c++ header file, class implementation file and main file that does all of...

    Please write a c++ header file, class implementation file and main file that does all of the following and meets the requirements listed below. Also include a Output of your code as to show that your program works and functions properly. EXERCISING A DOUBLY-LINKED LIST CLASS This project consists of two parts, the second of which appears below. For the first part, write a class that implements an unordered list abstract data type using a doubly-linked list with pointers to...

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