02 Laboratory Exercise 1(14)

  • Uploaded by: Joebanezair Buton Buatona
  • Size: 166.6 KB
  • Type: PDF
  • Words: 227
  • Pages: 3
Report this file Bookmark

* The preview only shows a few pages of manuals at random. You can get the complete content by filling out the form below.

The preview is currently being created... Please pause for a moment!

Description

//FINAL OUTPUT :

//WHOLE OUTPUT

//Documentation -- I have two classes, 1st Class [“LabExer2.java”] handles the MAIN METHOD & writeOutput() which I fetch all the data coming from the 2nd class. -- 2ND [“_extension.java”] Contains the Encapsulation Method of get&setItemName() and get&setTotalCost() also readInput()

Here are the source code of both two classes. -- LabExer2.java -- _extension.java -----------------------------LabExer2.java -----------------------------public class LabExer2{ //-write the code public void writeOutput(){ _extension ext = new _extension(); ext.readInput(); } //-run the code public static void main(String[] args) { LabExer2 lab = new LabExer2(); lab.writeOutput(); } } -----------------------------_extension.java -----------------------------import java.util.*; class _extension{ //-class variables private String itemName; private double itemPrice; private double amountDue; private int itemQuantity; String item; int item_amount; double price; //-item name public String getItemName(){return itemName;} public void setItemName(String newItemName) {itemName = newItemName;} //-total cost public double getTotalCost(){return amountDue;} public void setTotalCost(int quantity, double price) {itemQuantity = quantity; itemPrice = price; amountDue = quantity * price;}

public void readInput(){ _extension ext = new _extension(); Scanner sc = new Scanner(System.in); //-item name System.out.println("\n-----Output-----\nEnter the name of the item you purchase : "); item = sc.nextLine(); ext.setItemName(item); //-amount System.out.println("Enter quantity and price separated by space : "); item_amount = sc.nextInt();price = sc.nextDouble(); ext.setTotalCost(item_amount,price); //-output System.out.println("\nYou are purchasing " + item_amount + " " + ext.getItemName() + "(s) at " + price + " each. \nAmount Due is : " + ext.getTotalCost()); } }

Similar documents

02 Laboratory Exercise 1(14)

Joebanezair Buton Buatona - 166.6 KB

Exercise 02 - CE18

Kairo Yoshida - 242.9 KB

Exercise Adverbs

Ikhsan Khotib - 295.3 KB

EXERCISE- 1(redo)final

rutul patel - 692.4 KB

Practice Exercise

Prince Chaturvedi - 489.4 KB

tarea 02

URIEL ALATA MAYHUIRE - 340.1 KB

02 Materia

Erick Corilla Contreras - 3.1 MB

Print 02

Fabrizio Bezzolo - 58.2 KB

TAREA # 02

El mundo de Anna paula - 526.9 KB

02 Convocatoria

Copvi - 65.3 KB

02. Tarea2_Grupo67

Maria paula Ballen - 860 KB

© 2024 VDOCS.RO. Our members: VDOCS.TIPS [GLOBAL] | VDOCS.CZ [CZ] | VDOCS.MX [ES] | VDOCS.PL [PL] | VDOCS.RO [RO]