# Introduction to Computer Science Lab #2 Solution

For this lab, students will work individually. If questions arise, try to see if those around you are able to answer them, chances are one of your fellow students has encountered your problem and has figured out how to solve it. Ask the instructor for help as a last resort.
Try your best to complete the following programs today in class. If you cannot complete them all, make sure you complete them prior to the next class. Submit all files together in one .zip file to blackboard.

FormattedOutput.java
KeyboardInput.java
VendingMachine.java
StringMethods.java
IsEven.java

Lab Objectives
 Be able to create Java programs with
o Variables, Constants
o Primitive data types
o Strings
o Keyboard input and output
o Decision Structures
o Input Validation
 Be able to compile and execute a Java program
 Be able to test and debug a program

Write a program using escape sequences to print out the following: your name, your major, and your study list. The output should look exactly like this:
Student: “Superior Diaz” Major: \Computer Science\ Study List: CS ‘130’, ‘140’, and MAT ‘115’

Write a program that will ask the user to enter the following information in the given order:
 Name (String)
 Age (int)
 Company Name (String)
Your Program should display the following message using println.
My name is Superior Diaz, my age is 26 and
I hope to work for Skynet.

Write a program that determines the change to be dispensed from a vending machine. An item in the machine can cost between 25 cents and a dollar, in 5-cent increments (25, 30, 35, … 90, 95, 100), and the machine accepts only a single dollar bill to pay for the item. For example, a possible sample dialog might be
Enter price of item (from 25 cents to a dollar, in 5-cent increments): 45
You bought an item for 45 cents and gave me a dollar, So your change is 2 quarters, 0 dimes, and 1 nickels.

Rewrite the following program, add statements to verify whether the user input is either odd or even and make sure its within the range given, otherwise return an error.
//analysis of numbers
import java.util.Scanner;
public class IsEven {
public static void main(String[] args)
{
boolean evenOdd=false;
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter an integer from 0-10: ");
int n = keyboard.nextInt();
System.out.println("Is that number even? "+evenOdd);
}
}