/* I used Item as class name also see screenshot for indentation*/
/* Item.java */
public class Item {
// Instance variable
private String name;
private double price;
// default constructor
public Item(){
name = "Unknown";
price = 1;
}
// overload constructor
public Item(String name, double price) {
this.name = name;
this.price = price;
}
// Getter and setters
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
/* ItemDriver.java */ // Main function class
import java.util.Scanner;
import javax.swing.JOptionPane;
public class ItemDriver {
public static void main(String[] args) {
Item item1 = new Item(); // using default object
Item item2 = new Item("Ab12",250); // using given name and
price
Scanner sc = new Scanner(System.in); // for user input
System.out.print("Enter name of item: ");
String item = sc.nextLine(); // take item name input
System.out.print("Enter Price of item: ");
double price = sc.nextDouble(); // take price input
Item item3 = new Item(item,price); // using scanner
item = JOptionPane.showInputDialog("Enter name of item: "); // take
item name input
price = Double.parseDouble(JOptionPane.showInputDialog("Enter name
of price: "));
Item item4 = new Item(item,price);// using JOption pane
Item item5 = new Item("BC456",2*item3.getPrice()); // SET double
price of item3 in item5
item1.setPrice((item1.getPrice()+item1.getPrice()*0.1)); //
INCREASE PRICE BY 10%
double totalprice = item1.getPrice() + item2.getPrice() +
item3.getPrice()
+ item4.getPrice() + item5.getPrice(); // find total price
String info = "Item1 Name: "+item1.getName() +" Price:
"+item1.getPrice()+"\n"
+ "Item2 Name: "+item2.getName() +" Price:
"+item2.getPrice()+"\n"
+ "Item3 Name: "+item3.getName() +" Price:
"+item3.getPrice()+"\n"
+ "Item4 Name: "+item4.getName() +" Price:
"+item4.getPrice()+"\n"
+ "Item5 Name: "+item4.getName() +" Price:
"+item5.getPrice()+"\n"
+ "Total Price: "+ totalprice;
JOptionPane.showMessageDialog(null,info);
}
}
/* OUTPUT */
Hi , i have facing problems in both 5 error while i am soloving it can...
In Python a class can inherit from more than one class (Java does not allow this). The resulting class will have all the methods and attributes from the parent classes. Do the following: • Create a class called Person. In the class, define variables for storing date of birth, place of birth, and male/female attributes. In the class, define the constructor method, as well as methods for returning current values of the class attributes. • Create a class called Employee....
QUESTION 1 The following tables form part of a database held in a relational DBMS for storing the information of Customer, Item, Transaction, and temSale A transaction can contain multiple items and an item can be in multiple transactions as depicted in the following sample data Item(itemid, name, category, price Itemid pk) name category price Iteml Pencil Stationery $30 paperStationery Item2 $25 $15 Item3 Cards Stationery S40 Item4 Ink Stationery S13 Item5 Sprite Itemo Food S4 Milk Food Transaction ctransid,...
In C++, Step 1: Implement the Student Class and write a simple main() driver program to instantiate several objects of this class, populate each object, and display the information for each object. The defintion of the student class should be written in an individual header (i.e. student.h) file and the implementation of the methods of the student class should be written in a corresponding source (i.e. student.cpp) file. Student class - The name of the class should be Student. -...
Deliverable A zipped NetBeans project with 2 classes app ZipCode Address Classes Suggestion: Use Netbeans to copy your last lab (Lab 03) to a new project called Lab04. Close Lab03. Work on the new Lab04 project then. The Address Class Attributes int number String name String type ZipCode zip String state Constructors one constructor with no input parameters since it doesn't receive any input values, you need to use the default values below: number - 0 name - "N/A" type...
Java Eclipse Coding question: Use data abstraction (real-world modeling) to come up with 3 instance variables and 2 effectors for a new data type – the class HospitalPatient. You have the freedom to design the instance variables and effectors. instance variables effectors 1. 1. 2. 2. 3. Write the code for class HospitalPatient, according to the requirement above. Include the default constructors with no argument, and the constructor with all arguments. Provide a getter and setter for each individual instance...
Create an Item class, which is the abstract super class of all Items. Item class includes an attribute, description of type String for every item. [for eg. Book] A constructor to initialize its data member of Item class. Override toString() method to return details about the Item class. Create the ExtraCharge interface with the following details. Declare a constant RATE with value 0.25 Declare a method called calculateExtraCharge(), which returns a double value. Create the...
Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance and interface behaviors . The link to the PDF of the diagram is below MotorVehical.pdf Minimize File Preview User Define Object Assignment: Create a Intellij Project. The Intellij project will contain three user defined classes. The project will test two of the User Define Classes by using the invoking each of their methods and printing the results. You are required to create three UML...
Need three seperate files. ShoppingCartManager.java ShoppingCart.java ItemsToPurchase.java These are from part 1 what do you mean by deep study 7.25 LAB*: Program: Online shopping cart (Part 2) Note: Creating multiple Scanner objects for the same input stream yields unexpected behavior. Thus, good practice is to use a single Scanner object for reading input from System.in. That Scanner object can be passed as an argument to any methods that read input This program extends the earlier Online shopping cart program (Consider...
Programming Assignment 6: Object Oriented Programming Due date: Check Syllabus and Canvas Objectives: After successfully completing this assignment, students will practice Object Oriented design and programming by creating a Java program that will implement Object Oriented basic concepts. RetailItem Class: Part 1: Write a class named RetailItem that holds data about an item in a retail store. The class should have the following fields: • description. The description field references a String object that holds a brief description of the...
PART I: Create an abstract Java class named “Student” in a package named “STUDENTS”. This class has 4 attributes: (1) student ID: protected, an integer of 10 digits (2) student name: protected (3) student group code: protected, an integer (1 for undergraduates, 2 for graduate students) (4) student major: protected (e.g.: Business, Computer Sciences, Engineering) Class Student declaration provides a default constructor, get-methods and set-methods for the attributes, a public abstract method (displayStudentData()). PART II: Create a Java class named...