Starting from:

$20

CS 140 Introduction to Computer Science Lab #2

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
Task #1 Formatted Output
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’
Task #2 Keyboard Input
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.
Task #3 Vending Machine
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.
Task #4 Is Even
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);
}
}
Task #5 String Methods (Challenge)
Write a program that asks the user to enter your info, and it displays a story about you in a special format. The program should ask you to enter (use the Scanner class) the following: - first name - middle name - last name - age - lucky number - favorite color
For example, a possible sample dialog might be
Please enter your first name: superior Please enter your middle name: SPIDER Please enter your last name: mAn Please enter your age: 20 Please enter your lucky number: 9 Please enter your favorite color: GrEeN
A story about Superior Spider Man:
SUPERIOR SPIDER MAN is SSM.
SSM's favorite color is green, and Superior M. is 20.
The lucky number of Superior S. Man is 9.
0

More products