Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Lab 1 - Java Programming 1 - Introduction |, Lab Reports of Java Programming

Material Type: Lab; Class: Java Programming 1 - Introduction; Subject: Computer Science; University: Middlesex County College; Term: Forever 1989;

Typology: Lab Reports

2009/2010

Uploaded on 03/25/2010

ronny-14
ronny-14 🇺🇸

5

(1)

2 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lab 1
Lab Objectives
Be able to write an algorithm
Create a Java program template
Be able to enter and compile a Java program using Text Pad
Document a program using Word
1. TextPad
We will be using Textpad as our editor. Open Textpad by clicking on the icon on the
desktop. Familiarize yourself with the menu. Make sure you are familiar with the
standard word functions such as copy, paste, search and replace. Menu options that
are specific to Java are: /view/line numbers, /tools/external tools/compile java and
tools/external tools/Run Java application. Locate these menu items we will use them
later.
To make things easier: Select View and select Line numbers and visible spaces
(you’ll have to do this each time you start TextPad).
2. Snipping Tool (Start/Programs/Accessories)
The snipping tool allows you to cut and paste portions of the screen. Click on the
snipping tool icon on the desktop. Click and drag the cursor over the portion you
want to copy. Select Edit/Copy or Right Click/Copy. Open word and click paste.
To start again click on the New button.
3. Payroll Algorithm;
a) Write an algorithm to calculate an employees pay. The employee gets 1.5
times the hourly rate for more than 40 hrs.
b) Pick a few examples and manually calculate the result. This will be used
to verify that the program is working. Enter the results in the table below.
Hours Rate Pay (hand
calculated)
Pay (program
result)
pf3
pf4

Partial preview of the text

Download Lab 1 - Java Programming 1 - Introduction | and more Lab Reports Java Programming in PDF only on Docsity!

Lab 1

Lab Objectives

 Be able to write an algorithm  Create a Java program template  Be able to enter and compile a Java program using Text Pad  Document a program using Word

1. TextPad We will be using Textpad as our editor. Open Textpad by clicking on the icon on the desktop. Familiarize yourself with the menu. Make sure you are familiar with the standard word functions such as copy, paste, search and replace. Menu options that are specific to Java are: /view/line numbers, /tools/external tools/compile java and tools/external tools/Run Java application. Locate these menu items we will use them later. To make things easier: Select View and select Line numbers and visible spaces (you’ll have to do this each time you start TextPad). 2. Snipping Tool (Start/Programs/Accessories) The snipping tool allows you to cut and paste portions of the screen. Click on the snipping tool icon on the desktop. Click and drag the cursor over the portion you want to copy. Select Edit/Copy or Right Click/Copy. Open word and click paste. To start again click on the New button. 3. Payroll Algorithm; a) Write an algorithm to calculate an employees pay. The employee gets 1. times the hourly rate for more than 40 hrs. b) Pick a few examples and manually calculate the result. This will be used to verify that the program is working. Enter the results in the table below. Hours Rate Pay (hand calculated) Pay (program result)

4. Java Template. Using Textpad enter the following code and save it as Template.java. DO NOT save to hard drive, use a USB Drive. // Your Name // Lab Number // Description of Lab public class Template { public static void main (String[] args) { } } 5. Enter the following program: (Pay.java) (start with template.java, rename it and edit it). Must enter exactly as shown below, including blank lines, spaces, upper/lower case. // Your name // Lab 1 //This program calculates the user's gross pay import java.util.Scanner; //to be able to read from the keyboard public class Pay { public static void main(String [ ] args) { //create a Scanner object to read from the keyboard Scanner keyboard = new Scanner(System.in); //identifier declarations double hours; //number of hours worked double rate; //hourly pay rate double pay; //gross pay //display prompts and get input System.out.println(“Name”); System.out.println(“Lab 1”); System.out.print("How many hours did you work? "); hours = keyboard.nextDouble(); System.out.print("How much do you get paid per hour? "); rate = keyboard.nextDouble();

  1. Enter the following program, compile it and run it. Note there are some syntax errors to be corrected. By looking at the code write the algorithm used. // Your Name //This program calculates the total price which includes sales tax //solution import java.util.Scanner; public class SalesTax { public static void main(String[] args) { //identifier declarations final double D = 0.055; double A; double B double C; String item; //create a Scanner object to read from the keyboard Scanner keyboard = new Scanner(System.in); //display prompts and get input System.out.print("Item description: ); item = keyboard.nextLine(); System.out.print("Item price: $"); price = keyboard.nextDouble(); //calculations B = A * D; C = A + B; //display results System.print(item + " $") System.out.println(price); System.out.print("Tax $"); System.out.print(tax); System.out.print("Total $"); System.out.println(total); } }
  2. Use “search and replace” to replace A with price, B with tax, C with total and D with TAX_RATE. Add println’s to print your name and lab number. Compile and run