Question

Prelab Exercises Your task is to write a Java program that will print out the following...

Prelab Exercises
Your task is to write a Java program that will print out the following message (including the row of equal marks):
Computer Science, Yes!!!!
=========================
An outline of the program is below. Complete it as follows:
a. In the documentation at the top, fill in the name of the file the program would be saved in and a brief description of what
the program does.
b. Add the code for the main method to do the printing.
// ************************************************************
// File Name:
//
// Purpose:
// ************************************************************
public class CSYes
{
// -------------------------------------------------
// The following main method prints an exciting
// message about computer science
// -------------------------------------------------
}

Comments
File Count.java contains a Java program that counts from 1 to 5 in English, French, and Spanish. Save this file to your
directory and compile and run it to see what it does. Then modify it as follows:
1. Use // style comments to add a comment header at the top of the file that includes the name of the program, your name,
and a brief description of what the program does, neatly formatted. Include a delimiter line (e.g., all stars) at the
beginning and end of the header.
2. Add a comment before each println that indicates what language the next line is in. Experiment with leaving a blank line
before each of these comment lines (in the program itself, not the output). Is the program easier to read with or without
these blank lines?
3. Remove one of the slashes from one of your comment lines and recompile the program, so one of the comments starts
with a single /. What error do you get? Put the slash back in.
4. Try putting a comment within a comment, so that a // appears after the initial // on a comment line. Does this cause
problems?
5. Consult the documentation guidelines in Appendix F of the text. Have you violated any of them? List two things that you
could imagine yourself or someone else doing in commenting this program that these guidelines discourage.
Count.java
public class Count
{
public static void main (String[] args)
{
System.out.println ("one two three four five");
System.out.println ("un deux trois quatre cinq");
System.out.println ("uno dos tres cuatro cinco");
}
}


Correcting Syntax Errors
File Problems.java contains a simple Java program that contains a number of syntax errors. Save the program to your
directory, study it and correct as many of the errors as you can find. Then compile the program; if there are still errors,
correct them. Some things to remember:

Java is case sensitive, so, for example, the identifiers public, Public, and PUBLIC are all considered different. For
reserved words such as public and void and previously defined identifiers such as String and System, you have to get the
case right. You will learn the conventions about case soon, but for now you can look at a sample program in the text to
see what case should be used where.

When the compiler lists lots of errors, fix the first one (or few) and then recompile—often the later errors aren’t really
errors in the program, they just indicate that the compiler is confused from earlier errors.

Read the error messages carefully, and note what line numbers they refer to. Often the messages are helpful, but even
when they aren’t, the line numbers usually are.

When the program compiles cleanly, run it.
// ********************************************
// Problems.java
//
// Provide lots of syntax errors for the user to correct.
//
********************************************
public class problems
{
public Static main (string[] args)
{
System.out.println ("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
System.out.println ("This program used to have lots of problems,");
System.out.println ("but if it prints this, you fixed them all.")
System.out.println (" *** Hurray! ***");
System.out.println ("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}

1 0
Add a comment Improve this question Transcribed image text
Answer #1

Prelab Exercise:

CSYes.java

// ************************************************************

// File Name: CSYes.java
// Author Name: Your name here.
// Purpose: To print Computer Science, Yes!!!!
// ************************************************************
public class CSYes
{
// -------------------------------------------------
// The following main method prints an exciting
// message about computer science
// -------------------------------------------------

public static void main(String[] args){

System.out.println("Computer Science, Yes!!!!");

}
}

Comments:

Count.java

// ************************************************************

// File Name: Count.java
//Author name: Your name here.
// Purpose: To count the subjects in different langauge.
// ************************************************************

public class Count
{
public static void main (String[] args)
{

//This print statement prints count in English.  
System.out.println ("one two three four five");

//This print statement prints count in French.

System.out.println ("un deux trois quatre cinq");

// This print statement prints count in Spanish.

System.out.println ("uno dos tres cuatro cinco");
}
}

3. If we remove one slash from the comment, the compiler throws the below error

Syntax error on token "/", delete this token.

after putting the slash back, code runs fine with no compilation error.

4. Comment within a comment for eg. //hi i am // subrat works fine without compilation error.

5. Appendix F is not given so hard to tell, if we have violated any.

Correcting Syntax Errors

Corrected Problems.java code is below

// ********************************************
// Problems.java
// Author: Your Name here.
// Description: Provide lots of syntax errors for the user to correct.
//
********************************************
public class Problems //Class names should be nouns, in mixed case with the first letter of each internal word capitalized.
{
public static void main (String[] args) //static is a keyword it must be in small, and there should be a return type of main method and String is a class so first letter must be in uppercase
{
System.out.println ("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
System.out.println ("This program used to have lots of problems,");
System.out.println ("but if it prints this, you fixed them all."); //the statement must end with the ';'
System.out.println (" *** Hurray! ***");
System.out.println ("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}

}//code mblock must be ended with'}' if a block is starting with '{' then must end with '}'

Add a comment
Know the answer?
Add Answer to:
Prelab Exercises Your task is to write a Java program that will print out the following...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that will check a Java file for syntax errors. The program will ask...

    Write a program that will check a Java file for syntax errors. The program will ask for an input-file name and output-file name and will then copy all the code from the Java input file to the Java output file, but with the following changes: 1. Any syntax error found in the Java input file will be corrected: a. Missing semicolon b. Missing compound statements (curly braces) c. All comments have to start with // and end with a period....

  • Java Eclipse program Write statements to declare and initialize eight constants, one for each of the...

    Java Eclipse program Write statements to declare and initialize eight constants, one for each of the primitive types in Java. boolean, byte, char, short, int, long, float and double. Add statements to print the name of the constant and its value to your VariableDefinitions.javaprogram and compile the program. Assign a new value to one of the constants and compile. Comment out the lines of code that cause compilation errors but do not delete them and recompile your program.

  • 4.3Learning Objective: To read and write text files. Instructions: This is complete program with one Java...

    4.3Learning Objective: To read and write text files. Instructions: This is complete program with one Java source code file named H01_43.java (your main class is named H01_43). Problem: Write a program that prompts the user for the name of a Java source code file (you may assume the file contains Java source code and has a .java filename extension; we will not test your program on non-Java source code files). The program shall read the source code file and output...

  • Filename(s): ReformatCode. java Public class: ReformatCode Package-visible class(es): none Write a program that reformats Java source...

    Filename(s): ReformatCode. java Public class: ReformatCode Package-visible class(es): none Write a program that reformats Java source code from the next-line brace style to the end-of-line brace style. The program is invoked from the command line with the input Java source code file as args [0] and the name of the file to save the formatted code in as args [1]. The original file is left untouched. The program makes no other changes the source code, including whitespace. For example, the...

  • Using PuTTY Linux Server Task Compiling:             1) Download the two files from blackboard, driver.cpp, and...

    Using PuTTY Linux Server Task Compiling:             1) Download the two files from blackboard, driver.cpp, and circle.h             2) Create a new directory to store the files in             3) Compile the code a) Run the command g++ driver.cpp -o executable_name, this will compile the code both for driver.cpp and the referenced file circle.h note: -o parameter specifies a new name for the executable, if you do not specify the “-o” parameter the default name of the executable is “a.out”...

  • package _solution; /** This program demonstrates how numeric types and operators behave in Java Do Task...

    package _solution; /** This program demonstrates how numeric types and operators behave in Java Do Task #1 before adding Task#2 where indicated. */ public class NumericTypesOriginal { public static void main (String [] args) { //TASK #2 Create a Scanner object here //identifier declarations final int NUMBER = 2 ; // number of scores int score1 = 100; // first test score int score2 = 95; // second test score final int BOILING_IN_F = 212; // boiling temperature double fToC;...

  • Homework description::::: Write JAVA program with following description. Sample output with code will be helful... A...

    Homework description::::: Write JAVA program with following description. Sample output with code will be helful... A compiler must examine tokens in a program and decide whether they are reserved words in the Java language, or identifiers defined by the user. Design a program that reads a Java program and makes a list of all the identifiers along with the number of occurrences of each identifier in the source code. To do this, you should make use of a dictionary. The...

  • Getting started with Java on elvis Download Greeting.java from the class web site. Use FileZilla to...

    Getting started with Java on elvis Download Greeting.java from the class web site. Use FileZilla to place it into your Lab5 directory. Look at the content of your directory to see the file using the command ls Look at the content of the file in your directory using the command more Greeting.java Compile the HelloClass program using the command javac Greeting.java. Then use ls to see your class file. Run the program without parameters using the command java Greeting Run...

  • You will write a single java program called MadLibs. java.

    You will write a single java program called MadLibs. java. This file will hold and allow access to the values needed to handle the details for a "MadLibs" game. This class will not contain a maino method. It will not ask the user for any input, nor will it display (via System.out.print/In()) information to the user. The job of this class is to manage information, not to interact with the user.I am providing a MadLibsDriver.java e^{*} program that you can...

  • /************************************************************************************ * Program: PRG/420 Week 5 * Purpose: Week 5 Coding Assignment * Programmer: TYPE YOUR...

    /************************************************************************************ * Program: PRG/420 Week 5 * Purpose: Week 5 Coding Assignment * Programmer: TYPE YOUR NAME HERE * Class: PRG/420 * Creation Date: TYPE TODAY'S DATE HERE ************************************************************************************* * Program Summary: * This program converts a given date to a string. * The code includes exception handling for a ParseException. ************************************************************************************/ package prg420week5_codingassignment; import java.util.*; // wildcard to import all the util. classes import java.text.*; // wildcard to import all the text classes public class PRG420Week5_CodingAssignment { public static...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT