COMP 110 - Lecture notes all PDF

Title COMP 110 - Lecture notes all
Author Tim Shelton
Course Introduction to Algorithms and Programming and Lab
Institution California State University Northridge
Pages 7
File Size 144.4 KB
File Type PDF
Total Downloads 89
Total Views 167

Summary

COMP 110 (Orientation to Computer Science) – FALL 2017
Dr. Wen-Chin (Amy) Hsu
...


Description

ver·sa·tile ˈvərsədl/ adjective adjective: versatile 1 1. ! able to adapt or be adapted to many different functions or activities. Wednesday, September 6, 2017 java is case sensitive

2.3

(Convert feet into meters) Write a program that reads a number in feet, converts it to meters, and displays the result. One foot is 0.305 meter. Here is a sample run: learn from examples document analysis and design Enter a degree in Celsius: 43 43 Celsius is 109.4 Fahrenheit Enter the radius and length of a cylinder: 5.5 12 The area is 95.0331 The volume is 1140.4 Enter a value for feet: 16.5 16.5 feet is 5.0325 meters (Liang 69)

Answers:! numberinfeet = 0; numberinmeters = 0; readnum('what is the length in feet?', function(number) { numberinfeet = number; numberinmeters = (numberinfeet*0.305); write('your length in meters is'+numberinmeters ); });

Convert pounds into kilograms) Write a program that converts pounds into kilograms. The program prompts the user to enter a number in pounds, converts it to kilograms, and displays the result. One pound is 0.454 kilograms. Here is a sample run: (Liang 70) Liang, Y. D. Intro to Java Programming, Brief Version, 10th Edition. Pearson, 20140103. VitalBook file. Answers: numberinpounds = 0; numberinkilograms = 0; readnum('what is the weight in pounds', function(number) { numberinpounds = number; numberinklograms = (numberinpounds*0.454); write('your weight in kilograms'+numberinklograms ); });

Monday, September 11, 2017 EXERCISE: Write a Java program that asks users to enter two numbers and can display the average of these two numbers. What does this program need to do ? Algorithm : Write all phases in English sentences first and then convert them into Java codes •Phase 1:! • Declare a variable that can hold the first number.! • Declare another variable that can hold the second number. •Phase 2: Assignments of initial values! •Phase 3: Communicate with a user ( i.e. display a text message as an instruction to tell the user what she needs to do)! •Phase 4: Receive inputs from the user. How ? import java.util.*;! public class Average2num{!

public static void main (String[] args){! double num1=0;! double num2=0;! System.out.println("Please enter the first number");! Scanner input=new Scanner(System.in);! num1=input.nextDouble();! System.out.println("Please enter the second number");! num2=input.nextDouble();! double sum=num1+num2;! System.out.println("The average of two number is"+ sum/2.0);! ! }! }

2.3 IN JAVA import java.util.*;! public class Feettometers{! public static void main (String[] args){! System.out.println("Please enter the number in feet");! Scanner input=new Scanner(System.in);! double num=input.nextDouble();! double meter=num*0.305;! ! System.out.println("Your length in meter is"+ meter);! ! }! }

2.4 import java.util.*;! public class Poundstokilograms{! public static void main (String[] args){! System.out.println("Please enter the number in pounds");! Scanner input=new Scanner(System.in);! double pounds=input.nextDouble();! double kilograms=pounds*0.454;! ! System.out.println("Your weight in kilograms is"+ kilograms);! ! }! }

2.5 pencil code

subtotal = 0; rate = 0; gratuity = 0; total = 0; readnum('ENTER THE SUBTOTAL', function(num1) { subtotal = num1; readnum('Enter your gratuity rate as a DECIMAL', function(num2) { rate = num2; gratuity = num1*num2; total = (gratuity+subtotal); write('The gratuity is '+gratuity+', and the total is'+ total ); }); }); Java code ( still has one error) import java.util.*;! public class Gratuity{! public static void main (String[] args){! Scanner input= new Scanner(System.in);! System.out.println("Please enter your subtotal");! double subtotal=input.nextDouble();! System.out.println("Please enter your gratuity rate in decimal");! double gratuity rate=input.nextDouble();! double gtotal=gratuity*subtotal ;! double stotal=gtotal+subtotal;! System.out.println("The gratuity is"+gtotal+"and the total is"+stotal);}}

2.7 import java.util.*;! public class Minutes{! public static void main (String[] args){! Scanner input= new Scanner(System.in);! System.out.println("Please enter number of minutes");! int min=input.nextInt();!

int years =min/525600;! int leftover=min%525600 ;! int days=leftover/1440;! System.out.println(min+"Minutes is approximately"+years+"years and"+days+"days.");! }! }

Monday, September 25, 2017

A Boolean value is one with two choices: true or false, yes or no, 1 or 0. In Java, there is a variable type for Boolean values: boolean user = true; So instead of typing int or double or string, you just type boolean (with a lower case “b") The

java.lang.System.currentTimeMillis()

current return value may

time

in

milliseconds.The

value

is

a

depends be

measure

on

larger. time

in

millisecond, the

For

unit the

underlying example,

units

of

of

Wednesday, October 4, 2017 PRINTF : THE F MEANS FORMATp P P

//this is excercise for 10.10 on the ppt! ! private Course (String course);! private void main String[]args;!

of

returns

time

of

granularity

operating

many

tens

method

operating

system

the

of

the and

systems

milliseconds.

the

! ! public String[] getStudents()! //indicate the return type is string array data type! {! return Students;! }! ;! ! public Course(String ! ! ! ;! +CourseName(courseName:String)! public String getCourseName();! {! return CourseName;! }! ;! ! public int getNumberOfStudents();! {! return NumberOfStudents;! }! ;! ! Wednesday, November 29, 2017 Final review;

Strings. Strings, which are widely used in Java programming, are a sequence of characters. In the Java programming language, strings are objects. The Java platform provides the String class to create and manipulate strings. The java toString() method is used when we need a string representation of an object. It is defined in Object class. This method can be overridden to customize the String representation of the Object A "Driver class" is often just the class that contains a main. In a real project, you may often have numerous "Driver classes" for testing and whatnot, or you can build a main into any of your

objects and select the runnable class through your IDE, or by simply specifying "java classname." 1. set variable ! 2.constructors! 3.getter n setter! 4. public String toString constructor...


Similar Free PDFs