Question

Design a blueprint class that records the payment and purchase made in a CashRegister. (Write the...

Design a blueprint class that records the payment and purchase made in a CashRegister. (Write the code for CashRegister - JAVA) The requirements are as follows:

A) The class/object model will keep track of payments and purchases, both of which can be of type double. To do this, have the two instance variables called payment and purchase.

B) The class/object model will provide the values of the payments and purchases to the client program. To do this, have proper getters for the instance variables

C) The class/object model has method, recordPayment, that will record payments. To do this the method will receive the amount as a parameter and add this amount to the payments. Write a method in the class that will take in an input parameter called amount to add to payment. This method has a void return.

D) The class/object model has method, recordPurchases, that will record purchases. To do this the method will receive the amount as a parameter, and add this amount to the purchases. Write a method in the class that will take in an input parameter called amount, to add to purchase. This method has a void return.

E) The class/object model has a method called printBalance that will print the balance. The value of balance is given by the difference between payments and purchases. The printBalance method takes in no input parameters and has a void return. Format the print output and show the purchase and payment amounts as well.

F) The class/ object model has constructors that will allow default and full-argument overloaded constructors in the client class. Write appropriate default and overloaded constructors . Default values of payment and purchases are set to zero.

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

import java.util.*;

class CashRegister
{
double payment,purchase,balance;

CashRegister()
{
payment=0;
purchase=0;
}

CashRegister(double payment1,double purchase1)
{
payment=payment1;
purchase=purchase1;
}

void recordPayment(double amount)
{
payment=amount;
}

void recordPurchase(double amount)
{
purchase=amount;
}

void printBalance()
{
balance=Math.round(payment-purchase);
System.out.println("Value of payment : "+payment);
System.out.println("Value of purchase : "+purchase);
System.out.println("Balance : "+balance);
}
}


class TestCashRegister
{
public static void main(String args[])
{
double amount;
Scanner sc=new Scanner(System.in);
CashRegister cashReg1=new CashRegister();
System.out.print("\nEnter amount of payment : ");
amount=sc.nextDouble();
cashReg1.recordPayment(amount);
System.out.print("Enter amount of purchase : ");
amount=sc.nextDouble();
cashReg1.recordPurchase(amount);
cashReg1.printBalance();
System.out.println("\n");


CashRegister cashReg2=new CashRegister(0,0);
System.out.print("\nEnter amount of payment : ");
amount=sc.nextDouble();
cashReg2.recordPayment(amount);
System.out.print("Enter amount of purchase : ");
amount=sc.nextDouble();
cashReg2.recordPurchase(amount);
cashReg2.printBalance();
System.out.println("\n");
}
}

PS C:\Users luser\Desktop> javac TestcashRegister.java PS C:\Users\user\Desktop> java TestcashRegister Enter amount of paymen

Add a comment
Know the answer?
Add Answer to:
Design a blueprint class that records the payment and purchase made in a CashRegister. (Write the...
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) 1) Write a blueprint class that tracks the orders made to vendors in a company's...

    (JAVA) 1) Write a blueprint class that tracks the orders made to vendors in a company's product purchasing system. We will create a class called ProductOrder. The requirements are as follows: a) The class ProductOrder has the following private instance variables:productID orderld, quantityRequested quantity Fulfilled all of types integer. We will need separate variables for quantity requested and quantity fulfilled because the vendors may not be able to fulfill the requests completely b) The class/object model will provide the values...

  • Complete the CashRegister class by implementing the methods and adding the correct attributes (characteristics) as discussed...

    Complete the CashRegister class by implementing the methods and adding the correct attributes (characteristics) as discussed in class. Once complete, test the class using the CashRegisterTester class. Make sure you have 3 total items in the cash register. I have two classes, the first is CashRegisterTester below: public class CashRegisterTester { public static void main(String[] args) { //Initialize all variables //Construct a CashRegister object CashRegister register1 = new CashRegister(); //Invole a non-static method of the object //since it is non-static,...

  • In C++ Write a header cashRegister.h and source cashRegister.cpp files for the a CashRegister class. The...

    In C++ Write a header cashRegister.h and source cashRegister.cpp files for the a CashRegister class. The class a CashRegister class has the following data members: 1) an array of 100 Item objects. 2) Cash Register Name and 3) Count of Item objects purchased. 4) Item Cash Total 5) State Tax Rate. The Item is represented as a class in an item.h file. The Item class has the following data members: 1) Name of the item 2) Cost of the item....

  • can you solve it in java please Create the following: 1. Class Invoice ( the node...

    can you solve it in java please Create the following: 1. Class Invoice ( the node ) that includes three instance variables:     int No; // the Invoice No             String CustName; // the Customer name             int Amount; // the Invoice Amount Invoice next; // points to the next Invoice Default and overloaded constructors 2. Class Shop that includes three instance variables: Invoice head; Invoice Tail; Your class should have the following: • A method that initializes the instance variables....

  • Create a UML diagram to help design the class described in exercise 3 below. Do this...

    Create a UML diagram to help design the class described in exercise 3 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Baby class object; should they be private or public? Determine what class methods are required; should they be private or public? Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two constructors:...

  • Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the...

    Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...

  • Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   and please put comment with code! Problem:2 1. Class Student Create...

    Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   and please put comment with code! Problem:2 1. Class Student Create a "Hello C++! I love CS52" Program 10 points Create a program that simply outputs the text Hello C++!I love CS52" when you run it. This can be done by using cout object in the main function. 2. Create a Class and an Object In the same file as...

  • Create a UML diagram to help design the class described in exercise 3 below. Do this...

    Create a UML diagram to help design the class described in exercise 3 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Baby class object; should they be private or public? Determine what class methods are required; should they be private or public? 3. Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two...

  • Write a class called Student. The specification for a Student is: Three Instance fields name -...

    Write a class called Student. The specification for a Student is: Three Instance fields name - a String of the student's full name totalQuizScore - double numQuizesTaken - int Constructor Default construtor that sets the instance fields to a default value Parameterized constructor that sets the name instance field to a parameter value and set the other instance fields to a default value. Methods setName - sets or changes the student name by taking in a parameter getName - returns...

  • Write a Java class called BankAccount (Parts of the code is given below), which has two...

    Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...

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
ADVERTISEMENT