Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a loop to integer values until the user enters a -999 to quit. When the

ID: 3562805 • Letter: 1

Question

1. Write a loop to integer values until the user enters a -999 to quit. When the user is done, print the sum of the numbers entered.

//put your import statement here:

public static void main( String[ ] args {

int number;
//declare a Scanner reference variable

//declare other needed variables
//create a Scanner object to read data from the keyboard

//write the code to perform the task

}

2) Suppose you have already written the class for a Bowler. The Bowler class has two fields, a full name and a high score.

Write the main( ) method to create two instances of this Bowler class. Get the input from the user and send the name and high score values to the constructor method of the Bowler class.

Explanation / Answer

//1. Write a loop to integer values until the user enters a -999 to quit. When the user is done, print the sum of the numbers entered.
//put your import statement here:
import java.util.*;
public static void main( String[ ] args {

int number;
//declare a Scanner reference variable
Scanner in = null;
//declare other needed variables
int sum = 0;
//create a Scanner object to read data from the keyboard
in = new Scanner(System.in);
//write the code to perform the task
System.out.println("enter a number (-999 to stop):");
number = in.nextInt();
while(number !=-999)
{
sum = sum +number;
System.out.println("enter a number (-999 to stop):");
number = in.nextInt();
}
}

2) Suppose you have already written the class for a Bowler. The Bowler class has two fields, a full name and a high score.
Write the main( ) method to create two instances of this Bowler class. Get the input from the user and send the name and
high score values to the constructor method of the Bowler class.

public static void main(String[] args)
{
String name;
int score;
Scanner in = new Scanner(System.in);
System.out.println("Enter your name :");
name = in.next();
System.out.println("Enter your name :");
score = in.nextInt();
Bowler B1 = new Bowler(name,score);
System.out.println("Enter your name :");
name = in.next();
System.out.println("Enter your name :");
score = in.nextInt();
Bowler B2 = new Bowler(name,score);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote