Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Pre-laba Read the pre-lab and answer the questions before your lab session. This

ID: 3782073 • Letter: P

Question

Pre-laba Read the pre-lab and answer the questions before your lab session. This lab covers the following concepts: Important elements of Java programs Outputting text to the Monitor Comments When writing any Java program, there are a few bits of code that we will almost always use. Every Java program needs at least one class. Classes are like boxes where code is stored, and Java is a neat freak, so it requires that all code ends up in a class (after all, having piles ofcode scattered all over the floor would be rather messy, wouldn't it?). For our first few Java programs, we'll only have one class and only one code file. To tell Java that we're starting a class, we'd use a line of code like this: public class Puppy This tells Java that we'd like to create a class called Puppy. Don't worry about why the "public" is there, we'll deal with that later. After declaring and naming our class, we need to add a pair of curly braces, like so: public class Puppy These are like the walls of the code box. curly braces tell Java where blocks of code start and stop. Once we've got the curly braces in place, we need to add a method inside the class. Methods are bits of code that we write that we (or Java) can call on to execute certain tasks. Think of methods like little toys that we put inside our code box: each toy looks different from the others, and each toy does something different (e.g., some walk around the room, some make noise, and some torment your little brother by shooting Nerf darts at him). Methods are the same way. Each one gets a different name Gust like classes), and each onc usually does something related to its name. Every Java program needs to have at least one method called main, and we add it to our program like so:

Explanation / Answer

Answers for those 5 questions are as follows:

1. The following code should be written in Line 1:

public class Kitten

2. The comment should use // instead of /

3. In line 4, static word is missing. It should be declared as : public static void main ( String [ ] args )

4. Write this on line 7 to output desired in console:

System.out.println ( " Kittens are cuddly! " );

5. The filename would be Kitten.java for saving.

Code of Lab1.java

class Lab1

{
   public static void main (String[] args)
   {
       System.out.println("Roses are red");
       System.out.println("Violets are blue");
       System.out.println("Sugar is sweet");
       System.out.println("And Java is too!");
   }
}

Note: The rest of the things to mention in comment and other things are to be done by you as it is only known to you.

if there is an doubt, please comment it. Thank you. :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote