reate a new project called Trunc.java either by modifying TwoDPs. Trunc.java should loop around getting floating point (i.e. type double) numbers and displaying both the number and the running total to the nearest whole number. The program will finish when a number is entered outside of the range -100 to 100. The program should use methods to check whether the number is in this range, and then rounded to the nearest whole number without using Round method.
reate a new project called Trunc.java either by modifying TwoDPs. Trunc.java should loop around getting floating point (i.e. type double) numbers and displaying both the number and the running total to the nearest whole number. The program will finish when a number is entered outside of the range -100 to 100. The program should use methods to check whether the number is in this range, and then rounded to the nearest whole number without using Round method.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Create a new project called Trunc.java either by modifying TwoDPs. Trunc.java should loop around getting floating point (i.e. type double) numbers and displaying both the number and the running total to the nearest whole number. The

Transcribed Image Text:double posNum
num;
if (neg)posNum
//add 0.005 to the posNum, so that truncating nPlus
//is equivalent to rounding posNum
double nPlus =
-
num;
posNum+0.005;
//extract the whole number part and the rest
int whole =
(int)nPlus;
double rest= nPlus
whole;
//multiply the rest by 100
//truncate, csat and make sure there
//are some
zeros in front of small numbers
(int) (100.0*rest +100.0);
int temp
//make a string version of temp
String s
+temp;
int I
s.length();
String sign="";
if (neg) sign="-";
//display the message, sign,whole part and last two digits of s
System.out.println (msg +"" +sign +whole +"." +s.substring(I-
2,1));
}
}
//end of class
![import java.util.Scanner;
//Two Dps.java
//Displays running total of numbers in lines of standard
//input correct to two decimal places.
//Uses an out of range number(<-100 or >100) to quit.
public class TwoDPs{
public static void main (String [] args) {
new Scanner(System.in);
Scanner input
double total=0;
boolean flag=true;
System.out.println ("Use an out of range entry <-100 or >100 to
quit.");
while(flag){
System.out.println ("Enter a number on a line:");
double d
input.nextDouble ();
if (outOfRange (d)) {
flag=false;
}
else{
dispTwoDPs ("The number value is: ",d);
total = total + d;
dispTwoDPs ("The total is: ",total);
System.out.println ();
System.out.println ("Next.");
} //end of else
}//end of while
System.out.println ("You quit.");
}//end of main
static boolean outOfRange (double d) {
if (d<-100) return true;
if (d>100) return true;
return false;
}
static void dispTwoDPs (String msg, double num) {
//display on screen the message msg
//followed by num correct to two decima places
//with both decimal values showing even if they are zero
//record whetherthe number is negative
boolean neg = (num < 0);
//make a positive version of the number](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F729ec532-279a-4407-9535-7c93354b6b31%2F228d6762-6524-46ed-ae3e-1ccaf9e215a3%2Fnsbeo8_processed.jpeg&w=3840&q=75)
Transcribed Image Text:import java.util.Scanner;
//Two Dps.java
//Displays running total of numbers in lines of standard
//input correct to two decimal places.
//Uses an out of range number(<-100 or >100) to quit.
public class TwoDPs{
public static void main (String [] args) {
new Scanner(System.in);
Scanner input
double total=0;
boolean flag=true;
System.out.println ("Use an out of range entry <-100 or >100 to
quit.");
while(flag){
System.out.println ("Enter a number on a line:");
double d
input.nextDouble ();
if (outOfRange (d)) {
flag=false;
}
else{
dispTwoDPs ("The number value is: ",d);
total = total + d;
dispTwoDPs ("The total is: ",total);
System.out.println ();
System.out.println ("Next.");
} //end of else
}//end of while
System.out.println ("You quit.");
}//end of main
static boolean outOfRange (double d) {
if (d<-100) return true;
if (d>100) return true;
return false;
}
static void dispTwoDPs (String msg, double num) {
//display on screen the message msg
//followed by num correct to two decima places
//with both decimal values showing even if they are zero
//record whetherthe number is negative
boolean neg = (num < 0);
//make a positive version of the number
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 3 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education