The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 5 Days Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
Please explain everything
Questions for a review. code and execute actual code for some of them.
1. What�s the value of z?
z = 21%4/3+ 6/7 +100*3 ; ?
2. Circle circ = new Circle(5, 3, 2);
What is Circle here? What is Circle(5,3,2) with (...) at the end ?
What is circ?
3. How do you distinguish between local variables( including parameters in a constructors ),
and a class member variable(also known as Instance variables)?
What if both variables names are the same?
4. Create following classes -PRACTICE WRITING THEM ON THE PAPER FROM YOUR MEMORY
public class Cat
{
private int weight;
private String color;
private int size;
Cat(int w, String c, int size)
{
weight=w;
color=c;
this.size=size; // (why "this." keyword is used here?)
}
}
public class Cheetah extends Cat
{
int maxSpeed;
Chetah(int w, String c, int size, in maxs)
{
super(w,c, size);
maxSpeed = maxs;
}
}
public class AllCatsTesting
{
public static void main(String[] args)
{
Cheetah smallFast=Cheetah(25, "Striped Yellow", 2, 100);
Cheetah fatSlow=Cheetah(45, "Spotted Brown", 5, 95);
Cheetah inGoodShape=Cheetah(35, "Striped and Spotted Orange", 3, 105);
}
}
Can instance variable be accessed directly?
Which class is a superclass, which is the subclass?
All Cheetahs are identical objects? Or are they different? If different, how different are they, in what way?
4. Which of the following is a correct Java syntax? (select one)
a 10<y && x<50 && z>5
b z<0 && 100<z<100
c x>1 && x<100 || (1< x < 10)
d (1 > x > 100) && ( y > 0)
5. Which is the diference between Scanner and File? What is a File with capital F?
Make a research on it.
6. Create a method that takes an array as a parameter, finds the max value in the array and returns it back.
Here is an array to test
int [] nums={3,5,3,1,0}
Create a method that takes an array as a parameter, finds the INDEX of the max value in the array and returns it back.
7. How the Static member variable (instance of a class) works? How many copies there are if you have 5 objects?
8. Which of the popular datatypes in Java is represented by a class (writen with a capital letter) ?
9. If you try to access the file from a method, what additional syntax would you use/need?
10. You have two strings declared:
String name="John";
String name2=new String("John");
How do you write a code to compare Strings, name and name2? Are they equal?
If you assign a new String "Johnny" to the variable "name", what happens with "John"?
Does name get two letters added, or "John" is completely replaced with "Johnny"?
Does "name" reference point to the diferent place in memory now?
11. When objects are processed in a similar way (in a loop for example) such as we did with Point, Circle, Sphere,
how such a behavior is called/named in a programming terms?
12. What do you need to import, to use showMessageDialog(...) and showInputDialog(...) methods
13. How many times does the loop run and what exactly numbers are printed?
int k = 1;
while ( k < 12)
{
if ( (++k) % 3 ==0 )
System.out.print ("k=" + k);
}
14. Write an If statement for a lettergrade and a score. If score>90, then "A", score >80, then "B"
How the if statement will look like?
15. How do you declare a constant variable as a part of the class? Variable that cannot be changed after declaration? [2 Points]
16. Create an array of 12 integers, and initialize all of the elements to 100 using a loop.
Create an array of 5 doubles, and initialize of them to 2.3 during declaration.
17. Create a class Cat, and a class Cheetah, see above.
Create three overloaded constructors, and also set and get methods to be able to change instance variables.
18. Write a line of code that create object of datatype Cat.
Write another line of code that creates an object of a datatype Cheetah.
Where would you write these lines?
19. How many time this loop runs? What does it print?
int k = 0;
while (k < 5) {
System.out.println("k");
}
20. Write a method that accepts three arays as three parameters (fruits, prices, stores)
String fruits={"apple", "pear", "fig", "Plum","Cherry"}
double prices={2, 2.50, 6, 3.50, 4.50 }
String stores={"Safeway","Giant","Lion","BJ", "Whole Foods"}
and finds and prints the name of the most expensive fruit, and the store where it is being sold.
----------- He-----------llo----------- Si-----------r/M-----------ada-----------m -----------Tha-----------nk -----------you----------- fo-----------r y-----------our----------- in-----------ter-----------est----------- an-----------d b-----------uyi-----------ng -----------my -----------pos-----------ted----------- so-----------lut-----------ion-----------. P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll -----------be -----------qui-----------ckl-----------y