COMP 110-001: Introduction to Programming, SSI'15

Lab 1

25 points

Assigned: Friday, May 15, 2015
Due: Monday, May 18, 2015 by 11:59pm (EDT)

Description

In Eclipse, create a New Java Project called Lab1

Part 1

On the course webpage, you will find VendingMachine.java. Copy and paste the program into a new Java file in Eclipse (in the project Lab1). Run VendingMachine.java. Don't forget to change the header at the top of the program to say your name. In the textbook on page 75 you will find pseudocode for VendingMachine.java. Read through the pseudocode (Read pages 74-78) and make sure you understand the algorithm. Place each line of pseudocode into VendingMachine.java as comments directly above the line or lines that complete the action. The first line of pseudocode is already in the code as a comment. You may abbreviate the pseudocode comments when you place them into the code.

*** How to comment your code ***

Multiple-line comments

/* This is a
multi-line comment */


and single-line comments

// this is a single line comment

For example:

// Print a message to ask user to input his/her name
System.out.println("Hi, What's your name?");

/* Create an object keybord,
read user's input,
and then close the keyboard */

Scanner keyboard = new Scanner(System.in);
String name = keyboard.next();
keyboard.close();

// Print the welcome message including the user's name
System.out.println(name + ", welcome to COMP 110!");

Part 2

On the course webpage you will find TotalCost.java. You need to complete this program so that it calculates the total cost of a new coat including tax. (The user will input the cost of the coat and the tax rate.) Write pseudocode for how you would solve this problem. Following your pseudocode, complete the program TotalCost.java. Just like Part 1 insert your pseudocode as comments into your program.
NOTE: you are dealing with money so you should declare your variables as double, a number with a fractional part, instead of int, an integer number. Also, when reading doubles from the keyboard you would write keyboard.nextDouble() instead of keyboard.nextInt().

Additional Questions

Grading

How to hand in the assignment