
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
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](https://content.bartleby.com/qna-images/question/729ec532-279a-4407-9535-7c93354b6b31/228d6762-6524-46ed-ae3e-1ccaf9e215a3/nsbeo8_thumbnail.jpeg)
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 stepSolved 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.Similar questions
- Complete in JAVA!arrow_forwardNeeds to be written in java and completed using "for loops" or "nested for loops" and in one program just seperate methods: Write a program that calls these three methods. method 1 should print: 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 method 2 should print: 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 method 3 should create and array and store 10 multiples of 5 and print it out. Use for loop to generate the multiples and then print them out using a second for loop.arrow_forwardWrite a program (use value returning method) that gives simple math quizzes. The program should display two random integers from 1 to 100 that are to be added,The program allows the user to enter the answer. If the answer is correct, display “congratulations”. If the answer is incorrect, the program should show the correct answer. using java programmingarrow_forward
- In Java for zybooks ,Lab 3.27, Write a program that creates a login name for a user, given the user's first name, last name, and a four-digit integer as input. Output the login name, which is made up of the first six letters of the first name, followed by the first letter of the last name, an underscore (_), and then the last digit of the number (use the % operator). If the first name has less than six letters, then use all letters of the first name.arrow_forwardPlease use JAVA GRAPHICS to create a card game in which the dealer shuffles the deck and deals 13 cards to the player. The player sorts her hand and says whether it includes the King of Hearts. Repeat 4 times so all the cards are dealt eventually. Internally, the player should return true or false without writing to the console. In response, the dealer should write on the console, "You won!" or "You loose again."arrow_forwardWrite a method that takes a RegularPolygon as a parameter, sets its number of sides to a random integer between 10 and 20 inclusive, and sets its side length to a random decimal number greater than or equal to 5 and less than 12. Use Math.random() to generate random numbers. This method must be called randomize() and it must take an RegularPolygon parameter. You can call your method in the program's main method so you can test whether it works, but you must remove or comment out the main method before checking your code for a score. You will also need to make sure you do not remove the import statement "import testing.Math" as this is required to check your code for a score.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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