Java Questions 1. Are there ways to make it easier to keep track of what a secti
ID: 668352 • Letter: J
Question
Java Questions
1. Are there ways to make it easier to keep track of what a section of code does?
2.Lets say I have a class to keep track of the objects in my kitchen. Each object has a height that I want to keep track of. It doesn't make sense to have a negative height, so I want to make sure that each object has a positive height. How can setters make sure that this is true?
3.In some ways any program that runs correctly is good, but there are good practices to follow when writing code. What are they?
Explanation / Answer
1.
There are many ways to keep track of section of code like in procedural programming use variable and in OOP use list of objects.
2.
class a
{
int h;
a()
{
if (h<0)
{
System.out.println("Height is negative);
}
}
}
class track
{
public static void main(String args[])
{
a o=new a(5);
a o = new a(-4);
}
}
3.
Following are good practices while writing code
1.Focus on readability of code
2.Don't write what code is doing
3.Always write why you are writing this piece of code
4.Finish your comment in as few words
5.Give your code to fellow developer to understand
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.