Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i please help me with part A I'm new and I'm lost In this lab, you are going to create a Student class. Think about

image text in transcribed

i

image text in transcribed

image text in transcribed

please help me with part A I'm new and I'm lost

In this lab, you are going to create a Student class. Think about (1) things that a university needs to know about students (these are its data attributes or characteristics that in object oriented programming are stored in what are called instance variables [We'll discuss why they're called instance variables later.]) and (2) things that a student needs to be able to do (these are called methods). Instance variables and methods are the two main characteristics of every class like the Student class you are getting ready to create. 1) Part A: Create a Student class and add instance variables 2) Part B: Add constructors to Student class 3) Part C: Add getters and setters to Student class 4) Part D: Add more fields and methods to Student class 5) Part E: Add Javadoc comments to Student class 6) Part F: Draw UML diagram for Student class Part A: Create a Student class and add instance variables 1) Each instance variable is defined by its datatype and a unique name. Because instance variables are most often things, we generally use nouns as instance variable names. Note that in Java the convention for variable names is what's known as camel case. That is, the first word of the variable identifier is all lower-case letters. If multiple words are used in the identifier, the first character of every word after the first is upper case (like the hump on a camel). For example, a variable to hold your first name might have an identifier like firstName. A variable for the street of your address might just be street because it's only one word. A variable to hold your favorite movie might be named myFavoriteMovie. The table below shows the instance variable tables in the Student class. Student Class Instance Variables Instance Variable Description First name Middle Initial Last Name Student ID Age Lives on campus Java Datatype String char String String int boolean Java Identifier firstName middleInitial lastName studentId age liveOnCampus 2) First create a java project in your chosen IDE. 3) Create a driver/main class. This will contain the main method where you will manually test your program. 4) Create a class named Student. The contents of the Student class are everything from the right of the opening curly brace that follows the word Student to the left of the closing curly brace two lines below. Those two curly braces define what's known as a block. Everything inside this block defines the Student class. One thing to get used to is that many Java constructs come in opening and closing pairs like parentheses ( ) and curly braces { }. Having a starting curly brace without a corresponding closing one or a closing one without the corresponding starting one will cause an error. It's easy to do when writing large amounts of code. To avoid this, if I type an opening parenthesis or curly brace I IMMEDIATELY type the corresponding closing one (most heavier IDE's do this for you). Then I set my cursor back between the two and carry on. Mark my words, you're going to hate yourself when you get one of these errors after you've written a couple of hundred lines of code and have to find the single parenthesis or curly brace that's not matched properly. 5) Now start adding instance variable definitions to your Student class. Click the blank line below public class Student {. Type one line of code for each of the Instance variables in your instance variables table above. In Java, variables defined at the class level are called fields. To enter a field definition, type the datatype first then the identifier then a semicolon. For example, the definition for the firstName field would look like this: 8 9 @author Bruce 10 11 12 13 14 15 public class Student { String firstName; } 6) Continue this until all your fields have been defined. 7) To create an object of the Student class, type the following inside your driver's main method: Student hakim = new Student (); 8) Student () is a special method called a constructor. Constructors are a required part of every class. Their purpose is to initialize the instance variables of an object as soon as it's created. There are a couple of important things to know about constructors: . . They always have exactly the same name as the class. That's how you know they're a constructor. They don't have a return type. (void is a return type) Constructors are required but you'll notice there's no method in our Student class named Student. That's because Java includes what's known as a default constructor. You can write . your own constructors (you will do so in Part B) but if you don't, Java pretends you did and uses its own default constructor. Note that default constructor does not take any arguments. 9) Print out the instance variables of hakim by typing the following inside the main method: System.out.println (hakim.firstName); System.out.println(hakim.middleInitial); System.out.println (hakim.lastName); System.out.println (hakim. StudentId); System.out.println (hakim.age); System.out.println (hakim.livesOnCampus); 10) Check the output window, and you will see that all of these instance variables are printed with fault value. This is use the default constructor initializes each field to default value: String type is null, char type is '\0', numeric type is 0, and boolean type is false. In the next step, you are going to add a non-default constructor to the Student class

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

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

3rd Edition

0760049041, 978-0760049044

More Books

Students also viewed these Databases questions