Lab 5 Lab 5: Introduction to Java Programming Objectives The main objectives of this laboratory are ● to learn how to write, compile and run simple Java programs using BlueJ, and ● to learn how to...

1 answer below »
All the instructions are in the pdf. This is the shortest/easiest assignment compared to what I have ordered in the past.


Lab 5 Lab 5: Introduction to Java Programming Objectives The main objectives of this laboratory are ● to learn how to write, compile and run simple Java programs using BlueJ, and ● to learn how to document Java programs. 1. Installing BlueJ BlueJ is a lightweight IDE (Integrated Development Environment) for Java programming. BlueJ is already installed in the lab computers. You can download and install BlueJ from bluej.org and install it on your own computer. Login into your lab computer and click on the start menu and type “bluej” in the search box. It will show the BlueJ program. Click on it to launch the BlueJ IDE. 2. Developing Java programs on BlueJ We will now walk through the basic steps of the software development cycle using BlueJ. First, create a folder or directory named, lab5, on your computer. http://bluej.org/ Creating a new project 1. Open BlueJ. 2. Click on the Project tab. 3. Then click on the New Project tab. 4. Enter a project name, HelloWorld. 5. Under Location, find and choose the lab5 folder. 6. Click on the OK button. Creating a new class 1. Click on the New Class button. 2. Type in the name of the class, HelloWorld, and click OK. Editing a program file 1. Right click on the HelloWorld file icon. 2. Then click on the Open Editor button. 3. Delete text from the file. 4. Manually type in (not copy and paste) the following code: public class HelloWorld { public static void main(String args[]) { System.out.println("Hello, World!"); } } Compiling and running Java programs 1. To compile, from BlueJ’s main window, right click on the program file and then click on the Compile menu. 2. To run, right click on the program file and then click on the void main(String[]args) tab. 3. Click on OK to run the program. This should print in BlueJ’s Terminal Window: Hello, World! Now, modify your code so that it will print Hi there! How are you? What happens when you change println to print? What does println do? 3. Temperature conversion Recall Lab 2, when we wrote a Python script to convert a temperature given in Celsius to the equivalent temperature in Fahrenheit: c = int(input('Enter a temperature in Celsius: ')) f = (9/5)*c + 32 print('The temperature in Fahrenheit is', f, 'degrees.') The following Java program accomplishes the same task: import java.util.*; // for Scanner class public class Temperature { public static void main(String args[]) { Scanner sc = new Scanner(System.in); double c, f; System.out.print("Enter a temperature in Celsius: "); c = sc.nextInt(); f = (9.0/5.0)*c + 32; System.out.println("The temperature in Fahrenheit is " + f + " degrees."); } } Create a new BlueJ project and a new class named Temperature in lab5. Type in (not copy and paste) the code above. Compile and run the program. Does your program give the correct answers? Now, add code to the Temperature class to do the exact opposite: convert a temperature given in Fahrenheit to the equivalent temperature in Celsius. Compile and run your program with five different test cases and save the output in a text file named temp.txt as follows: 1. From Terminal Window, click on Options and click on Save to file. 2. Enter a text file name, temp.txt, and click on Save. 4. Documentation As programs get more complex, it becomes increasingly important to include comments that are meaningful and succinct. It is also important to document such comments following some standards. In this course (and perhaps in other courses you will take in the future), you are expected to follow the Javadoc format. Here is an example of a file header in the Javadoc style: /** * This program converts temperature between Celsius and Fahrenheit * * @author Maminur Islam * @version 1.0, 10/19/2021 */ You should include such a file header at the beginning of each class you implement. What to hand in Upon completion of your laboratory, create a folder by your last name, copy your files(java source, Temperature.java, and the output, temp.txt,) inside the folder. Then create a zip file(your_last_name.zip) and upload the zip file in the moodle.
Answered Same DayOct 19, 2021

Answer To: Lab 5 Lab 5: Introduction to Java Programming Objectives The main objectives of this laboratory are...

Vaibhav answered on Oct 20 2021
121 Votes
temp.txt
Enter a temperature in celsius :
0
The temperature in Fahrenheit is 32.0 degrees.
Enter
a temperature in Fahrenheit :
32
The temperature in celsius is 0.0...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here