Instructions

1. Start NetBeans.

2. Create a new project:

  • In the File menu select New Project
  • A form should appear called Choose Project.
  • Under Categories: make sure that Java with Maven is selected.
  • Under Projects: make sure that Java Application is selected.
  • Click Next >.
  • If you get an error at this point about additional modules, mark all of the check boxes, click Download and Activate and follow the instructions to install the missing modules.
  • A new form should appear called Name and Location.
  • For Project Name: type Assign1
  • For Project Location: click Browse and select a location on your computer where you want to store your lab assignments.
  • For Group ID type csci1010
  • Click Finish

3. Modify the Java Main class template:

  • In the Tools menu, select Templates.
  • In the dialog box that comes up, open the Java folder, select Java Main Class and click the Open in Editor button.
  • A new file should open up containing the following text:
< #assign licenseFirst = "/*" >
< #assign licensePrefix = " * " >
< #assign licsenseLast = " */ " >

< #if package?? && package != "" >
< /#if >
public class ${name} {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
}
  • Delete the first four lines and after @author replace the text ${user} with your first and last name.
  • In the File menu select Save. You can also click on the Save All icon to save your files.
  • Close the Java Main Class file by clicking the X on the tab.

4. Create a Java main class file:

  • In the File menu select New File
  • Under Categories: make sure that Java is selected.
  • Under File Types: make sure that Java Main Class is selected.
  • Click Next >.
  • For Class Name: type YourlastnameAssign1
  • For Package: select csci1010.assign1
  • Click Finish
  • A text editor window should pop up with the following source code (except with your name instead)
/**
* @author Firstname Lastname
*/
public class FirstNameAssign1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
}

5. Write a program that displays Hello World!:

  • Modify the source code in the text editor to add CSCI 1010 Assignment 1 to the comment in the line before the @author line.
  • Replace the line // TODO code application logic here with the line System.out.println("Hello World!");

6. Build and debug the program:

  • Compile and run your program by clicking on the green triangle icon.
  • If a window pops up asking you to select a main class for execution, select csci1010.assign1.Assign1 and click Select Main Class.
  • If you typed in the program correctly, after displaying a lot of messages about downloading jar files, it should display something like the following in the Output pane of the window:
Hello World!
-----------------------------------------------------------
BUILD SUCCESS
-----------------------------------------------------------
Total time: 0.739 s
Finished at: 2020-06-03T16:17:00-05:00
Final Memory: 10M/309M
-----------------------------------------------------------
  • This pane is also known as the console.
  • Delete the semicolon(;) character in the line you added to the main function.
  • Notice now that the line you modified has a red squiggly line under it. This means that there is an error in your program and it will not compile. If you hover over the line with the error it should give you a message saying ';' expected.
  • Add the semicolon back in and the line should go away.
  • Save your source file.

7. Rewrite your program so it calculates the area and perimeter of a rectangle and a square, and the area of a triangle. The program will perform the following tasks:

  • Display "Welcome to (your name)'s geometry calculator."
  • Ask the user to enter the square's side.
  • Calculates the area and the perimeter of the square based on the entered value and displays them.
  • Ask the user to enter the base of the triangle.
  • Ask the user to enter the height of the triangle.
  • Calculates only the area of the triangle based on the entered values and displays them.

To calculate the area and the perimeter use the following formulas:

Area of a square with side s is s*s
Perimeter of a square with a side s is s*4

Area of a rectangle with length l and width w is l*w
Perimeter of a rectangle with length l and width w is (l+w)*2

Area of a triangle with base b and the height h is (b*h)/2

Example Input and Output

When you test your program the output should look like the following examples, except that your name should be used.

Example Run 1:

Welcome to YourName's Geometry calculator.
Enter the square's side:
5
Square Area: 25
Square Perimeter: 20

Enter the Rectangle's length:
8
Enter the Rectangle's width:
5
Rectangle Area: 40
Rectangle Perimeter: 26

Enter Triangle's base:
10
Enter Triangle's height:
5
Triangle Area: 25.0

Note that the 5, 8, 5, 10, and 5 are user input.

Example Run 2:

Welcome to YourName's Geometry calculator.
Enter the square's side:
3
Square Area: 9
Square Perimeter: 12

Enter the Rectangle's length:
9
Enter the Rectangle's width:
6
Rectangle Area: 54
Rectangle Perimeter: 30

Enter Triangle's base:
5
Enter Triangle's height:
4
Triangle Area: 10.0

In this case the user has entered 0, 0, 5, and 0 as input, and 50 is calculated by multiplying 0 by 1 to get 0, multiplying 0 by 5 to get 0, multiplying 5 by 10 to get 50, multiplying 0 by 20 to get 0, and adding these results to get 50.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.