1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
r-ruslan [8.4K]
3 years ago
6

Write a class called Course that represents a course taken at a school. Represent each student using the modified Student class

from the previous programming project. Use an ArrayList in the Course to store the students taking that course. The constructor of the Course class should accept only the name of the course. Provide a method called addStudent that accepts one Student parameter. Provide a method called average that computes and returns the average of all students’ test score averages. Provide a method called roll that prints all students in the course. Create a driver class with a main method that creates a course, adds several students, prints a roll, and prints the overall course test average.
Computers and Technology
1 answer:
Vinvika [58]3 years ago
3 0

Answer:

The code is given below with its appropriate output

Explanation:

//Student.java

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

import java.util.Scanner;

public class Student {

public String firstName;

public String lastName;

public float[] marks;

Scanner scanner = new Scanner(System.in);

public Student(String firstName, String lastName) {

this.firstName = firstName;

this.lastName = lastName;

}

public void getdetail() {

System.out.println("enter only five marks");

marks = new float[5];

int count = 0;

for (int i = 0; i < 5; i++) {

float mark = 0;

++count;

if (count <= 5) {

System.out.println("enter score " + count);

mark = scanner.nextFloat();

if (mark >= 0.0 && mark <= 100.0)

marks[i] = mark;

else {

System.out.println("you entered mark is invalid");

marks[i] = 0;

}

} else

System.out.println(" maximum is five only");

}

}

public void tostring() {

System.out.println("firstname :" + "\t" + firstName + "\t" + "lastname :"

+ "\t" + lastName + "\n" + "the marks are");

int count = 0;

for (float mark : marks) {

count++;

System.out.println("the mark of " + count + " is " + mark);

}

}

public void Averagecal() {

float sum = 0.0f;

for (float mark : marks) {

sum = sum + mark;

}

float avg = sum / 5;

System.out.println("average of a student is " + avg);

}

}

//Course.java

import java.io.*;

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

import java.util.Scanner;

public class Course {

public String courseName;

public int number;

Student[] students;

Scanner scanner = new Scanner(System.in);

public Course(String courseName) {

this.courseName = courseName;

}

public void addStudents() {

System.out

.println("how many no of students you want to add for this particular course");

int count = scanner.nextInt();

students = new Student[count];

for (int i = 0; i < count; i++) {

System.out.println("enter the first name");

String fname = scanner.next();

System.out.println("enter the last name");

String lname = scanner.next();

Student s = new Student(fname, lname);

s.getdetail();

s.tostring();

s.Averagecal();

students[i] = s;

}

}

public void roll() {

int count = 0;

for (Student stud : students) {

count++;

}

System.out.println("the no of students in this " + courseName

+ " course is " + count);

}

}

//Driver.java

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

import java.util.Scanner;

public class Driver {

public static void main(String[] args) {

Course course = new Course("java");

course.addStudents();

course.roll();

}

}

<u>output: </u>

C:\Users\Daniel\Desktop\New folder>javac Student.java

C:\Users\Danie;\Desktop\New folder>javac Course.java

C:\Users\Daniel\Desktop\New folder>javac Driver.java

C:\Users\Daniel\Desktop\New folder>java Driver

how many no of students you want to add for this particular course ?

1

enter the first name

john

enter the last name

rich

enter only five marks

enter score 1

89

enter score 2

91

enter score 3

85

enter score 4

78

enter score 5

96

firstname : john lastname : rich

the marks are

the mark of 1 is 89.0

the mark of 2 is 91.0

the mark of 3 is 85.0

the mark of 4 is 78.0

the mark of 5 is 96.0

average of a student is 87.8

the no of students in this java course is 1

C:\Users\Ravi\Desktop\New folder>

You might be interested in
How many address bits are needed to specify each byte in a 512 byte memory unit?
schepotkina [342]

Explanation:

In a 512 byte memory unit, in order to address each byte, there will be 512 locations (each one byte) ranging from 0 to 511.

Thus it will take 9 bits (2^9=512) to store the address within the unit.

5 0
3 years ago
1). What is the proper name of the healing agent?
VLD [36.1K]

Answer:

1. Hydroxychloroquine is the healing agent

2. Chloroquine does not have a hydroxyl group attached    

Explanation:              

Chloroquine and  Hydroxy chloroquine have been in use for many decades for malaria treatment and prophylaxis.    

It was found that there was a high possibility of being poisoned when treatment of chloroquine was administered. In 1946 the hydroxyl group replaced the CH3₃  (methyl) group with an ⁻OH (hydroxyl) group as indicated by the attachment. Toxicity by chloroquine was reduced to 40% when the ⁻OH group was attached.

Later chloroquine was added to formulas that are used for cleaning pools and fish tanks.

Both of these chemicals should be used by following the guide lines and under medical supervision if taken for any illness.

3 0
3 years ago
K. What are the types of page orientation?​
Leokris [45]

Answer:

there are 2 landscape and portrait

Explanation:

there are just 2 you can confirm using word and layout

4 0
3 years ago
To place the caption at the top of the image, you will need to change the __________ in the
dsp73
You have to change the options
4 0
3 years ago
Read 2 more answers
3. Coaxial/telephone cable sends<br> during the data transmission<br> signal
Vlad1618 [11]

Answer:

high frequency signal.

3 0
3 years ago
Other questions:
  • What is the one common feature that ties together different social media technologies? All of the social media tools we use toda
    5·2 answers
  • What procedures are involved in saving a file for the first time?
    10·2 answers
  • When typing the Works Cited in a report, set a .5" ______ indent. *
    12·1 answer
  • 1. Write a query to list the names all products (by product code and name) and the average ordered quantity for each product wit
    9·1 answer
  • Given two variables , first_place_winner and second_place_winner, write some code that swaps their associated values. use any ad
    12·1 answer
  • Universal Containers has two customer service contact centres and each focuses on a specific product line. Each contact centre h
    7·1 answer
  • Which two features offered by SharePoint
    12·1 answer
  • Define management styles
    14·2 answers
  • ________ technologies are technologies that enable the incremental improvement of products and services.
    10·2 answers
  • windows switches to secure desktop mode when the uac prompt appears. what is the objective of secure desktop mode?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!