Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is example: // Class example from book on Object locations -Comping objects (addresses) public class DemoA { public static void main(String[] args) { double

This is example:

// Class example from book on Object locations -Comping objects (addresses) public class DemoA { public static void main(String[] args) { double average; StudentA std1, std2, std3; //Declare objects of type Class // Build student objects using "default" constructor std1= new StudentA(); //Create new object belonging to Class // stores the reference (pointer) to that object in , System.out.println("std1 memory pointer in hex " + std1); std2= new StudentA(); //create second object belonging to Class // stores reference to that object in which is different for System.out.println("std2 memory address in hex " + std2); std3=null; System.out.println("std3 memory address in hex " + std3+" "); // outputs the Hex the point of std1 std3= std1; //copy the "reference" value (memory address) of std1 into std3 not eh Object itself System.out.println("std3 memory address in hex " + std3); // outputs the Hex the point of std1 // // add data in to object and std1.name="Joe"; std2.name="Bill"; System.out.println("std1 name " + std1.name); // Joe System.out.println("std2 name " + std2.name); // Bill System.out.println("std3 name " + std3.name); // Joe again // Arrays in Student class System.out.println("array in class student std1 "+std1.testArray ); System.out.println("array in class student std2 "+std2.testArray ); System.out.println("array in class student std3 "+std3.testArray ); average= std1.getAverage(); // "call" method in class Student System.out.println(std1.name +" average " + average); }// End Main }//End Class

problem start right here:

In class Exercise 5 Student Class

// Using the in class example <DemoA> for the main routine and <StudentA> as the class

// Create a new class <StudentB> & a new main class <DemoB> in separate .java file but in the same package. See Files, In Class Ex., Chapter 5: for demoA.java and StudnetA files

// 1) for <StudentB> Modify <StudentA> to add a new method <setGrads> to be able to

// randomly assign grads from 0. to 100. into the array in < StudentB > of length [4].

// (use Math.random)

// The existing method to find the average grade < getAverage > should still work.

// 2) Modify <DemoA> to create <DemoB>

// Hint (delete unnecessary existing print statement first)Then run to make sure it runs

// Create (build) 4 instances (objects) of <StudentB> std1std4

// Assign names for std1,std2,std3 and leave std4 as ,

// std1 will be your first and last together for Ex. Peter_Baker for me.

// std2,std3 can be any name ; AND assign std4 = std1, then output all 4 names

// 3) invoke < setGrads> which is in Class <StudentB> to set the random grades

// for all 4 instances (objects) you created std1,std2..

// For each instance built find the average grade using < getAverage> in <StudentB>

// 4) for all 4 instances you created output the student name & the grade to two decimals

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_2

Step: 3

blur-text-image_3

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

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions

Question

What are unit banks?

Answered: 1 week ago

Question

LO1 Understand risk management and identify its components.

Answered: 1 week ago