Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Just provide the coding where it says: //PLEASE PUT YOUR WORK HERE //PLEASE END YOUR WORK HERE The questions are provided before the starting of

Just provide the coding where it says:

//PLEASE PUT YOUR WORK HERE //PLEASE END YOUR WORK HERE

The questions are provided before the starting of the codes as well.

All sub-parts need to be answered. All the codes are provided. Must be in Java.

1.A.

You are given two variables, already declared and assigned values:

one of type double, named totalShipmentWeight, containing the weight of the shipment

the other of type int, named numberOfBooks, containing the number of textbooks in the shipment.

Write an expression that calculates and outputs the the weight of one book.

Code:

import java.util.*;

/** * The following is the only class of the program and contains all * program code. The program starts running in the main() of this class. */

public class Operators01 {

/** * Main method that runs when the program is started. */ public static void main(String[] args) { Scanner in = new Scanner(System.in); double totalShipmentWeight = in.nextDouble(); int numberOfBooks = in.nextInt(); //PLEASE PUT YOUR WORK HERE

//PLEASE END YOUR WORK HERE System.out.println("END OF OUTPUT"); } }

1.B.

Assume that an int variable number that has already been declared, and initialized to a positive value.

Declare an integer variable lastDigit and initialize its value to the last (rightmost) digit of numer.

Code:

import java.util.*; import java.text.DecimalFormat;

/** * The following is the only class of the program and contains all * program code. The program starts running in the main() of this class. */

public class Operators02 {

/** * Main method that runs when the program is started. */ public static void main(String[] args) { //Instantiate new scanner to read from the console. Scanner in = new Scanner( System.in );

//Read in length int number = in.nextInt(); //PLEASE PUT YOUR WORK HERE

//PLEASE END YOUR WORK HERE //Output the expected test output System.out.println(lastDigit); System.out.println("END OF OUTPUT");

} }

1.C.

Assume that priceInCents is an integer variable whose value is the price in cents of an item.

Assuming the item is paid for with a minimum amount of change and just single dollars, declare an integer variable dollarsNeeded and initialize it to the number of single dollars that would have to be paid.

Code:

import java.util.*;

/** * The following is the only class of the program and contains all * program code. The program starts running in the main() of this class. */

public class Operators03 {

/** * Main method that runs when the program is started. */ public static void main(String[] args) { //Instantiate new scanner to read from the console. Scanner in = new Scanner( System.in );

//Read in integer from the console. int priceInCents = in.nextInt();

//PLEASE PUT YOUR WORK HERE

//PLEASE END YOUR WORK HERE //Output the expected test output System.out.println(dollarsNeeded); System.out.println("END OF OUTPUT"); } }

1.D.

Assume that priceInCents is an integer variable whose value is the price in cents of an item.

Assuming the item is paid for with a minimum amount of change and just single dollars, declare an integer variable named changeNeeded and intialize it to the amount of change (in cents) that would have to be paid.

Code:

import java.util.*;

/** * The following is the only class of the program and contains all * program code. The program starts running in the main() of this class. */

public class Operators04 {

/** * Main method that runs when the program is started. */ public static void main(String[] args) { //Instantiate new scanner to read from the console. Scanner in = new Scanner( System.in );

//Read in integer from the console. int priceInCents = in.nextInt();

//PLEASE PUT YOUR WORK HERE

//PLEASE END YOUR WORK HERE //Output the expected test output System.out.println(changeNeeded); System.out.println("END OF OUTPUT"); } }

1.E.

Assume that priceInCents is an integer variable whose value is the price in cents of an item.

Write a statement that prints the value of price in the form X dollars and Y cents on a line by itself.

e.g. If the value of price was 1253, your code would print "12 dollars and 53 cents". If the value was 751 it would print "7 dollars and 51 cents". If the value was 43 your code would print "0 dollars and 43 cents".

Code:

import java.util.*;

/** * The following is the only class of the program and contains all * program code. The program starts running in the main() of this class. */

public class Operators05 {

/** * Main method that runs when the program is started. */ public static void main(String[] args) { //Instantiate new scanner to read from the console. Scanner in = new Scanner( System.in );

//Read in integer from the console. int priceInCents = in.nextInt();

//PLEASE PUT YOUR WORK HERE

//PLEASE END YOUR WORK HERE //Output the expected test output System.out.println("END OF OUTPUT"); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Python Programming MySQL MongoDB OOP And Tkinter

Authors: R. PANNEERSELVAM

1st Edition

9357011331, 978-9357011334

More Books

Students also viewed these Databases questions

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago