Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have sent with a starter code please check A louch of Class All of the variables we have used so far (with the exception

I have sent with a starter code please check image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
A louch of Class All of the variables we have used so far (with the exception of arrays and the inputhielper) have been primitive data types. There's an awful lot you can do with primitive data types, in languages such as C we only have primitive data types (and people have done an awful lot with C). In Java however we have the option of creating more complex data types, classes! Programs of can get complex very quickly, in large pieces of software it is simply impossible to keep track of tens of thousands of lines of code when they are in a single file. To make life much easier for ourselves (honestly), we separate our code into separate functional classes. Class Half Full You may have noticed that you have been using classes in every single Java program you have written in this course so far, nice job! We define a class using the keyword, which you may note has been near the start of each of your submissions. Each of our programs have been quite short, so we haven't used many of the features apart from a single function where we have put all of our code. Each of our classes can contain a number of variables, as well as functions to operate on those variables. From now on, variables when they belong to a class will be referred to as attributes, and a function which belongs to a class is called a method. This ability to separate methods into classes is what makes object oriented programming so powerful. We define a method by first specifying the access modifier of the method, which for now we will make then the return type of the method, which will be either a primitive data type, another class or to indicate no return type. We then have the name of the method, followed by the types and names of each of the variables the method will take. An example class with a single variable and a single method could be: public class Student f pubtic bootean hasSuberitted - folse; public void subeitcoursenork \& f hassubmitted - true; My Body Is Not An Object The body of this class defines the operations we can perform on this object. Once we have the class body written in a Java file, we can use it in any other code in the same directory. To use classes we must first instontiate these as objects otherwise we will get an exception. We do this in exactly the same manner as we declared primitive types in previous labs e.g. Student alice - new Student ; If Instantioting a class System, out.ppintln ("Alice Submitted coursenork: " olice. hassubenitted) atice. submit coursecorkC Systea,out,printin("Alice Subeitted Coursenork: " ollice. hassubeitted) This is a bit of a boring class currently, so let's add some functionality. Lab: Objects (2/3) What's in a Name? Let's change the given starter code a bit, and add more attributes as follows. - Most students have a name, so at the top of the class add a variable - Similarly, add a attribute called - an attribute called - an attribute called - and an attribute called - Finally, an to the class to keep track of the students score, called initially equal to 0 . Now add a new method called "updateGrade", that takes an parameter (and returns nothing = that can be used to set a student's grade. After each of the assignments, the lecturer will update the students score with a method which will return a void called , which will add the students grade for that assignment to their grade: The automarker will be using these terms, so make sure to follow this specification closely (capitalisation matters)! Gather Round Lecturers will typically store their students grades on an abacus, but some progressive types have started using software to do this for them. We often deal with lots of objects of the same type when building real world software, and Java makes it easy for us to bundle these together into Arrays. Arrays in Java allow us to structure our code and saves us from creating lots of variables (which looks messy). Lets start creating some software to simulate a virtual classroom, similar to the one you're virtually interacting with right now! create a new file where we will store the code for our virtual virtual classroom in the form of a new class called For now well keep it simple and write a with a single method, and all this program will do is help the lecturer calculate the class average. The Lecturer has all the students grades written down so needs to enter them one by one into the terminal, and will then expect to have the average returned to them. To do this use the method to first read in the number of students, then use a loop to read in the grade of each student. Once all the 5 have had their grades read in, use another for loop to compute the class average, and print this to the terminal. This output should display at most 2 digits after the decimal point. Example Usages: 5) javo Viather Example Usages: 5. java vGather Mon Mony Students in Closs? Enter a grode: 1 Enter a grades Enter a orode: (3.0. How Mony Students In Class? Enter a grade: Enter:a grode: Hon Mony Students in Closs? 33 Enter a arade: Iinter a grode: Enter: yeade: 4,33 . Hint: To read in an integer and create an array of size the syntax is: Hint: There are several ways to print a double only up to a given precision. One easy way is to print at most the last 2 digits after the decimal point is to multiply by round to the next integer, then divide by Use here? pubUe class student \{ public boolean hasSubmitted = Hilit; pubtuc votd subaitCoursework() i hasSubmitted =

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Readings In Database Systems

Authors: Michael Stonebraker

2nd Edition

0934613656, 9780934613651

More Books

Students also viewed these Databases questions