![missalawode28](/avatars/8126.jpg)
missalawode28
18.08.2020 •
Computers and Technology
JAVA:
Assign courseStudent's name with Smith, age with 20, and ID with 9999. Use the print member method and a separate println statement to output courseStudents's data. Sample output from the given program:
Name: Smith, Age: 20, ID: 9999
// Code from file PersonData.java
public class PersonData {
private int ageYears;
private String lastName;
public void setName(String userName) {
lastName = userName;
return;
}
Solved
Show answers
More tips
- S Science and Technology Why is there no gravity on other planets?...
- F Food and Cooking Deflope: What is it and how does it work?...
- B Business and Finance How to Create a Business Plan? Your Ultimate Guide...
- F Food and Cooking Unusually Delicious Shashlik - Follow the Etiquette of Proper Preparation!...
- C Computers and Internet Make Easy Accessible Screenshots on iPad in Just a Few Minutes...
- T Travel and tourism Lost in the Catacombs: What to Do?...
- F Family and Home Protect Your Home or Apartment from Pesky Ants...
- H Health and Medicine How to Treat Styes: Causes, Symptoms, and Home Remedies...
- L Legal consultation What Documents Are Required for a Russian Passport?...
- F Family and Home How to Properly Use a Water Level?...
Answers on questions: Computers and Technology
- F French Select the appropriate definite or indefinite article for each noun. 1. des amie 2. la étudiants 3. acteur 4. • chanteuses 5. v bibliothèque 6. 7 examen 7. bureaux 8. animal...
- H Health HELP PLEASE ASAP Why is your personal health important to your community? A. When you make good health choices, you enable others to make poor health choices. B. When your...
- H History ¿Qué procesos de imperialismo y colonialismo se está presentando en el mundo del hoy día?...
- M Mathematics Which number has the greatest absolute value? A)0 B)−18 C)−31 D)−44...
- B Business g If you borrow $12,000 with an interest rate of 4 percent, to be repaid in five equal yearly payments at the end of the next five years, what would be the amount of each payment?...
- M Mathematics On a coordinate plane, a straight red line with a positive slope, labeled g of x, crosses the x-axis at (negative 6, 0) and the y-axis at (0, 6). A straight blue line with...
- P Physics Unless indicated otherwise, assume the speed of sound in air to be v = 344 m/s.A violinist is tuning her instrument to concert A (440 Hz). She plays the note while listening...
- B Business An estate is transferred with the stipulation that alcohol will never be consumed on the premises or the seller will take back the property. This kind of estate is a...
- M Mathematics Order each row from least to greatest please! (10 points)...
- M Mathematics Nx+1= x + 2? Im confused i think there is no solution...
Ответ:
Here is the JAVA program:
public class {
public static void main (String [] args) { //start of main function
StudentData courseStudent = new StudentData(); //creates an object of StudentData class named courseStudent
courseStudent.setName("Smith"); //assign courseStudent's name with Smith using courseStudent object and by calling the mutator method setName
courseStudent.setAge(20); //assign courseStudent's age with 20 using courseStudent object and by calling the mutator method setAge
courseStudent.setID(9999); //assign courseStudent's ID with 9999 using courseStudent object and by calling the mutator method setID
courseStudent.printAll(); //calls printAll member method using courseStudent object. This will print the name and age
System.out.println(", ID: " + courseStudent.getID()); //println statement to print the ID by calling accessor method getID of StudentData class
return;}}
Explanation:
Here is the complete program:
PersonData.java
public class PersonData {
private int ageYears;
private String lastName;
public void setName(String userName) {
lastName = userName;
return; }
public void setAge(int numYears) {
ageYears = numYears;
return; }
public void printAll() {
System.out.print("Name: " + lastName);
System.out.print(", Age: " + ageYears);
return; }}
StudentData.java
public class StudentData extends PersonData {
private int idNum;
public void setID(int studentId) {
idNum = studentId;
return; }
public int getID() {
return idNum; } }
.java
public class {
public static void main (String [] args) {
StudentData courseStudent = new StudentData();
courseStudent.setName("Smith");
courseStudent.setAge(20);
courseStudent.setID(9999);
courseStudent.printAll();
System.out.println(", ID: " + courseStudent.getID());
return;}}
Here the courseStudent is the object of class StudentData
new keyword is used to create and object of a class
This object is used to access the methods of class
Note that the StudentData class is the sub class of PersonData class
The object courseStudent first accesses the mutator method setName of class PersonData to set the name (lastName) as Smith.
Next it accesses the mutator method setAge of class PersonData to set the age (ageYears) to 20
Then courseStudent accesses the mutator method setID of class StudentData to set the ID (idNum) to 9999.
Then the method printAll() of PersonData class is called using courseStudent object. This method has two print statements i.e.
System.out.print("Name: " + lastName);
System.out.print(", Age: " + ageYears);
So these two statement are printed on the output screen. They display the name and age i.e. Smith and 20 with a comma between them.
Next we have to display the ID too so we use this statement:
System.out.println(", ID: " + courseStudent.getID());
The above print statement calls getID accessor method of StudentData class to get the ID and display it on the screen.
Hence the output of the above program is:
Name: Smith, Age: 20, ID: 9999
Ответ:
Step-by-step explanation:
a^2+b^2=c^2
3^2+4^2=c^2
9+16=c^2
25=c^2
5=c