User Input Code
Random :)
Classes/Objects
Arithmetic Operations
100

What is the top-level import statement for using the Scanner class?

import java.util.*;

100

int temperature = 72;

boolean isHot = (temperature > 80); 

System.out.println(isHot);

What is the output?

False

100

What are three things must a class definition have?

a name, attributes (variables), and behaviors (methods).

100

What will the following code print?

int n = 5; 

n ++; 

n ++; 

n += n;  

n--;

System.out.println(n);

13

200

How many tokens appear on the following line of input?

 23 Johnny Smith 22.009.22 "Purple Butterfly" $2.50 "19 23 45" 

10

200

What is the shorthand version of: 

variable = variable + value;

variable += value;

200

I have an object called car. 

It has a String attribute called color.

How can I change the color of the car to white? 

car.color="white";

200

double gpa = 2.5;

gpa --;

What is stored in gpa after running this code?

gpa = 1.5;

300

Ask the user how old they are and store it in variable age (only prompt and assignment).

System.out.print("How old are you? ");

int age = console.nextInt();

300

Accessing an instance variable of a null reference will result in a ...

NullPointerException

300

Describe the relationship between a class and an object?

A class definition specifies the attributes and behavior of every object that will be made.

300

Employees are paid by the hour and only work in 1-hour increments. 

Salaries start at minimum wage, but employees get a $0.50 raise after the first month. 

Which variables would be the best to store the hours and salary of the employees and why?

hours - int - hours are in full number increments

salary - double - money can be a decimal

400

Create an instance of Scanner called console.

Ask the user for their full name.

Store the name in variable name

Scanner console = new Scanner(System.in);

System.out.println("Enter your full name");

String name = console.nextLine();

400

What's the difference between a reference type and a primitive type?

The memory associated with a variable of a reference type holds an object reference value. This value is the memory address of the referenced object. 

A primitive type holds either in int, double, or Boolean. 

400

Write a constructor for class Bird that has variables Color, Region, and Prey.

  public Bird (String r, String p, String c) {

        region = r;

        prey= p;

        color = c;

  }

    

400

double result = 1 / 2

What is stored in result?

result = 0.0

500

Create an instance of Scanner called console.

Ask the user for 2 full numbers.

Store the numbers in variable num1 and num2.

Print the sum of both numbers. 

System.out.println("Please type two numbers: ");

int num1 = console.nextInt();

int num2 = console.nextInt();

System.out.println(num1 + num2);

500

Describe what a constructor is.

What would make a constructor "overloaded."

The constructor of a class is a method that allows us to initialize the attributes variables) of an object when it is first created.

Constructors are said to be overloaded when there are multiple constructors with the same name but a different signature.  

500

The class Bird has variables Color, Region, and Age. 

Write a Java statement to create a new instance of Bird called bird1. 


Bird bird1 = new Bird("region", "prey", 1);

500

int x = 0;

int y = 5;

int z = 1;

y -= 3;

z = x + z;

x = y* z;

y %= 2;

z --;

What is the value of x at the end of this code?

x = 4;

M
e
n
u