Question

PROGRAM STATEMENT AND REQUIREMENTS: Great Tutors Inc. is a company that provides tutoring services to elementary school stude

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

NOTE:- IN CASE OF ANY QUERY FEEL FREE TO ASK IN COMMENT ANYTIME ........HAPPY LEARNING AND KEEP CHEGGING.......

ANSWER:-

Here we have total 3 classes :

1. Teacher.java

package com.teaching;

import java.util.List;

public class Teacher {
        
        private int id;
        private String name;
        private int pay_hour;
        private int teaching_hours;
        private int ongoing_hours;
        private List<Student> students;
        private int total_payout;
        
        
        
        public Teacher(int id,String name, int teaching_hours, int pay_hour) {
                super();
                this.id = id;
                this.name = name;
                this.teaching_hours = teaching_hours;
                this.pay_hour = pay_hour;
        }
        
        
        
        public int getOngoing_hours() {
                return ongoing_hours;
        }



        public void setOngoing_hours(int ongoing_hours) {
                this.ongoing_hours = ongoing_hours;
        }



        public int getPay_hour() {
                return pay_hour;
        }



        public void setPay_hour(int pay_hour) {
                this.pay_hour = pay_hour;
        }



        public int getId() {
                return id;
        }

        public void setId(int id) {
                this.id = id;
        }

        public String getName() {
                return name;
        }
        public void setName(String name) {
                this.name = name;
        }
        public int getTeaching_hours() {
                return teaching_hours;
        }
        public void setTeaching_hours(int teaching_hours) {
                this.teaching_hours = teaching_hours;
        }
        public List<Student> getStudents() {
                return students;
        }
        public void setStudents(List<Student> students) {
                this.students = students;
        }
        public int getTotal_payout() {
                return total_payout;
        }
        public void setTotal_payout(int total_payout) {
                this.total_payout = total_payout;
        }



        @Override
        public String toString() {
                return "Teacher [id=" + id + ", name=" + name + ", pay_hour=" + pay_hour + ", teaching_hours=" + teaching_hours
                                + ", students=" + students + ", total_payout=" + total_payout + "]";
        }

        

        
        
        
        
        
        
        

}

2. Student.java

package com.teaching;

public class Student {
        
        private int id;
        private int age;
        private String name;
        private Teacher teacher;
        public Student(int id, int age, String name, Teacher teacher) {
                super();
                this.id = id;
                this.age = age;
                this.name = name;
                this.teacher = teacher;
        }
        
        public int getId() {
                return id;
        }

        public void setId(int id) {
                this.id = id;
        }

        public int getAge() {
                return age;
        }
        public void setAge(int age) {
                this.age = age;
        }
        public String getName() {
                return name;
        }
        public void setName(String name) {
                this.name = name;
        }
        public Teacher getTeacher() {
                return teacher;
        }
        public void setTeacher(Teacher teacher) {
                this.teacher = teacher;
        }
        @Override
        public String toString() {
                return "Student [id="+id+", age=" + age + ", name=" + name + ", teacher=" + teacher + "]";
        }
        
        
        

}

3. Driver.java

package com.teaching;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Driver {

        static List<Teacher> teacher_list = new ArrayList<>();
        static List<Student> student_list = new ArrayList<>();
        private static DecimalFormat df2 = new DecimalFormat("#.##");
        static Scanner sc = new Scanner(System.in);

        public static void main(String[] args) {

                while (true) {
                        System.out.println(
                                        "Press 1 to add teacher\nPress 2 to add students\nPress 3 for teaching process : \nPress 4 for generating invoice\nPress 0 to exit");
                        int choice = sc.nextInt();
                        switch (choice) {
                        case 1:
                                addTeacher();
                                break;
                        case 2:
                                addStudent();
                                break;
                        case 3:
                                teachingProcess();
                                break;
                        case 4:
                                generateInvoice();
                                break;
                        case 0:
                                System.exit(0);
                                break;
                        default:
                                System.out.println("Please select a proper choice");
                        }
                }
        }

        private static void generateInvoice() {
                System.out.println("Please enter student id : ");
                int stid = sc.nextInt();
                List<Student> stl = student_list.stream().filter(stu -> stu.getId() == stid).collect(Collectors.toList());
                if (stl.size() == 1) {
                        Student s = stl.get(0);
                        double pay = s.getTeacher().getOngoing_hours() * s.getTeacher().getPay_hour();
                        double discount = 0;
                        if (s.getAge() < 10)
                                discount = pay * 0.1;
                        // pay = Double.valueOf(df2.format(pay*0.9));

                        System.out.println("***************************************\n\n");
                        System.out.println("Invoice");
                        System.out.println("***************************************\n");
                        System.out.println("Student Details : \n\n");
                        System.out.println("Name : " + s.getName());
                        System.out.println("Age : " + s.getAge());
                        System.out.println("Mentor's Name : " + s.getTeacher().getName());
                        System.out.println("Total Teaching Hours : " + s.getTeacher().getOngoing_hours());
                        System.out.println("Total Pay : " + pay);
                        System.out.println("Total Discount : " + discount);
                        System.out.println("Total Payment : " + Double.valueOf(df2.format(pay * 0.9)));
                        System.out.println("***************************************\n\n");
                } else {
                        System.out.println("Please enter a right student id");
                }
        }

        private static void teachingProcess() {
                System.out.println("Please enter Student id : ");
                int id = sc.nextInt();
                List<Student> stl = student_list.stream().filter(stu -> stu.getId() == id).collect(Collectors.toList());
                if (stl.size() == 1) {
                        System.out.println("Please enter teaching hours : ");
                        int hours = sc.nextInt();
                        for (int i = 0; i < teacher_list.size(); i++) {
                                if (stl.get(0).getTeacher().getId() == teacher_list.get(i).getId()) {
                                        int total_h = teacher_list.get(i).getTeaching_hours();
                                        int ongoing_h = teacher_list.get(i).getOngoing_hours();
                                        if (total_h - ongoing_h >= hours)
                                                teacher_list.get(i).setOngoing_hours(ongoing_h + hours);
                                }
                        }
                } else {
                        System.out.println("Please enter a right student id");
                }
        }

        private static void addTeacher() {
                System.out.println("Enter name :");
                String name = sc.next();
                System.out.println("Enter Max teaching hours : ");
                int hours = sc.nextInt();
                System.out.println("Enter per hour fees : ");
                int fees = sc.nextInt();
                Teacher tch = new Teacher(teacher_list.size() + 1, name, hours, fees);
                teacher_list.add(tch);
                System.out.println("Teacher is added successfully. Id is : "+tch.getId());
        }

        private static void addStudent() {
                System.out.println("Enter Name : ");
                String name = sc.next();
                System.out.println("Enter Age : ");
                int age = sc.nextInt();
                Student st = null;
                if (teacher_list.size()!=0) {
                        Random rand = new Random();
                        int num = rand.nextInt(teacher_list.size());
                        st = new Student((student_list.size() + 1), age, name, teacher_list.get(num));
                        List<Student> sl = teacher_list.get(num).getStudents();
                        if(sl==null) {
                                sl = new ArrayList<Student>();
                        }
                        sl.add(st);
                        teacher_list.get(num).setStudents(sl);
                } else
                        st = new Student((student_list.size() + 1), age, name, null);

                student_list.add(st);
                System.out.println("Student is added successfully. Id is : "+st.getId());

        }

}

Output :

Press 1 to add teacher
Press 2 to add students
Press 3 for teaching process : 
Press 4 for generating invoice
Press 0 to exit
1
Enter name :
Soumya
Enter Max teaching hours : 
38
Enter per hour fees : 
150
Teacher is added successfully. Id is : 1
Press 1 to add teacher
Press 2 to add students
Press 3 for teaching process : 
Press 4 for generating invoice
Press 0 to exit
1
Enter name :
Sudeshna
Enter Max teaching hours : 
35
Enter per hour fees : 
120
Teacher is added successfully. Id is : 2
Press 1 to add teacher
Press 2 to add students
Press 3 for teaching process : 
Press 4 for generating invoice
Press 0 to exit
2
Enter Name : 
Kundan
Enter Age : 
8
Student is added successfully. Id is : 1
Press 1 to add teacher
Press 2 to add students
Press 3 for teaching process : 
Press 4 for generating invoice
Press 0 to exit
2
Enter Name : 
Ram
Enter Age : 
12
Student is added successfully. Id is : 2
Press 1 to add teacher
Press 2 to add students
Press 3 for teaching process : 
Press 4 for generating invoice
Press 0 to exit
3
Please enter Student id : 
1
Please enter teaching hours : 
3
Press 1 to add teacher
Press 2 to add students
Press 3 for teaching process : 
Press 4 for generating invoice
Press 0 to exit
3
Please enter Student id : 
2
Please enter teaching hours : 
4
Press 1 to add teacher
Press 2 to add students
Press 3 for teaching process : 
Press 4 for generating invoice
Press 0 to exit
4
Please enter student id : 
1
***************************************


Invoice
***************************************

Student Details : 


Name : Kundan
Age : 8
Mentor's Name : Sudeshna
Total Teaching Hours : 7
Total Pay : 840.0
Total Discount : 84.0
Total Payment : 756.0
***************************************
Press 1 to add teacher
Press 2 to add students
Press 3 for teaching process : 
Press 4 for generating invoice
Press 0 to exit
0
Add a comment
Know the answer?
Add Answer to:
PROGRAM STATEMENT AND REQUIREMENTS: Great Tutors Inc. is a company that provides tutoring services to elementary...
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 this phase of the project you will create an ERD based upon the following requirements and bus...

    In this phase of the project you will create an ERD based upon the following requirements and business rules. Limit your ERD to entities and relationships based on the business rules showed here. In other words, do not add realism to your design by expanding or refining the business rules. However, make sure you include all attributes needed that would permit the model to be successfully implemented, including all primary and foreign keys. 1. Trinity College (TC) is divided into...

  • �Martial Arts R Us� (MARU) needs a database. MARU is a martial arts school with hundreds of students. It is necessary to...

    �Martial Arts R Us� (MARU) needs a database. MARU is a martial arts school with hundreds of students. It is necessary to keep track of all the different classes that are being offered, who is assigned to teach each class, and which students attend each class. Also, it is important to track the progress of each student as they advance. Create a complete Crow�s Foot ERD for these requirements: Students are given a student number when they join the school....

  • Help needed on C++ program: Program Description: Complete the Ship, CruiseShip, and CargoShip program (#12 in...

    Help needed on C++ program: Program Description: Complete the Ship, CruiseShip, and CargoShip program (#12 in the 9th edition of the text). Read the specific method requirements in the text. Specific Requirements: • Create the Ship class. • Create CruiseShip and CargoShip classes that are derived from Ship. • Create a small tester cpp file that has an array of Ship pointers (one each of Ship, CruiseShip, and CargoShip). The program steps through the array, calling each object’s print method....

  • write in java and please code the four classes with the requirements instructed You will be...

    write in java and please code the four classes with the requirements instructed You will be writing a multiclass user management system using the java. Create a program that implements a minimum of four classes. The classes must include: 1. Employee Class with the attributes of Employee ID, First Name, Middle Initial, Last Name, Date of Employment. 2. Employee Type Class that has two instances of EmployeeType objects: salaried and hourly. Each object will have methods that calculates employees payrol...

  • code in java please:) Part I Various public transporation can be described as follows: A PublicTransportation...

    code in java please:) Part I Various public transporation can be described as follows: A PublicTransportation class with the following: ticket price (double type) and mumber of stops (int type). A CityBus is a PublicTransportation that in addition has the following: an route number (long type), an begin operation year (int type), a line name (String type), and driver(smame (String type) -A Tram is a CityBus that in addition has the following: maximum speed (int type), which indicates the maximum...

  • Question 1: University Database Consider the following set of requirements for a UNIVERSITY database that is...

    Question 1: University Database Consider the following set of requirements for a UNIVERSITY database that is used to keep track of students' transcripts. The university keeps track of each student's name, student number, social security number current address and phone, permanent address and phone, birth date, sex, class (freshman, sophomore,., graduate), major department, minor department (if any), and degree program (B.A., B.S.,..., Ph.D.). Some user applications need to refer to the city, state, and zip of the student's permanent address,...

  • Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance...

    Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance and interface behaviors . The link to the PDF of the diagram is below MotorVehical.pdf Minimize File Preview User Define Object Assignment: Create a Intellij Project. The Intellij project will contain three user defined classes. The project will test two of the User Define Classes by using the invoking each of their methods and printing the results. You are required to create three UML...

  • Problem 1 Consider the following set of requirements for a university database that is used to...

    Problem 1 Consider the following set of requirements for a university database that is used to keep track of students' transcripts. (a) The university keeps track of each student's name, student number, social security number, current address and phone, permanent address and phone, birthdate, sex, class (freshman, sophomore, -, graduate), major department, minor department (if any), and degree program (B.A., B.S., ...., Ph.D.). Some user applications need to refer to the city, state, and zip of the student's permanent address,...

  • CS 2050 – Programming Project # 1 Due Date: Session 3 (that is, in one week!)....

    CS 2050 – Programming Project # 1 Due Date: Session 3 (that is, in one week!). Can be resubmitted up to two times until Session 6 if your first version is submitted by session 3. In this project, you create two classes for tracking students. One class is the Student class that holds student data; the other is the GradeItem class that holds data about grades that students earned in various courses. Note: the next three projects build on this...

  • Create a C++ program to calculate grades as well as descriptive statistics for a set of...

    Create a C++ program to calculate grades as well as descriptive statistics for a set of test scores. The test scores can be entered via a user prompt or through an external file. For each student, you need to provide a student name (string) and a test score (float). The program will do the followings: Assign a grade (A, B, C, D, or F) based on a student’s test score. Display the grade roster as shown below: Name      Test Score    ...

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