Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should

Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables: Part number (type String) Part description (type String) Quantity of the item being purchased (type int) Price per item (double). Your class should have the following: Provide a get method for each instance variable to read data value. Provide a method named getInvoiceAmount that calculates the invoice amount (i.e., multiplies the quantity by the price per item), then returns the amount as a double value. Create one object of Invoice class and display the invoice such as: Part Number Part Description Invoice Amount is 1100 Candle $ 200.00 Thats what Iwrote, I cant find mistake:

import java.util.*;

public class Invoice {

String number;

String description;

int quantity;

double price;

public Invoice() { /* YOUR CONSTRUCTOR CODE HERE*/ }

public void get_number()

{ Scanner s1 = new Scanner(System.in);

System.out.println("enter number");

number = s1.nextLine(); }

public void get_description() {

Scanner s1 = new Scanner(System.in);

System.out.println("Enter description");

description = s1.nextLine(); }

public void get_quantity() {

Scanner s1 = new Scanner(System.in);

System.out.println("Enter quantity");

quantity = s1.nextInt(); }

public void get_price() {

Scanner s1 = new Scanner(System.in);

System.out.println("Enter price");

price = s1.nextDouble(); }

public double getInvoiceAmount() {

double InvoiceAmount= price*quantity;

return(InvoiceAmount); }

public static void main(String[] args) {

Invoice h1 = new Invoice();

System.out.println("number " + h1.number);

System.out.println("description " + h1.description);

double result = h1.getInvoiceAmount();

System.out.println("invoice amount " + result); } /* ADD YOUR CODE HERE */ }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions

Question

Describe a typical technical skills training program

Answered: 1 week ago