Computer science

profileSandesh878
HW1.pdf

Homework 1 1310

HW Submission requirements: 1) Put your name and ID number on the top of EACH assignment (in comments for programs) 2) Name each file the name written in blue above each problem 3) Put all the files into a folder and zip it 4) Name the zipped folder with all assignments HW#.zip (5 point deduction for incorrect name) MAKE SURE ALL PROGRAMS ARE PROPERLY INDENTED-automatic 10 point deduction

Problem 1-True or False Submit Answers.doc In your word document called Answers, please write the number of the statement and T for true and F for false. YOU MUST EXPLAIN WHY EACH STATEMENT IS TRUE OR FALSE TO RECEIVE CREDIT. You will be using the following code to determine your answers. Code: public class Practice { public static void main( String[] args ) { Scanner in=new Scanner(System.in); System.out.println("Enter a number:"); int n=in.nextInt(); } } True or False 1) This program would run with no errors. 2) This program has a line for outputting to screen a value entered by a user. 3) n is the name of a char variable. 4) There are no comments. 5) This program allows for user input. 6) There is a concatenation operator somewhere in the code.

Problem 2-Pick vocabulary Submit Answers.doc (use same document from above) Write the name of the underlined portion of code on the line given. A word bank of possible answers is given at the bottom of this page. Any possible answer can be used more than once or not at all. Code Fragment 1: int donuts=40; 1___________________ int customerOne, customerTwo; Scanner in=new Scanner(System.in); System.out.println( "Donuts! ” + donuts); 2___________________ donuts=in.nextInt(); System.out.printf( "I’m baking %d donuts!” , donuts ); 3___________________, 4________________

Problem 3-Write a program Submit a program called info.java DO NOT FORGET TO INDENT! You will be writing a program that allows users to input information. They will be entering a name, an age and a favorite food. This information will then be output onto the screen so it matches the sample output. Note that you should write one program (the sample runs are just for checking that your program works correctly). Sample Run 1: Enter your name: Bob Enter your age: 20 Enter your favorite food: pasta My name is: Bob and my favorite food is pasta! *** I am 20 years old and in 2 years I will be 22!

Argument Concatenation Operator Format Specifier Variable Declaration and Initialization Variable Assignment Variable Declaration Variable Initialization Comment

Sample Run 2: Enter your name: Pinky Enter your age: 40 Enter your favorite food: Candy My name is: Pinky and my favorite food is Candy! *** I am 40 years old and in 2 years I will be 42!