Question

Write a java class that obtains an integer value from a customer that represents the number...

Write a java class that obtains an integer value from a customer that represents the number of photocopies to be printed. Then, calculate and display the total job cost. Your "if" test will determine whether or not there are more than 50 copies involved.

You will need to use the DecimalFormat class to obtain the proper number of decimal places shown in the output sample. Review Notes 3.

Base your calculations on these rates: the cost for up to and including 50 copies is $0.07 per copy. Copies in excess of 50 copies cost $0.04 per copy, plus the cost of the first 50 at the $0.07 rate.

Example: 56 copies would cost .07 x 50 + .04 x 6 = $3.50 + $0.24 = $3.74 (these are the actual numeric results)


Algorithm and coding considerations:

Declare one input-capture variable to store the total number of copies desired. Name it iCopies.

Declare another variable to store the calculated number of copies over 50. Name it iCopiesOver50.

Declare one (and only one) variable named dCost to use as the expression-result variable when calculating cost. It CAN be done: dCost can be accumulated.

Use the if block's true branch for copies <= 50 and the false branch for copies greater than 50.

Output the total cost within each branch (i.e., repeat the output statement in the <= 50 branch as well as the > 50 branch). Using this approach, all the output will occur INSIDE the if block.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.text.DecimalFormat;

import java.util.Scanner;

public class Tester3{

      public static void main(String args[] ){

            Scanner scan = new Scanner(System.in);

            //Getting the input from user

            System.out.print("Enter the number of phoocopies to be printed: ");

            int iCopies = scan.nextInt();

            int iCopiesOver50=0;

            double dCost=0;

            //Using DecimalFormat to display the output to 2 decimal places

            DecimalFormat df = new DecimalFormat();

            df.setMaximumFractionDigits(2);

            //Using if condition to validate the user input

            if(iCopies>50){

                  iCopiesOver50 = iCopies-50;

                  dCost = 50*0.07 + iCopiesOver50*0.04;

                  System.out.println("Total cost to print: "+df.format(dCost)+"$");

            }

            else{

                  dCost = iCopies*0.07;

                  System.out.println("Total cost to print: "+df.format(dCost)+"$");

            }

            scan.close();

      }

}

Output:

Add a comment
Know the answer?
Add Answer to:
Write a java class that obtains an integer value from a customer that represents the number...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • java This lab is intended to give you practice creating a class with a constructor method,...

    java This lab is intended to give you practice creating a class with a constructor method, accessor methods, mutator methods, equals method , toString method and a equals method. In this lab you need to create two separate classes, one Student class and other Lab10 class. You need to define your instance variables, accessor methods, mutator methods, constructor, toString method and equals method in Student class. You need to create objects in Lab10 class which will have your main method...

  • Write a Java program that uses six grades as integer values and calculate their average. Result...

    Write a Java program that uses six grades as integer values and calculate their average. Result must be printed as a floating data type. Design your program using the following specifications. 1. You must declare integer variables to hold the grades. Assume grades are always integer. 2. Result must be stored in a separate variable. 3. All numbers in the output must be in floating data type. 4. All grades must be displayed in one significant digit floating number. 5....

  • Anyone helps me in a Java Languageif it it is possible thanks. Write a class called...

    Anyone helps me in a Java Languageif it it is possible thanks. Write a class called Player that holds the following information: Team Name (e.g., Ravens) . Player Name (e.g., Flacco) . Position's Name (e.g. Wide reciver) . Playing hours per week (e.g. 30 hours per week). Payment Rate (e.g., 46 per hour) . Number of Players in the Team (e.g. 80 players) . This information represents the class member variables. Declare all variables of Payer class as private except...

  • Look at this partial class definition, and then answer questions a - b below: Class Book...

    Look at this partial class definition, and then answer questions a - b below: Class Book    Private String title    Private String author    Private String publisher    Private Integer copiesSold End Class Write a constructor for this class. The constructor should accept an argument for each of the fields. Write accessor and mutator methods for each field. Look at the following pseudocode class definitions: Class Plant    Public Module message()       Display "I'm a plant."    End Module...

  • in java Write a class called Flight that represents an airline flight. (50 pts) It should...

    in java Write a class called Flight that represents an airline flight. (50 pts) It should contain instance data that represents the airline name, flight number, departure city, destination cities, and flight price.   Define the Flight constructor to accept and initialize all instance data.   Overload the Flight constructor such that the initial value of instance data airline name by Delta.   Include getter and setter methods for all instance data.   Include a toString method that returns a one-line description of the...

  • Java Programming The following is about creating a class Fish and testing it. In every part,...

    Java Programming The following is about creating a class Fish and testing it. In every part, correct any syntax errors indicated by NetBeans until no such error messages. (i) Create a class Fish with the attributes name and price. The attributes are used to store the name and the price of the fish respectively. Choose suitable types for them. You can copy the class Counter on p.17 of the unit and modify the content. Copy the content of the file...

  • Write a Java program to read customer details from an input text file corresponding to problem...

    Write a Java program to read customer details from an input text file corresponding to problem under PA07/Q1, Movie Ticketing System The input text file i.e. customers.txt has customer details in the following format: A sample data line is provided below. “John Doe”, 1234, “Movie 1”, 12.99, 1.99, 2.15, 13.99 Customer Name Member ID Movie Name Ticket Cost Total Discount Sales Tax Net Movie Ticket Cost Note: if a customer is non-member, then the corresponding memberID field is empty in...

  • Write a class XXX_Course • A course has a name, a course number, a department code...

    Write a class XXX_Course • A course has a name, a course number, a department code (for example, CS, MATH) and a room number. • Include a static variable used to assign the course number to each Course in the constructor. The value of the variable will start at 1000. • Write the instance variables, the accessors (getters), the mutators (setters) and two constructors for the class. One of the constructors should be the no args constructor Write a second...

  • Write a grading program in Java for a class with the following grading policies: There are...

    Write a grading program in Java for a class with the following grading policies: There are three quizzes, each graded on the basis of 10 points. There is one midterm exam, graded on the basis of 100 points. There is one final exam, graded on the basis of 100 points. The final exam counts for 40% of the grade. The midterm counts for 35% of the grade. The three quizzes together count for a total of 25% of the grade....

  • [IN JAVA] Copy the following code into your main.cpp and complete it public class Main { pub...

    [IN JAVA] Copy the following code into your main.cpp and complete it public class Main { public static void main(String [] args) { int [] array1 = {5, 8, 34, 7, 2, 46, 53, 12, 24, 65}; int numElements = 10; System.out.println("Part 1"); // Part 1 // Enter the statement to print the numbers in index 5 and index 8 // put a space in between the two numbers and a new line at the end // Enter the statement...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT