Anda di halaman 1dari 6

Chapter 1: Computer Systems

Solutions
Multiple Choice
Solutions
1. c
2. b
3. d
4. e
5. a
6. c
7. b
8. e

True/False
Solutions
1. F
2. T
3. T
4. T
5. F
6. T
7. F
8. T
9. F
10. F

Short Answer Solutions


1.1.

Describe the hardware components of your personal computer or of a computer in a lab to which you have
access. Include the processor type and speed, storage capacities of main and secondary memory, and types of
I/O devices. Explain how you determined your answers.
Processor:
AMD Athlon
800 MHz
Primary Memory:
256 MB of RAM
Secondary Memory
40 GB hard drive
CD-R drive
CompactFlash card reader/writer
Floppy drive
I/O Devices:
Keyboard
Mouse
Monitor
Speakers
Modem
HP PhotoSmart 1115 printer
HP LaserJet 1200 printer
HP ScanJet 4400c scanner
To find the processor and memory information, I accessed the System Information
from the control panel. To find the I/O devices, I looked in the device manager.

1.2.

Why do we use the binary number system to store information on a computer?

2007 Pearson Education

S1

S2

Lewis/Loftus/Cocking, 2/e: Chapter 1 Solutions

Devices that store and move information are less expensive and more reliable if
they have to represent only one of two possible values.

1.3.

If a language uses 240 unique letters and symbols, how many bits would be needed to store each character of a
document? Why?
8 bits are needed to store each character of a document written in a language of
240 unique characters and symbols. 7 bits would be sufficient for only 128
different characters. 8 bits is sufficient for 256 different characters. Because
240 is greater than 128, but not greater than 256, at least 8 bits are needed if
all characters are represented by the same number of bits.

1.4.

Explain the difference between random-access memory (RAM) and read-only memory (ROM).
Both RAM and ROM are random access devices.
but ROM can be only read from.

1.5.

RAM can be written to and read from,

Explain the differences between a local-area network (LAN) and a wide-area network (WAN). What is the
relationship between them?
A LAN is designed to span a short distance and to connect a relatively small
number of computers. A WAN connects two or more LANs, typically across long
distances.

1.6.

What is the total number of communication lines needed for a fully connected point-to-point network of eight
computers? Nine computers? Ten computers? What is a general formula for determining this result?
Eight computers: 28 communication lines
Nine computers: 36 communication lines
Ten computers: 45 communication lines
General formula for n computers: n(n-1)/2, which represents the sum of the numbers
between 1 and n-1

1.7.

Give examples of the two types of Java comments and explain the differences between them.
One kind of comment begins with a double slash (//) and continues to the end of
the line. A second kind of comment begins following an initiating slash-asterisk
(/*) and terminates immediately preceding a terminating asterisk-slash (*/). The
second type of comment can span multiple lines.

1.8.

Why are the following valid Java identifiers not considered good identifiers?

Q is a meaningless name

TotVal

TotalValue would be more meaningful than the abbreviation

theNextValueInTheList

too lengthy; nextValue would serve as well

1.9.

Categorize each of the following situations as a compile-time error, run-time error, or logical error.

multiplying two numbers when you meant to add them

a logical error

dividing by zero

a run-time error

2007 Pearson Education

Lewis/Loftus/Cocking: Chapter 1 Solutions

S3

forgetting a semicolon at the end of a programming statement

a compile-time error

spelling a word wrong in the output

a logical error

producing inaccurate results

a logical error

typing a { when you should have typed (

a compile-time error

1.10.

How many bits are needed to store a color picture that is 400 pixels wide and 250 pixels high? Assume color is
represented using the RGB technique described in this chapter and that no special compression is done.
Allowing 8 bits for each of the 3 (red, green, and blue) color components of each
of 400 x 250 pixels comprising the picture means that 8 x 3 x 400 x 250 =
2,400,000 bits are needed.

Programming Project Solutions


1.1 Test
//********************************************************************
// Test.java
Author: Lewis/Loftus/Cocking
//
// Solution to Programming Project 1.1
//********************************************************************
class test
{
//----------------------------------------------------------------// Prints a statement.
//----------------------------------------------------------------public static void main (String[] args)
{
System.out.println ("An Emergency Broadcast");
}
}
1.2 Test2
//********************************************************************
// Test2.java
Author: Lewis/Loftus/Cocking
//
// Solution to Programming Project 1.2
//********************************************************************
class Test2
{
//----------------------------------------------------------------// Tests various modifications to the program.
//----------------------------------------------------------------public static void main (String[] args)
{
System.out.println ("An Emergency Broadcast");
}
}
//
// a. Change Test to test
//
//
The compiler produces the bytecode file name based on the
//
class name (not the source code file name), so the bytecode
//
file name has a lower case t.
//
2007 Pearson Education

S4

//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//

Lewis/Loftus/Cocking, 2/e: Chapter 1 Solutions

b. Change Emergency to emergency


The program compiles fine, and when executed prints the word
emergency with a lower case e.
c. Remove the first quotation mark in the string literal
The compiler produces an error: String not terminated at end
of line. It interpreted the last quote as the beginning of
a new string literal.
d. Remove the last quotation mark in the string literal
The compiler produces the same error as in part c.
e. Change main to man
The program compiles, but when submitted to the interpreter
it complains that the main method could not be found.
f. Change println to bogus
The compiler produces an error that says method bogus is not
found in class java.io.PrintStream.
g. Change Broadcast to Brxoadxcaxst
As with part b, the output changes to reflect the changes
made to the string literal.
h. Remove the semicolon at the end of the println statement
The compiler produces an error indicating that there is a
semicolon missing at the end of the println statement.
i. Remove the last brace in the program
The compiler produces an error indicating that there should
be a brace at the end of the program.

1.3 Info
//********************************************************************
// Info.java
Author: Lewis/Loftus/Cocking
//
// Solution to Programming Project 1.3
//********************************************************************
public class Info
{
//----------------------------------------------------------------// Prints information about the programmer.
//----------------------------------------------------------------public static void main (String args[])
{
System.out.println("Name
: Lara");
System.out.println("Birthday : March 25");
System.out.println("Hobbies : Sailing, Cooking, Hiking");
System.out.println("Favorite Book
: The Brothers Karamasov");
System.out.println("Favorite Movies : Remains of the Day");
}
}
1.4 Knowledge
//********************************************************************
2007 Pearson Education

Lewis/Loftus/Cocking: Chapter 1 Solutions

// Knowledge.java
Author: Lewis/Loftus/Cocking
//
// Solution to Programming Project 1.4
//********************************************************************
class Knowledge
{
//----------------------------------------------------------------// Prints a phrase in various configurations.
//----------------------------------------------------------------public static void main (String[] args)
{
System.out.println ();
System.out.println ("Knowledge is Power");
System.out.println ();
System.out.println ();
System.out.println ("Knowledge");
System.out.println ("
is");
System.out.println (" Power");
System.out.println ();
System.out.println ();
System.out.println ("==========================");
System.out.println ("|
|");
System.out.println ("|
Knowledge is Power
|");
System.out.println ("|
|");
System.out.println ("==========================");
System.out.println ();
}
}
1.5 Diamond
//********************************************************************
// Diamond.java
Author: Lewis/Loftus/Cocking
//
// Solution to Programming Project 1.5
//********************************************************************
public class Diamond
{
//----------------------------------------------------------------// Prints a diamond
//----------------------------------------------------------------public static void main (String args[])
{
System.out.println("
*");
System.out.println("
***");
System.out.println(" *****");
System.out.println(" *******");
System.out.println("*********");
System.out.println(" *******");
System.out.println(" *****");
System.out.println("
***");
System.out.println("
*");
}
}
1.6 Initials
//********************************************************************
// Initials.java
Author: Lewis/Loftus/Cocking
//
// Solution to Programming Project 1.6
//********************************************************************
class Initials
2007 Pearson Education

S5

S6

Lewis/Loftus/Cocking, 2/e: Chapter 1 Solutions

{
//----------------------------------------------------------------// Prints some initials in block letters.
//----------------------------------------------------------------public static void main (String[] args)
{
System.out.println ();
System.out.println ("JJJJJJJJJJJ
A
LLL");
System.out.println ("JJJJJJJJJJJ
AAA
LLL");
System.out.println ("
JJJ
AA AA
LLL");
System.out.println ("
JJJ
AA
AA
LLL");
System.out.println ("
JJJ
AA
AA
LLL");
System.out.println ("
JJJ
AAAAAAAAA
LLL");
System.out.println ("
JJJ
AAAAAAAAA
LLL");
System.out.println ("JJ
JJJ
AA
AA
LLL");
System.out.println ("JJJJJJJJ
AA
AA
LLLLLLLLLL");
System.out.println ("JJJJJJJJ
AA
AA
LLLLLLLLLL");
System.out.println ();
}
}

2007 Pearson Education

Anda mungkin juga menyukai