CSIS 10A Assignment 3 Due: 2/21 at midnight

Similar documents
CSIS 10A Assignment 4 SOLUTIONS

Assignment 8B SOLUTIONS

Task #1 The if Statement, Comparing Strings, and Flags

CSIS 10A Assignment 9 Solutions

Over and Over Again GEEN163

Chapter 5 Lab Methods

CSIS 10A Assignment 7 SOLUTIONS

Chapter 5 Lab Methods

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

Building Java Programs

What two elements are usually present for calculating a total of a series of numbers?

Chapter 1 Lab Algorithms, Errors, and Testing

St. Edmund Preparatory High School Brooklyn, NY

Lesson 7 Part 2 Flags

Chapter 3 Lab Decision Structures

CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam

Console Input and Output

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

Building Java Programs

What methods does the String class provide for ignoring case sensitive situations?

Chapter 5 Lab Methods

A+ Computer Science -

Full file at

Lecture 8 " INPUT " Instructor: Craig Duckett

Returns & if/else. Parameters and Objects

Full file at

1 Short Answer (10 Points Each)

Anatomy of a Java Program: Comments

AP Computer Science. if/else, return values. Copyright 2010 by Pearson Education

A+ Computer Science -

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

Evaluating the Style of your programs

Check out how to use the random number generator (introduced in section 4.11 of the text) to get a number between 1 and 6 to create the simulation.

Building Java Programs

Full file at

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

AP Computer Science Unit 1. Writing Programs Using BlueJ

Midterm Examination (MTA)

Using Classes. GEEN163 Introduction to Computer Programming

Topic 11 Scanner object, conditional execution

AP Computer Science Unit 1. Writing Programs Using BlueJ

Building Java Programs Chapter 4

BASIC INPUT/OUTPUT. Fundamentals of Computer Science

Building Java Programs

for Diane Christie University of Wisconsin Stout

! definite loop: A loop that executes a known number of times. " The for loops we have seen so far are definite loops. ! We often use language like

Chapter 3 Selections. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

Introduction to Java Unit 1. Using BlueJ to Write Programs

Oct Decision Structures cont d

CSIS 10A Assignment 4 SOLUTIONS

BlueJ Demo. Topic 1: Basic Java. 1. Sequencing. Features of Structured Programming Languages

Chapter 4: Conditionals and Recursion

1. What is the difference between a compiler and an interpreter? Also, discuss Java s method.

M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014

Darrell Bethea May 10, MTWRF 9:45-11:15 AM Sitterson 011

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION

CS110 Programming Language I. Lab 6: Multiple branching Mechanisms

2. What are the two main components to the CPU and what do each of them do? 3. What is the difference between a compiler and an interpreter?

Basic Computation. Chapter 2

Chapter 3 Selections. 3.1 Introduction. 3.2 boolean Data Type

CS 152: Data Structures with Java Hello World with the IntelliJ IDE

Loops. GEEN163 Introduction to Computer Programming

Practice with variables and types

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: Text-printing program. CSC 209 JAVA I

The NetBeans IDE is a big file --- a minimum of around 30 MB. After you have downloaded the file, simply execute the file to install the software.

1 Short Answer (5 Points Each)

Variables and Assignments CSC 121 Spring 2017 Howard Rosenthal

ACS-1903 Basic program structure Feb 16, 2017

Tutorial 03. Exercise 1: CSC111 Computer Programming I

COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz

When we reach the line "z = x / y" the program crashes with the message:

1 Short Answer (10 Points Each)

Topic 11 Scanner object, conditional execution

The action of the program depends on the input We can create this program using an if statement

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007

Fundamentals of Programming Data Types & Methods

Encapsulation in Java

The for Loop, Accumulator Variables, Seninel Values, and The Random Class. CS0007: Introduction to Computer Programming

Lecture 6. Assignments. Java Scanner. User Input 1/29/18. Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4

Basic Computation. Chapter 2

Lesson 10: Quiz #1 and Getting User Input (W03D2)

1. Word Analysis: (Which nouns suggest a need for memory (a variable) and which verbs suggest a need for action (a function maybe).

JAVA PROGRAMMING (340)

Please answer the following questions. Do not re-code the enclosed codes if you have already completed them.

1 Short Answer (2 Points Each)

Lab1 Solution. Lab2 Solution. MathTrick.java. CoinFlip.java

Basic Programming Elements

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Simple Control Flow: if-else statements

Program Control Flow

Program Control Flow

S8352: Java From the Very Beginning Part I - Exercises

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Testing and Debugging

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

Chapter 6 Lab Classes and Objects

CS 112 Introduction to Programming

COSC 123 Computer Creativity. I/O Streams and Exceptions. Dr. Ramon Lawrence University of British Columbia Okanagan

COMP-202 Unit 4: Programming With Iterations. CONTENTS: The while and for statements

Exercise 1: Class Employee: public class Employee { private String firstname; private String lastname; private double monthlysalary;

COMP 202 Java in one week

Introduction to Computer Science Unit 2. Exercises

Transcription:

CSIS 10A Assignment 3 Due: 2/21 at midnight Read: Chapter 3 Choose and complete any 10 points from the problems below by first downloading the assignment 3 folder from the website. Use BlueJ to complete the assignment, then export JAR file and upload to the server using your pass code. You may do more than 10 points of work but the max award will be 11 points. Part I: Exam Prep Exercises--7 points total To be answered in the Exercises file Find the Error: in the Exercise file 1. Warning! This code contains ERRORS! if (x == 1); xxxxx there should be no ; because that makes the statment end, so it xxxxx will assign 2 to y no matter what y = 2; if (x == 2); xxxxx there should be no ; y = 3; if (x == 3); xxxxxx there should be no ; y = 4; 2. Warning! This code contains an ERROR! if (average = 100) xxxxx this should be if (average == 100) so it compares xxxxx average to 100, not assign 100 to average System.out.println("Perfect Average!");

Algorithm Workbench 1) if (y==0) x = 100; 2) if (y==10) x = 0; x = 1; if (amount1>10 && amount2<100) if (amount1 > amount2) System.out.println("the greater is " + amount1); System.out.println("the greater is " + amount2); if ( title1.compareto(title2) < 0) System.out.println(title1 + ", " + title2); System.out.println(title2 + ", " + title1); Part 3: Programming Challenges - 3 points each 1) Create a new class called P1BMI and solve the following:

P1BMI.java import java.util.scanner; public class P1BMI public static void main (String [] args) Scanner keyboard = new Scanner(System.in); double weight, height; //declare variables //prompt user and get weight and height System.out.println("What is your weight in pounds?"); weight = keyboard.nextdouble(); System.out.println("What is your height in inches?"); height = keyboard.nextdouble(); //calculate their bmi double bodymass = weight * 703 / (height * height); //tell user if they are underweight, overweight or optimal if (bodymass < 18.5) System.out.println("You are underweight."); if (bodymass > 25) System.out.println("You are overweight."); System.out.println("You have optimal weight."); 2) Create a new class called P2SortedNames P2SortedNames.java

/** * Asks the user to enter three names, then displays them in alphabetical order. * * Andrew Fiola * 2012.02.16 */ import java.util.scanner; public class P2SortedNames public static void main(string[] args) //declare variables Scanner keyboard = new Scanner(System.in); //keyboard scanner String name1; //Names entered by user String name2; String name3; //Prompt user for input System.out.print("\fPlease enter a name: "); name1 = keyboard.nextline(); System.out.print("And another: "); name2 = keyboard.nextline(); System.out.print("And one more: "); name3 = keyboard.nextline(); //Display those names, alphabetically sorted //Sort by first determining which name is first, //then determining the order of the second two. System.out.println("Alphabetically sorted:"); if (name1.comparetoignorecase(name2) <= 0 && name1.comparetoignorecase(name3) <= 0) if (name2.comparetoignorecase(name3) <= 0) if (name2.comparetoignorecase(name1) <= 0 && name2.comparetoignorecase(name3) <= 0) if (name1.comparetoignorecase(name3) <= 0) if (name1.comparetoignorecase(name2) <= 0)

3) Create a new class called P3InternetBill and solve the following: P3InternetBill.java //Dana A. DeVost //18FEB2012 /** * Write a description of class P3InternetBill here. This program is going to ask for two user inputs, type of package and hours used. * Then calculate the final cost for the package. */ import java.util.scanner; import java.text.decimalformat; public class P3InternetBill public static void main (String [] args) //Create a DecimalFormat object with 2 decimal places DecimalFormat formatter = new DecimalFormat("#0.00"); //Create a Scanner object to read input Scanner keyboard = new Scanner (System.in); String typeofpackage; double cost; double hoursused; //Letter of package bought //Cost of typeofpackage plus extra hours //Number of hours used. System.out.println("We provide three types of Internet Service: \n" + "Package A: For $9.95 per month, 10 hours of access are provided. " + "Additional hours are $2.00 per hour.\n" + "Package B: For $13.95 per month, 20 hours of access are provided. " + "Additional hours are $1.00 per hour.\n" + "Package C: For $19.95 per month, unlimited access is provided.\n"); System.out.println("Enter A, B, or C, for your package type: "); typeofpackage=keyboard.nextline(); System.out.println("Enter approximately how many hours of service were used. "); hoursused = keyboard.nextint(); if ((typeofpackage.equals("a") typeofpackage.equals("a")) && (hoursused <=10)) System.out.println("Your monthly cost is $9.95. ");

if ((typeofpackage.equals("a") typeofpackage.equals("a")) && (hoursused >10)) cost = (((hoursused-10) * 2.00) + (9.95)); System.out.println("Your monthly cost is: $ " + cost); if ((typeofpackage.equals("b") typeofpackage.equals("b")) && (hoursused <=20)) System.out.println("Your monthly cost is: $13.95. "); if ((typeofpackage.equals("b") typeofpackage.equals("b")) && (hoursused >20)) cost = ((hoursused-20) * 1.00) + (13.95); System.out.println("Your monthly cost is: $ " + cost); if (typeofpackage.equals("c") typeofpackage.equals("c")) System.out.println("Your bill is $19.95 a month with unlimited access. ");