- import java.util.Scanner;
-
-
public class Program01C
-
{
-
-
public static void main(String[] args)
-
{
-
double purchase, totalTax, salesTax, countyTax, total;
-
salesTax = 0.04;
-
countyTax = 0.02;
-
-
-
Scanner keyboard = new Scanner(System.in);
-
System.out.print("Enter the amount of purchase: ");
-
purchase = keyboard.nextInt();
-
-
totalTax = (salesTax + countyTax);
-
total = (((totalTax) * purchase) + purchase);
-
System.out.println("Sales Tax:" + salesTax + "\nCounty Tax:" + countyTax + "\nTotal Sales Tax:" + totalTax + "\nTotal Purchase:" + purchase + "\nTotal Amount of Purchase:" + total);
-
-
I want to add precision to total variable at the end of the program by 2, but forgot how to do it:
-
-
"\nTotal Amount of Purchase:" + total);
-
-
Thanx, Paradox(>")>
-
-
Question num# 2:
-
-
import java.util.Scanner;
-
-
public class Program01B
-
{
-
-
public static void main(String[] args)
-
{
-
double testScore01, testScore02, testScore03, totalAverage, totalAveragemod;
-
-
Scanner keyboard = new Scanner(System.in);
-
System.out.print("Enter Test Score 1:");
-
testScore01 = keyboard.nextInt();
-
System.out.print("Enter Test Score 2:");
-
testScore02 = keyboard.nextInt();
-
System.out.print("Enter Test Score 3:");
-
testScore03 = keyboard.nextInt();
-
-
//Division of 3 testscores plus remainder(Modulus)
-
totalAverage = ((testScore01 + testScore02 + testScore03) / 3);
-
totalAveragemod = ((testScore01 + testScore02 + testScore03) % 3);
-
-
System.out.println("Test Score 1:" + testScore01 + "\nTest Score 2:" + testScore02 + "\nTest Score 3:" + testScore03 + "\nTotal Average of Test Scores:" + totalAverage + "." + totalAveragemod);
-
}
-
}
-
The modulus outputs as so:
Enter Test Score 1:80
Enter Test Score 2:90
Enter Test Score 3:80
Test Score 1:80.0
Test Score 2:90.0
Test Score 3:80.0
Total Average of Test Scores:83.33333333333333.1.0
How can I make so it outputs in decimal form(00.00) or if it needs to have precision added to it then ok, but it has 3 decimal places so IDK!
Thanx, Paraodx(>")>
6 3121 @horace1
That article is soooo old; better read what r035198x wrote.
kind regards,
Jos
I changed the code to this: - //Robert Burns
-
//Feb. 5, 2009
-
//paradox6996@gmail.com
-
//Program01B-Calculates total average of test scores
-
-
import java.util.Scanner;
-
import static java.lang.Math.*;
-
-
public class Program01B {
-
-
public static void main(String[] args) {
-
-
double testScore01, testScore02, testScore03, totalAverage, totalAveragemod;
-
-
Scanner keyboard = new Scanner(System.in);
-
System.out.print("Enter Test Score 1:");
-
testScore01 = keyboard.nextDouble();
-
System.out.print("Enter Test Score 2:");
-
testScore02 = keyboard.nextDouble();
-
System.out.print("Enter Test Score 3:");
-
testScore03 = keyboard.nextDouble();
-
-
//Division of 3 test scores plus remainder(Modulus)
-
totalAverage = ((testScore01 + testScore02 + testScore03) / 3);
-
totalAveragemod = ((testScore01 + testScore02 + testScore03) % 3);
-
-
System.out.printf("Test Score 1:" + testScore01 + "\nTest Score 2:" + testScore02 + "\nTest Score 3:" + testScore03 + "\nTotal Average of Test Scores:%.2f", totalAverage, Math.ceil(totalAverage));
-
}
-
}
This is the output:
Enter Test Score 1:85
Enter Test Score 2:90.5
Enter Test Score 3:88.2
Test Score 1:85.0
Test Score 2:90.5
Test Score 3:88.2
Total Average of Test Scores:87.90
Thanx for the help, Paradox(>")>
You don't need that variable totalAveragemod at all.
kind regards,
Jos
@JosAH
I know I took it out to get this: - //Robert Burns
-
//Feb. 5, 2009
-
//paradox6996@gmail.com
-
//Program01B-Calculates total average of test scores
-
-
import java.util.Scanner;
-
-
//Math class so I can truncate doubles to get nice looking decimals
-
import static java.lang.Math.*;
-
-
public class Program01B {
-
-
public static void main(String[] args) {
-
-
double testScore01, testScore02, testScore03, totalAverage;
-
-
Scanner keyboard = new Scanner(System.in);
-
System.out.print("Enter Test Score 1:");
-
testScore01 = keyboard.nextDouble();
-
System.out.print("Enter Test Score 2:");
-
testScore02 = keyboard.nextDouble();
-
System.out.print("Enter Test Score 3:");
-
testScore03 = keyboard.nextDouble();
-
-
//Division of 3 test scores
-
totalAverage = ((testScore01 + testScore02 + testScore03) / 3);
-
-
System.out.printf("Test Score 1: " + testScore01 + "\nTest Score 2: " + testScore02 + "\nTest Score 3: " + testScore03 + "\nTotal Average of Test Scores: %.2f", totalAverage, Math.ceil(totalAverage));
Sign in to post your reply or Sign up for a free account.
Similar topics
by: RobertMaas |
last post by:
After many years of using LISP, I'm taking a class in Java and finding
the two roughly comparable in some ways and very different in other
ways. Each has a decent size library of useful utilities...
|
by: patrick_woflian |
last post by:
hey guys, im just writing a basic calculation at the moment, before
building on it for an A-Level piece of work. i can add/divide etc...
two numbers together yet i am having a major problem with...
|
by: Jobs |
last post by:
Download the JAVA , .NET and SQL Server interview with answers
Download the JAVA , .NET and SQL Server interview sheet and rate
yourself. This will help you judge yourself are you really worth of...
|
by: jweaver |
last post by:
I'm having a problem getting back appropriate metadata for stored
procedures from MS SQL Server 2000 and 2005.
I've created a simple stored procedure that has an output param that
is a cursor.
...
|
by: chad_walters |
last post by:
Does JavaScript have a mechanism to provide the equivalent of Java's
Double.doubleToLongBits() and the reverse operation
Double.longBitsToDouble?
...
|
by: King Raz |
last post by:
The shootout site has benchmarks comparing different languages. It
includes C# Mono vs Java but not C# .NET vs Java. So I went through
all the benchmark on the site ...
...
|
by: aarklon |
last post by:
Hi all,
See:- http://www.cs.princeton.edu/introcs/faq/c2java.html
for C vs Java in number crunching
http://husnusensoy.blogspot.com/2006/06/c-vs-java-in-number-crunching.html
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |