Question

C# for beginners (Methods and Properties, Data types) WorkStation:- Visual Studio 2019 Create a class called...

C# for beginners (Methods and Properties, Data types)

WorkStation:- Visual Studio 2019


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 – a part number (type int), a part description (type string), a quantity of the item being purchased (type int) and a price per item (type decimal). Your class should have a constructor that initializes the four instance variables. Provide a property with a get and set for each instance variable. In addition, provide a method named GetInvoiceAmount that calculates the invoice amount (i.e. multiplies the quantity by price per item), then returns the amount as a decimal value. If the quantity is negative, it should be left unchanged. Similarly, if the price per item is negative, it should be left unchanged.

Create the class diagram for class Invoice.

Write a test console application named InvoiceTest that demonstrates class Invoice’s capabilities. Allow user to enter invoice information. Use properties and methods of class Invoice to process the information and output the results

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

Visual C# Console Application

Code for Invoice.cs:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace InvoiceProject //Change this namespace if you save project with different name.

{

public class Invoice

{

//instance variables

private string partNumber;

private string partDescription;

private int quantity;

private decimal pricePerItem;

//Constructor

public Invoice(string part, string description, int quantity, decimal price)

{

PartNumber = part;

Description = description;

Quantity = quantity;

Price = price;

}//end constructor

// PartNumber Property

public string PartNumber

{

get

{

return partNumber;

}

set

{

partNumber = value;

}

}

// Description Property

public string Description

{

get

{

return partDescription;

}

set

{

partDescription = value;

}

}

//Method GetInvoiceAmount() returns the total invoice

public decimal GetInvoiceAmount()

{

return Price * Quantity;

}

//Begin Instance Variable Property Assignment

public int Quantity

{

get

{

return quantity;

} //end get

set

{

if (value >= 0)

quantity = value;

} //end set

}//end property Quantity

public decimal Price

{

get

{

return pricePerItem;

} //end get

set

{

if (value >= 0)

pricePerItem = value;

} //end set

}//end property Price

}//end Invoice class

}


Rename the Program.cs file to InvoiceTest.cs in the solution explorer.
Code for InvoiceTest.cs:
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace InvoiceProject

{

class InvoiceTest

{

static void Main(string[] args)

{

Invoice invoice1 = new Invoice("AV676","Intro to C#", 50, 250);

Invoice invoice2 = new Invoice("IS542", "Starting out with VB", 5, 50);

Console.WriteLine("*********INVOICE 1*********");

Console.WriteLine("Part number : {0}", invoice1.PartNumber);

Console.WriteLine("Description : {0}", invoice1.Description);

Console.WriteLine("Price : {0}", invoice1.Price);

Console.WriteLine("Quantity : {0}", invoice1.Quantity);

Console.WriteLine("Total : {0}", invoice1.GetInvoiceAmount());

Console.WriteLine("*********INVOICE 2*********");

Console.WriteLine("Part number : {0}", invoice2.PartNumber);

Console.WriteLine("Description : {0}", invoice2.Description);

Console.WriteLine("Price : {0}", invoice2.Price);

Console.WriteLine("Quantity : {0}", invoice2.Quantity);

Console.WriteLine("Total : {0}", invoice2.GetInvoiceAmount());

Console.ReadKey();

}

}

}

Note: Add a Class File to the Project (Right-Click on the solution, Add->Class) and Save it as Invoice.cs

Add a comment
Know the answer?
Add Answer to:
C# for beginners (Methods and Properties, Data types) WorkStation:- Visual Studio 2019 Create a class called...
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
  • Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and...

    Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and a driver program called invoiceDriver.cpp. The class Invoice is used in a hardware store to represent an invoice for an item sold at the store. An invoice class should include the following: A part number of type string A part description of type string A quantity of the item being purchased of type int A price per item of type int A class constructor...

  • In JAVA 1. Create a class called Rectangle that has integer data members named - length...

    In JAVA 1. Create a class called Rectangle that has integer data members named - length and width. Your class should have a default constructor (no arg constructor) Rectangle() that initializes the two instance variables of the object Rect1. The second overloading constructor should initializes the value of the second object Rect2. The class should have a member function named GetWidth() and GetLength() that display rectangle's length and width. OUTPUT: Rectl width: 5 Rectl length: 10 Enter a width :...

  • Using Java, Class Invoice could be used by a hardware store to represent an invoice for...

    Using Java, Class Invoice could be used by a hardware store to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables—a part number, a part description, a quantity of the item being purchased, and a price per item. Code the class with the instance variables and a constructor for the class that initializes the four instance variables with values received by parameters of the same name. TT T...

  • 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....

  • Exercise 02: Based on LINQ extension methods. [15 marks] Create an Invoice class which includes four...

    Exercise 02: Based on LINQ extension methods. [15 marks] Create an Invoice class which includes four properties - a PartNumber ( type int), a PartDescription ( type string), a Quantity of item being purchased (type int) and a Pricel type decimal). Use the following sample data for Invoice class objects: Quantity 7 Part Number 87 24 7 77 39 68 Part Description Electric Sander Power Saw Sledge Hammer Hammer Lawn Mower Screw Driver Jig saw 18 11 76 3 Price...

  • JAVA Use the class, Invoice, provided to create an array of Invoice objects. Class Invoice includes...

    JAVA Use the class, Invoice, provided to create an array of Invoice objects. Class Invoice includes four instance variables; partNumber (type String), partDescription (type String), quantity of the item being purchased (type int0, and pricePerItem (type double). Perform the following queries on the array of Invoice objects and display the results: Use streams to sort the Invoice objects by partDescription, then display the results. Use streams to sort the Invoice objects by pricePerItem, then display the results. Use streams to...

  • Need help to create general class Classes Data Element - Ticket Create an abstract class called...

    Need help to create general class Classes Data Element - Ticket Create an abstract class called Ticket with: two abstract methods called calculateTicketPrice which returns a double and getld0 which returns an int instance variables (one of them is an object of the enumerated type Format) which are common to all the subclasses of Ticket toString method, getters and setters and at least 2 constructors, one of the constructors must be the default (no-arg) constructor. . Data Element - subclasses...

  • C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (Strin...

    C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (String) edition ( int) published year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method// that return sting representation of Book object. 2-Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title...

  • Visual C# C# Visual Studio 2017 You are to create a class object called “Employee” which included eight private variable...

    Visual C# C# Visual Studio 2017 You are to create a class object called “Employee” which included eight private variables - firstN - lastN - idNum -wage: holds how much the person makes per hour -weekHrsWkd: holds how many total hours the person worked each week. - regHrsAmt: initialize to a fixed amount of 40 using constructor. - regPay - otPay After going over the regular hours, the employee gets 1.5x the wage for each additional hour worked. Methods: -...

  • JAVA HELP (ARRAYS) Assignment Create a class named Module4 containing the following data members and methods...

    JAVA HELP (ARRAYS) Assignment Create a class named Module4 containing the following data members and methods (note that all data members and methods are for objects unless specified as being for the entire class) 1) Data members: none 2) Methods a. A method named displayContents that accepts an array of type int and prints their values to the b. A method named cemoveNegatives that accepts an array of type int, copies all its non-negative the new array should be 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