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
1. Why is photographing lightning a difficult process?
bulgar [2K]
<span>1. Why is photographing lightning a difficult process?
</span>Some reasons which come to my mind for saying this are: 1) You get only one chance for the particular situation - it is not like portrait photography where you can go back in the studio if the photos didn't come out well; 2) lightning varies so much in brightness, intensity and location that guessing the proper exposure requires a lot of experience, as well as luck; 3) you are always at some risk when photographing worthwhile lightning; and 4) lightning is a point (line) source, and demands the most of the optical quality of your camera 
<span>
2. What piece of equipment is helpful in capturing lightning photographs?
</span><span><span>SLR camera with B-shutter speed (preferably SLR; you might try using your digital camera, if it has B mode, but this is much more difficult)</span><span>lenses ranging from 28mm to 135mm at minimum. Fixed-focal lenses are preferred over zoomlenses. Aperture ranges should be f/2.8 - f/22.</span><span>sturdy tripod (metal or plastic doesn't make any difference whatsoever at all in safety - if lightning is so close by, you are in trouble anyway)</span><span>cable release, which can be locked</span><span>Slow-speed film: 100 or 200 ISO
</span></span><span>
3. Why is it important to mentally prepare for photographing lightning?
</span><span>When photographing lightning, it’s important to realize that the conditions you are shooting in are unpredictable and dangerous, and there will always be an element of chance and luck involved. So you should prepare yourself.
</span><span>
4. What time of day should you try to photograph lightning?
</span>Nighttime lightning photography is the easiest <span>type
</span><span>
5. Why is composition important in lightning photographs?
It boosts or adds drama to your picture. </span>
6 0
2 years ago
Read 2 more answers
What is Gpu in simple terms ​
Bingel [31]
Graphic processing unit !!?????!!??!??!?!!?!!?
5 0
2 years ago
Read 2 more answers
What are the major differences between searching and sorting in Java? What are some of the differences in the techniques used in
Studentka2010 [4]

Answer:  

  • Searching is a technique to look for an item or target value in a data structure like searching for a phone number in a directory.Data structure can be an array,List etc. Searching algorithms are used for searching. Most common examples are Linear Search and Binary Search. Lets take the example Linear Search in order to explain it using JAVA. Its the simplest searching algorithm. To search for a specific element, look at each element in the data structure sequentially and check if it matches with the element being searched for.
  • Sorting is a technique of arranging the elements in a specific order e.g. numerical sorting, ordering students according to their exam score. This order can be ascending or descending or alphabetical order. Contrary to search it returns the data structure e.g. an array in which the elements of array are sorted in a particular order. Sorting algorithms are used to sort elements in a data structure. Some common examples of sorting algorithms are Bubble Sort, Insertion Sort, Selection Sort, Merge Sort, Quick Sort, Heap Sort etc. JAVA uses Array.Sort() built-in function for sorting an array. By default it sorts the input array in ascending order.
  • Selection Sort: It is a sorting technique which divides an array into two subarrays. One subarray in the left is sorted and the other one at right is unsorted. This is an in-place algorithm. It is not a good option for large data. Initially the sorted part is empty and all elements are placed in unsorted array. First the element which is the smallest in the unsorted array is selected and swapped with the leftmost array element and becomes part of the sorted array. In each iteration the smallest element from the unsorted array is selected and moved to sorted part of the array.The worst case time complexity of this algorithm is O(n)^2 as we have to find the smallest for every element in the array.
  • Merge Sort: It is a comparison based algorithm. It works on divide and conquer technique. It uses recursion approach for sorting. This means it breaks the problem(lets say array list to be sorted) into sub problems (smaller parts) and then solves (in this case sorts) each sub problem in a recursive manner. At the end it merges the solutions (hence the merged sorted array). Although selection sort works faster when data set is small merge sort outperforms it for larger data sets. Merge sort is a stable algorithm and works best for linked lists. Its not an in place algorithm. Time complexity of merge sort is O(n*log n) for best, average and worst cases because it always divides the array in two parts and takes linear time to merge these part. O(n(logn)) time complexity makes it better,more efficient and faster to sort large data sets.
  •  Big Oh O notation is an asymptotic annotation written as O(n) which is a mathematical way to represent the upper bound of the running time of   algorithm (sorting algorithm in this case). It computes the worst case time complexity. Worst case time complexity means that the longest amount of time or maximum number of operations that will be required for a sorting algorithm to complete. The time complexity mostly gets affected as the size of the input varies.
  • For example lets find out the worst-case time complexity of Bubble Sort for a list of n elements. Worst case is when the array is reversed sorted. At first iteration it would make n-1 comparisons. At iteration 1, for n-2 times and so total comparison will be O(n^)2. So the time to run program is proportional to the square of the input size.
  • Searching algorithms are used when there is a need to find a specific data item from bulk of data item. Searching algorithms make this hectic process easier. For example you want to find phone number of person from directory. without searching algorithm looking for each phone number in the directory manually can be very time consuming. For example you have to find address of a customer number 254 from database to deliver a product. Instead  of manually looking for customer numbers you can simply use  linear search algorithm that will start from customer 1 and sequentially searches for specific customer 254 number and provides the address in a shorter time.
  • Sorting reduces complexity of problems e.g reducing the searching complexity. It is easier to locate data elements in a sorted list than unsorted. For example comparing two large data sets containing millions of records. If both the data sets are ordered, the comparison gets easier. Moreover every sorting algorithm has certain usage. Like merge sort is useful for linked lists,heap sort is good with arrays and uses less memory. If data is small with large values, selections sort is better for this. It doesn’t require any additional space. Databases use merge sort to arrange data that is too large to be loaded completely into memory.  Heap sort is used in reading bar codes on plastic cards. Quick sort is used to maintain sports score on the basis of win-loss ratio.
5 0
2 years ago
You use a web browser to search for “winter sweaters” on your laptop. Later, you are playing a game on your phone and an ad show
melomori [17]

Answer:

C

data mining

Explanation:

they are seeing what you are interested in and creating personalized adds

8 0
2 years ago
Read 2 more answers
What will be the color if today is Saturday?
Dennis_Churaev [7]

Answer:

I would say D but I am not for sure

6 0
3 years ago
Other questions:
  • Liz will use a CD-R compact disk to write to more than once. Carlo will use a CD-RW compact disk to write to more than once. Who
    8·2 answers
  • A tower or mini tower pc is a type of all- in -one unit true or false
    9·2 answers
  • Read the scenario below and then answer the
    14·1 answer
  • Which option describes wearable technology?
    9·1 answer
  • True or False: When you share something on a friend’s Timeline, only that friend can see it.
    5·2 answers
  • Ok.,so i have a sopitify account and by accident i pressed the downlaod on button and it says start you free trial i pressed tha
    11·2 answers
  • Based on the screenshot below which letter do you select to sort the items in an alphabetical order?
    9·1 answer
  • Conclusion for primary memory
    15·1 answer
  • What is the codebook?
    6·1 answer
  • I came here for a answer so why did i get a pep talk
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!