SlideShare a Scribd company logo
1 of 6
Download to read offline
Assignment 6 as a reference
public class ArrExample {
private int[] arr;
public ArrExample(int length) {
this.arr = new int[length];
}
public ArrExample(int[] arr) {
this.arr = arr;
}
public void arrDisplay() {
if (arr.length == 0) {
System.out.println("{}");
} else {
System.out.print("{");
System.out.print(arr[0]);
for (int i = 1; i < arr.length; i++) {
System.out.print("," + arr[i]);
}
System.out.println("}");
}
}
public int arrTot() {
int total = 0;
for (int i = 0; i < arr.length; i++) {
total += arr[i];
}
return total;
}
public int arrMax() {
int maxSeen = arr.length == 0 ? 0 : arr[0];
for (int i = 1; i < arr.length; i++) {
if (arr[i] > maxSeen) {
maxSeen = arr[i];
}
}
return maxSeen;
}
public int arrMin() {
int minSeen = arr.length == 0 ? 0 : arr[0];
for (int i = 1; i < arr.length; i++) {
if (arr[i] < minSeen) {
minSeen = arr[i];
}
}
return minSeen;
}
public int arrRange() {
return arrMax() - arrMin();
}
public double arrAverage() {
return (double) arrTot() / arr.length;
}
public void arrClip(int clipValue) {
for (int i = 0; i < arr.length; i++) {
if (arr[i] > clipValue) {
arr[i] = clipValue;
}
}
}
public int arrfindCount(int value) {
int count = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] == value) {
count++;
}
}
return count;
}
public static void testData() {
int[] arr0 = { -2, -1 };
int[] arr1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int[] arr2 = { 2, 4, 6, 8, 10, 12, 14, 16, 7, 6, 22, 8, 9, 16, 5, 2, 7, 8, 12, 2, 0, 14, 17, 19, 22 };
ArrExample A1 = new ArrExample(arr0);
ArrExample A2 = new ArrExample(arr1);
ArrExample A3 = new ArrExample(arr2);
A1.arrDisplay();
A2.arrDisplay();
A3.arrDisplay();
System.out.println("Total of A1: " + A1.arrTot());
System.out.println("Total of A2: " + A2.arrTot());
}
1)a) This assignment builds on Assignment 6. In Assignment 6, your arrInt class always used a
completely
filled array. But what if you add values only one at a time, and dont know how many items you will
have
when you are done? In this assignment, you will create an array bffr without filling it right away.
That
means that you have an array but most of the values are meaningless zeroes. At the beginning, all
of the
values are meaningless zeroes. Only as you begin putting values into the array do some of the
elements
become meaningful. The important idea to capture, is that the size or capacity of the array, and
the
number of values in the array (or count), are two separate numbers. Start a project, as always.
Create
your main class with the same name as the project. Then create a new class called
BffrIntFirstname
(Use your first name ). The BffrIntFirstname class will have two private variables: an array of ints
(private int bffr[];), and a count of the number of values that have been added, called count. The
class
should have two constructors. The constructor that takes no arguments should create an array of
8 ints
(using a constant called BFFR_SZ) for initializing the array: bffr = new int[BFFR_SZ];. The other
constructor takes an integer argument and uses that to create the initial buffer array of that size.
Both
constructors should set the count to 0.
The BffrIntFirstname class should have the following methods,
addRand( which adds a random two digit integer to the array using the java.util.Random and not
Math.random),
getCount (which is a getter to return the current count), and
printToScreen (which works like the printLiteral method in assignment 6, except that it only
prints as many values as have been added).
Hint: The key to making addRand()method work is that when the array is empty (nothing yet
added), it
puts the first value in location 0, which would be bffr[0] = value;. After getting its first value, the
count
should be incremented so it becomes 1. Then next time addRand()is called to add a value, that
value
should be put in location 1: bffr[1] = value; and the count is incremented as before, and becomes
2. We
cannot write the actual array index in the assignment, because each time we add a new value,
that
index must be one bigger than the array index we used before. But notice that the array index that
we
want to use is the same value as the count before the new value is added. In other words, when
the
count is 0, the next value goes in location 0. When the count is 1, the next value goes in location
1.
When the count is 7, the next value will go in location 7. So the addRand() method should use the
count
variable as the array index for the new value, and then increment it after the new value has been
added
to the buffer array:
bffr[count] = value;
count++;
As a last step, make the BffrIntFirstname more robust and safe from buffer overflow. Make the
addRand method compare the count to the buffer length, first. If count is greater than or equal
to the length, no value is added. The return type should be changed to Boolean (boolean) so
that it returns true when the value is added, and false when it is not, due to having reached the
end of the buffer.
1)b)
Temperature as a Class Assignment
The goal of this assignment is to better acquaint you with using an object in the design of a
solution.
Your task is to create an application that asks the user to enter a temperature and the type of units
of
that temperature. It then reports the temperature in 3 different units. The application should use a
class called TmpFirstname that stores a single temperature, but provides functions to set and get
that
temperature using any of the three units: Celsius, Fahrenheit, or Kelvin. In the code for
getTmpFromUser, given below, you need to use the three set functions. Your job is to implement
the
TmpFirstname class, and then write a main function that uses the three get functions to complete
this
task. I have included a separate static function header(not part of the TmpFirstname class), called
getTmpFromUser(), that takes the TmpFirstname object as its argument. Put this function in the
same
file where you put main(). The getTmpFromUser function prompts the user for the temperature
and the
type of units and reads them in. It also detects if the user gives bad input and provides the user
with an
opportunity to try again. When the getTmpFromUser function returns, the tmpfirstname object
which
was passed as an argument should contain a temperature. In your main function, call the
getTmpFromUser function, and then, using the three get functions of the tmpfirstname object,
report
the temperature in each of the three units. If written correctly, the output should look exactly as
shown
below.
Output on console:
I will ask you for a temperature and its units. Use C for Celsius, F for Fahrenheit or K for
Kelvin.
Enter a Temperature followed by the units: 0 K
The temperature in Celsius is -273.15
The temperature in Fahrenheit is -459.67
The temperature in Kelvin is 0.0
Please read the following scenario to make sure you understand what is meant by an abstract
temperature. Imagine this scenario. I give my Temperature object to John to take the temperature.
He
is comfortable using Fahrenheit and his thermometer reads in Fahrenheit. So he sets the
temperature in
Fahrenheit. Then I give the same Temperature object to Helga. Helga is accustomed to Celsius,
and her
lab equipment uses Celsius. So she uses the getCelsius to get the temperature that John just
measured.
In addition, she wants to compute something that involves the temperature, but the formula she
has is
written to use Kelvin. So she gets the same temperature for her formula, but this time she gets it in
Kelvin. Now supposing the formula tells her that the temperature they want is a little different, but
they
only have it in Kelvin. So she sets that temperature in Kelvin and sends it back to John. John looks
at
what that is in Fahrenheit so he can work on getting the right temperature. The point is that the
object
is THE TEMPERATURE and having a Temperature object makes it possible for anybody to see
THE
TEMPERATURE without having to know anything about who set it or how they set it. We call that
an
ABSTRACTION. It gives us what we need, while hiding unnecessary details from those who use it.
Yes,
there is conversion involved. But that is just part of the job of hiding the detail of which units are
used
inside the class for storage. In other words, there is no "convert" function. Conversion is just what
we
may or may not to do in a get or set in order to make it work as an abstraction.
For the TempFirstname class, you have to decide which type of units to use for the private
storage, and
then provide getters and setters with conversions to and from that value for the other choices. You
can
find the conversion formulas by searching them (e.g. formula for fahrenheit to celsius conversion).
// Function: getTmpFromUser
// Purpose: Prompt user for a temperature and put it in the argument object
// Parameter: tempObject is a TmpFirstname object
// Returns: nothing
// public static void getTmpFromUser(TmpFirstname tmpObject)
Develop this function onto the end of your main file (the one where you have main()).In your main,
declare an object of your Temperature class, call getTmpFromUser with your object, and then
write
three lines with sysout to output the lines shown in the console output above.
You can use the same main to test BffrIntFirstname class also.
Ty for your help!!!

More Related Content

Similar to Assignment 6 as a reference public class ArrExample pr.pdf

Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfinfo309708
 
Arrays in programming
Arrays in programmingArrays in programming
Arrays in programmingTaseerRao
 
Ecs 10 programming assignment 4 loopapalooza
Ecs 10 programming assignment 4   loopapaloozaEcs 10 programming assignment 4   loopapalooza
Ecs 10 programming assignment 4 loopapaloozaJenniferBall44
 
Ecet 370 Education Organization -- snaptutorial.com
Ecet 370   Education Organization -- snaptutorial.comEcet 370   Education Organization -- snaptutorial.com
Ecet 370 Education Organization -- snaptutorial.comDavisMurphyB81
 
Chapter 7.1
Chapter 7.1Chapter 7.1
Chapter 7.1sotlsoc
 
C++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersC++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersANUSUYA S
 
Java conceptual learning material
Java conceptual learning materialJava conceptual learning material
Java conceptual learning materialArthyR3
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework HelpC++ Homework Help
 
C++ Function
C++ FunctionC++ Function
C++ FunctionHajar
 
Programming basics
Programming basicsProgramming basics
Programming basicsillidari
 
First C++ code written... I think its quite efficient with all the.pdf
First C++ code written... I think its quite efficient with all the.pdfFirst C++ code written... I think its quite efficient with all the.pdf
First C++ code written... I think its quite efficient with all the.pdfankit482504
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxamrit47
 

Similar to Assignment 6 as a reference public class ArrExample pr.pdf (20)

Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
 
Arrays in programming
Arrays in programmingArrays in programming
Arrays in programming
 
Ecs 10 programming assignment 4 loopapalooza
Ecs 10 programming assignment 4   loopapaloozaEcs 10 programming assignment 4   loopapalooza
Ecs 10 programming assignment 4 loopapalooza
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
Ecet 370 Education Organization -- snaptutorial.com
Ecet 370   Education Organization -- snaptutorial.comEcet 370   Education Organization -- snaptutorial.com
Ecet 370 Education Organization -- snaptutorial.com
 
Chapter 7.1
Chapter 7.1Chapter 7.1
Chapter 7.1
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
C++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersC++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about Pointers
 
Java conceptual learning material
Java conceptual learning materialJava conceptual learning material
Java conceptual learning material
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework Help
 
Python_Module_2.pdf
Python_Module_2.pdfPython_Module_2.pdf
Python_Module_2.pdf
 
Lecture 8
Lecture 8Lecture 8
Lecture 8
 
C++ Function
C++ FunctionC++ Function
C++ Function
 
Programming basics
Programming basicsProgramming basics
Programming basics
 
C++ Homework Help
C++ Homework HelpC++ Homework Help
C++ Homework Help
 
Unit iii
Unit iiiUnit iii
Unit iii
 
Functions
FunctionsFunctions
Functions
 
First C++ code written... I think its quite efficient with all the.pdf
First C++ code written... I think its quite efficient with all the.pdfFirst C++ code written... I think its quite efficient with all the.pdf
First C++ code written... I think its quite efficient with all the.pdf
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
 
Savitch ch 04
Savitch ch 04Savitch ch 04
Savitch ch 04
 

More from kksrivastava1

Assume that there exists a bestfirst search algorithm in wh.pdf
Assume that there exists a bestfirst search algorithm in wh.pdfAssume that there exists a bestfirst search algorithm in wh.pdf
Assume that there exists a bestfirst search algorithm in wh.pdfkksrivastava1
 
Assume that there are 5 processes P0 through P4 and 4 type.pdf
Assume that there are 5 processes P0 through P4 and 4 type.pdfAssume that there are 5 processes P0 through P4 and 4 type.pdf
Assume that there are 5 processes P0 through P4 and 4 type.pdfkksrivastava1
 
Assume that there are 5 processes PO through P4 and 4 type.pdf
Assume that there are 5 processes PO through P4 and 4 type.pdfAssume that there are 5 processes PO through P4 and 4 type.pdf
Assume that there are 5 processes PO through P4 and 4 type.pdfkksrivastava1
 
Assume that SLL is a singly linked list with the head node .pdf
Assume that SLL is a singly linked list with the head node .pdfAssume that SLL is a singly linked list with the head node .pdf
Assume that SLL is a singly linked list with the head node .pdfkksrivastava1
 
Assume that i is in t0 register x is in f0 register the .pdf
Assume that i is in t0 register x is in f0 register the .pdfAssume that i is in t0 register x is in f0 register the .pdf
Assume that i is in t0 register x is in f0 register the .pdfkksrivastava1
 
Assume that a simple random sample has been selected and tes.pdf
Assume that a simple random sample has been selected and tes.pdfAssume that a simple random sample has been selected and tes.pdf
Assume that a simple random sample has been selected and tes.pdfkksrivastava1
 
Assume that a security model is needed to protect informatio.pdf
Assume that a security model is needed to protect informatio.pdfAssume that a security model is needed to protect informatio.pdf
Assume that a security model is needed to protect informatio.pdfkksrivastava1
 
Assume that 352 of people have sleepwalked Assume that in.pdf
Assume that 352 of people have sleepwalked Assume that in.pdfAssume that 352 of people have sleepwalked Assume that in.pdf
Assume that 352 of people have sleepwalked Assume that in.pdfkksrivastava1
 
assume Assume fn4n01gn10lognhn2npn3logn i.pdf
assume Assume fn4n01gn10lognhn2npn3logn i.pdfassume Assume fn4n01gn10lognhn2npn3logn i.pdf
assume Assume fn4n01gn10lognhn2npn3logn i.pdfkksrivastava1
 
Assume an organization is planning to move a significant IT .pdf
Assume an organization is planning to move a significant IT .pdfAssume an organization is planning to move a significant IT .pdf
Assume an organization is planning to move a significant IT .pdfkksrivastava1
 
Assume a singly linkedlist List class of nodes sorted by .pdf
Assume a singly linkedlist List class of nodes sorted by .pdfAssume a singly linkedlist List class of nodes sorted by .pdf
Assume a singly linkedlist List class of nodes sorted by .pdfkksrivastava1
 
Assume a firm has earnings before depreciation and taxes of .pdf
Assume a firm has earnings before depreciation and taxes of .pdfAssume a firm has earnings before depreciation and taxes of .pdf
Assume a firm has earnings before depreciation and taxes of .pdfkksrivastava1
 
Assignment4 Assignment 4 Hashtables In this assignment we w.pdf
Assignment4 Assignment 4 Hashtables In this assignment we w.pdfAssignment4 Assignment 4 Hashtables In this assignment we w.pdf
Assignment4 Assignment 4 Hashtables In this assignment we w.pdfkksrivastava1
 
Assignment Overview Over twothirds of Americans are conside.pdf
Assignment Overview Over twothirds of Americans are conside.pdfAssignment Overview Over twothirds of Americans are conside.pdf
Assignment Overview Over twothirds of Americans are conside.pdfkksrivastava1
 
Associativity Left to right 1 Show the order of evaluatio.pdf
Associativity Left to right 1 Show the order of evaluatio.pdfAssociativity Left to right 1 Show the order of evaluatio.pdf
Associativity Left to right 1 Show the order of evaluatio.pdfkksrivastava1
 
ASSIGNMENT OI a The IASBs Framework for the Preparation a.pdf
ASSIGNMENT OI a The IASBs Framework for the Preparation a.pdfASSIGNMENT OI a The IASBs Framework for the Preparation a.pdf
ASSIGNMENT OI a The IASBs Framework for the Preparation a.pdfkksrivastava1
 
Assignment is a case essay and requires you to obtain suffic.pdf
Assignment is a case essay and requires you to obtain suffic.pdfAssignment is a case essay and requires you to obtain suffic.pdf
Assignment is a case essay and requires you to obtain suffic.pdfkksrivastava1
 
Assignment 4 Class Petromyzontida 10 List three features o.pdf
Assignment 4 Class Petromyzontida 10 List three features o.pdfAssignment 4 Class Petromyzontida 10 List three features o.pdf
Assignment 4 Class Petromyzontida 10 List three features o.pdfkksrivastava1
 
Assign the ICD10CM codes to diagnosis and conditions and.pdf
Assign the ICD10CM codes to diagnosis and conditions and.pdfAssign the ICD10CM codes to diagnosis and conditions and.pdf
Assign the ICD10CM codes to diagnosis and conditions and.pdfkksrivastava1
 
Assigned Topic Alzheimers disease Case study Create a b.pdf
Assigned Topic Alzheimers disease Case study  Create a b.pdfAssigned Topic Alzheimers disease Case study  Create a b.pdf
Assigned Topic Alzheimers disease Case study Create a b.pdfkksrivastava1
 

More from kksrivastava1 (20)

Assume that there exists a bestfirst search algorithm in wh.pdf
Assume that there exists a bestfirst search algorithm in wh.pdfAssume that there exists a bestfirst search algorithm in wh.pdf
Assume that there exists a bestfirst search algorithm in wh.pdf
 
Assume that there are 5 processes P0 through P4 and 4 type.pdf
Assume that there are 5 processes P0 through P4 and 4 type.pdfAssume that there are 5 processes P0 through P4 and 4 type.pdf
Assume that there are 5 processes P0 through P4 and 4 type.pdf
 
Assume that there are 5 processes PO through P4 and 4 type.pdf
Assume that there are 5 processes PO through P4 and 4 type.pdfAssume that there are 5 processes PO through P4 and 4 type.pdf
Assume that there are 5 processes PO through P4 and 4 type.pdf
 
Assume that SLL is a singly linked list with the head node .pdf
Assume that SLL is a singly linked list with the head node .pdfAssume that SLL is a singly linked list with the head node .pdf
Assume that SLL is a singly linked list with the head node .pdf
 
Assume that i is in t0 register x is in f0 register the .pdf
Assume that i is in t0 register x is in f0 register the .pdfAssume that i is in t0 register x is in f0 register the .pdf
Assume that i is in t0 register x is in f0 register the .pdf
 
Assume that a simple random sample has been selected and tes.pdf
Assume that a simple random sample has been selected and tes.pdfAssume that a simple random sample has been selected and tes.pdf
Assume that a simple random sample has been selected and tes.pdf
 
Assume that a security model is needed to protect informatio.pdf
Assume that a security model is needed to protect informatio.pdfAssume that a security model is needed to protect informatio.pdf
Assume that a security model is needed to protect informatio.pdf
 
Assume that 352 of people have sleepwalked Assume that in.pdf
Assume that 352 of people have sleepwalked Assume that in.pdfAssume that 352 of people have sleepwalked Assume that in.pdf
Assume that 352 of people have sleepwalked Assume that in.pdf
 
assume Assume fn4n01gn10lognhn2npn3logn i.pdf
assume Assume fn4n01gn10lognhn2npn3logn i.pdfassume Assume fn4n01gn10lognhn2npn3logn i.pdf
assume Assume fn4n01gn10lognhn2npn3logn i.pdf
 
Assume an organization is planning to move a significant IT .pdf
Assume an organization is planning to move a significant IT .pdfAssume an organization is planning to move a significant IT .pdf
Assume an organization is planning to move a significant IT .pdf
 
Assume a singly linkedlist List class of nodes sorted by .pdf
Assume a singly linkedlist List class of nodes sorted by .pdfAssume a singly linkedlist List class of nodes sorted by .pdf
Assume a singly linkedlist List class of nodes sorted by .pdf
 
Assume a firm has earnings before depreciation and taxes of .pdf
Assume a firm has earnings before depreciation and taxes of .pdfAssume a firm has earnings before depreciation and taxes of .pdf
Assume a firm has earnings before depreciation and taxes of .pdf
 
Assignment4 Assignment 4 Hashtables In this assignment we w.pdf
Assignment4 Assignment 4 Hashtables In this assignment we w.pdfAssignment4 Assignment 4 Hashtables In this assignment we w.pdf
Assignment4 Assignment 4 Hashtables In this assignment we w.pdf
 
Assignment Overview Over twothirds of Americans are conside.pdf
Assignment Overview Over twothirds of Americans are conside.pdfAssignment Overview Over twothirds of Americans are conside.pdf
Assignment Overview Over twothirds of Americans are conside.pdf
 
Associativity Left to right 1 Show the order of evaluatio.pdf
Associativity Left to right 1 Show the order of evaluatio.pdfAssociativity Left to right 1 Show the order of evaluatio.pdf
Associativity Left to right 1 Show the order of evaluatio.pdf
 
ASSIGNMENT OI a The IASBs Framework for the Preparation a.pdf
ASSIGNMENT OI a The IASBs Framework for the Preparation a.pdfASSIGNMENT OI a The IASBs Framework for the Preparation a.pdf
ASSIGNMENT OI a The IASBs Framework for the Preparation a.pdf
 
Assignment is a case essay and requires you to obtain suffic.pdf
Assignment is a case essay and requires you to obtain suffic.pdfAssignment is a case essay and requires you to obtain suffic.pdf
Assignment is a case essay and requires you to obtain suffic.pdf
 
Assignment 4 Class Petromyzontida 10 List three features o.pdf
Assignment 4 Class Petromyzontida 10 List three features o.pdfAssignment 4 Class Petromyzontida 10 List three features o.pdf
Assignment 4 Class Petromyzontida 10 List three features o.pdf
 
Assign the ICD10CM codes to diagnosis and conditions and.pdf
Assign the ICD10CM codes to diagnosis and conditions and.pdfAssign the ICD10CM codes to diagnosis and conditions and.pdf
Assign the ICD10CM codes to diagnosis and conditions and.pdf
 
Assigned Topic Alzheimers disease Case study Create a b.pdf
Assigned Topic Alzheimers disease Case study  Create a b.pdfAssigned Topic Alzheimers disease Case study  Create a b.pdf
Assigned Topic Alzheimers disease Case study Create a b.pdf
 

Recently uploaded

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 

Recently uploaded (20)

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 

Assignment 6 as a reference public class ArrExample pr.pdf

  • 1. Assignment 6 as a reference public class ArrExample { private int[] arr; public ArrExample(int length) { this.arr = new int[length]; } public ArrExample(int[] arr) { this.arr = arr; } public void arrDisplay() { if (arr.length == 0) { System.out.println("{}"); } else { System.out.print("{"); System.out.print(arr[0]); for (int i = 1; i < arr.length; i++) { System.out.print("," + arr[i]); } System.out.println("}"); } } public int arrTot() { int total = 0; for (int i = 0; i < arr.length; i++) { total += arr[i]; } return total; } public int arrMax() { int maxSeen = arr.length == 0 ? 0 : arr[0]; for (int i = 1; i < arr.length; i++) { if (arr[i] > maxSeen) { maxSeen = arr[i]; } } return maxSeen; } public int arrMin() { int minSeen = arr.length == 0 ? 0 : arr[0]; for (int i = 1; i < arr.length; i++) { if (arr[i] < minSeen) { minSeen = arr[i];
  • 2. } } return minSeen; } public int arrRange() { return arrMax() - arrMin(); } public double arrAverage() { return (double) arrTot() / arr.length; } public void arrClip(int clipValue) { for (int i = 0; i < arr.length; i++) { if (arr[i] > clipValue) { arr[i] = clipValue; } } } public int arrfindCount(int value) { int count = 0; for (int i = 0; i < arr.length; i++) { if (arr[i] == value) { count++; } } return count; } public static void testData() { int[] arr0 = { -2, -1 }; int[] arr1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int[] arr2 = { 2, 4, 6, 8, 10, 12, 14, 16, 7, 6, 22, 8, 9, 16, 5, 2, 7, 8, 12, 2, 0, 14, 17, 19, 22 }; ArrExample A1 = new ArrExample(arr0); ArrExample A2 = new ArrExample(arr1); ArrExample A3 = new ArrExample(arr2); A1.arrDisplay(); A2.arrDisplay(); A3.arrDisplay(); System.out.println("Total of A1: " + A1.arrTot()); System.out.println("Total of A2: " + A2.arrTot()); } 1)a) This assignment builds on Assignment 6. In Assignment 6, your arrInt class always used a completely filled array. But what if you add values only one at a time, and dont know how many items you will
  • 3. have when you are done? In this assignment, you will create an array bffr without filling it right away. That means that you have an array but most of the values are meaningless zeroes. At the beginning, all of the values are meaningless zeroes. Only as you begin putting values into the array do some of the elements become meaningful. The important idea to capture, is that the size or capacity of the array, and the number of values in the array (or count), are two separate numbers. Start a project, as always. Create your main class with the same name as the project. Then create a new class called BffrIntFirstname (Use your first name ). The BffrIntFirstname class will have two private variables: an array of ints (private int bffr[];), and a count of the number of values that have been added, called count. The class should have two constructors. The constructor that takes no arguments should create an array of 8 ints (using a constant called BFFR_SZ) for initializing the array: bffr = new int[BFFR_SZ];. The other constructor takes an integer argument and uses that to create the initial buffer array of that size. Both constructors should set the count to 0. The BffrIntFirstname class should have the following methods, addRand( which adds a random two digit integer to the array using the java.util.Random and not Math.random), getCount (which is a getter to return the current count), and printToScreen (which works like the printLiteral method in assignment 6, except that it only prints as many values as have been added). Hint: The key to making addRand()method work is that when the array is empty (nothing yet added), it puts the first value in location 0, which would be bffr[0] = value;. After getting its first value, the count should be incremented so it becomes 1. Then next time addRand()is called to add a value, that value should be put in location 1: bffr[1] = value; and the count is incremented as before, and becomes 2. We cannot write the actual array index in the assignment, because each time we add a new value, that index must be one bigger than the array index we used before. But notice that the array index that we want to use is the same value as the count before the new value is added. In other words, when the
  • 4. count is 0, the next value goes in location 0. When the count is 1, the next value goes in location 1. When the count is 7, the next value will go in location 7. So the addRand() method should use the count variable as the array index for the new value, and then increment it after the new value has been added to the buffer array: bffr[count] = value; count++; As a last step, make the BffrIntFirstname more robust and safe from buffer overflow. Make the addRand method compare the count to the buffer length, first. If count is greater than or equal to the length, no value is added. The return type should be changed to Boolean (boolean) so that it returns true when the value is added, and false when it is not, due to having reached the end of the buffer. 1)b) Temperature as a Class Assignment The goal of this assignment is to better acquaint you with using an object in the design of a solution. Your task is to create an application that asks the user to enter a temperature and the type of units of that temperature. It then reports the temperature in 3 different units. The application should use a class called TmpFirstname that stores a single temperature, but provides functions to set and get that temperature using any of the three units: Celsius, Fahrenheit, or Kelvin. In the code for getTmpFromUser, given below, you need to use the three set functions. Your job is to implement the TmpFirstname class, and then write a main function that uses the three get functions to complete this task. I have included a separate static function header(not part of the TmpFirstname class), called getTmpFromUser(), that takes the TmpFirstname object as its argument. Put this function in the same file where you put main(). The getTmpFromUser function prompts the user for the temperature and the type of units and reads them in. It also detects if the user gives bad input and provides the user with an opportunity to try again. When the getTmpFromUser function returns, the tmpfirstname object which was passed as an argument should contain a temperature. In your main function, call the getTmpFromUser function, and then, using the three get functions of the tmpfirstname object, report the temperature in each of the three units. If written correctly, the output should look exactly as shown
  • 5. below. Output on console: I will ask you for a temperature and its units. Use C for Celsius, F for Fahrenheit or K for Kelvin. Enter a Temperature followed by the units: 0 K The temperature in Celsius is -273.15 The temperature in Fahrenheit is -459.67 The temperature in Kelvin is 0.0 Please read the following scenario to make sure you understand what is meant by an abstract temperature. Imagine this scenario. I give my Temperature object to John to take the temperature. He is comfortable using Fahrenheit and his thermometer reads in Fahrenheit. So he sets the temperature in Fahrenheit. Then I give the same Temperature object to Helga. Helga is accustomed to Celsius, and her lab equipment uses Celsius. So she uses the getCelsius to get the temperature that John just measured. In addition, she wants to compute something that involves the temperature, but the formula she has is written to use Kelvin. So she gets the same temperature for her formula, but this time she gets it in Kelvin. Now supposing the formula tells her that the temperature they want is a little different, but they only have it in Kelvin. So she sets that temperature in Kelvin and sends it back to John. John looks at what that is in Fahrenheit so he can work on getting the right temperature. The point is that the object is THE TEMPERATURE and having a Temperature object makes it possible for anybody to see THE TEMPERATURE without having to know anything about who set it or how they set it. We call that an ABSTRACTION. It gives us what we need, while hiding unnecessary details from those who use it. Yes, there is conversion involved. But that is just part of the job of hiding the detail of which units are used inside the class for storage. In other words, there is no "convert" function. Conversion is just what we may or may not to do in a get or set in order to make it work as an abstraction. For the TempFirstname class, you have to decide which type of units to use for the private storage, and then provide getters and setters with conversions to and from that value for the other choices. You can find the conversion formulas by searching them (e.g. formula for fahrenheit to celsius conversion).
  • 6. // Function: getTmpFromUser // Purpose: Prompt user for a temperature and put it in the argument object // Parameter: tempObject is a TmpFirstname object // Returns: nothing // public static void getTmpFromUser(TmpFirstname tmpObject) Develop this function onto the end of your main file (the one where you have main()).In your main, declare an object of your Temperature class, call getTmpFromUser with your object, and then write three lines with sysout to output the lines shown in the console output above. You can use the same main to test BffrIntFirstname class also. Ty for your help!!!