Escolar Documentos
Profissional Documentos
Cultura Documentos
Problem 1 (3 points)
Answer the following:
a) What is an identifier (variable name)?
Identifiers are the names of variables, methods, classes. In a system
program, the String and println are identifiers. It tells the program
what to look for and do exactly what is needed. The variable has a
name in the program.
b) What are the rules for naming an identifier (variable name)?
Variables can only start with a letter, and underscore (_) or a dollar
sign $ and must have no spaces. When calling a variable, it is
important everything matches as they are case senstitive.
Problem 2 (3 points)
Identify the type of data, integer, double, or string, and a valid
identifier (variable name) for the following types of data:
a) permanent city
String
b) average number of students in a class
Double
c) total number of students in a class
Integer
d) grade point average
Double
e) client name
String
f) insurance discount based on age
Integer for age
Double for discount (number times % = decimal)
This can also be a boolean. Does the customer qualify for the age? If
yes, then what discount based off age, if NO then they do not qualify.
Problem 3 (3 points)
Identify the syntax errors in the following identifier (variable)
definitions
a) int 1num = 0;
2
Problem 4 (3 points)
Copy the following program into BlueJ, compile, and execute.
import java.io.*;
import java.lang.*;
import java.util.*;
public class Art
{
public static void main(String[] args)
{
int n = 15;
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < (n - i); j++)
System.out.print(" ");
for (int j = 1; j <= i; j++)
System.out.print("*");
for (int k = 1; k < i; k++)
System.out.print("*");
System.out.println();
}
for (int i = n - 1; i >= 1; i--)
{
for (int j = 0; j < (n - i); j++)
System.out.print(" ");
for (int j = 1; j <= i; j++)
System.out.print("*");
for (int k = 1; k < i; k++)
System.out.print("*");
System.out.println();
}
}
}
It draws out two diamonds using *. The first diamond has the top
section cut off and the second diamond under it is an entire diamond.
Problem 5 (3 points)
Copy the following program into BlueJ. Compile and execute. Use
this code to answer the following questions:
public class Cube
{
public static void main()
{
double height = 3.0; \\ inches
double cubeVolume = height * height * height;
double surfaceArea = 8 * height
System.out.print("Volume = " + surfaceArea);
System.out.print("Surface area = + surfaceArea);
}