Recent questions in Java Programming

No documents found, press Enter to search

How to code logic gates(And,Nand) Using Oops concepts in java

OOPS CONCEPTS LIKE INHERITANCE, ConstructioConstruct
0

computer science for java programming

The program should then read the same file to calculate the student module mark by finding the average of the quizzes and display the records on screen.
0
hamza001-avatar
over 7 years ago

Java programming exercise.

You are to write a set of supporting classes for a simple shopping program. Prices are expressed using doubles and quantities are expressed as simple integers (e.g., you can’t buy 2.345 of something). Notice that some of the items have a discount when you buy more. For example, product X normally costs $3.95 each, but you can buy 10 for $19.99. These items have, in effect, two prices: a single item price and a bulk item price for a bulk quantity. When computing the price for such an item, apply as many of the bulk quantity as you can and then use the single item price for any leftovers. For example, the user is ordering 12 buttons that cost $0.99 each but can be bought in bulk, 10 for $5.00. The first 10 are sold at that bulk price ($5.00) and the two extras are charged at the single item price ($0.99 each) for a total of $6.98.You are to implement four classes that are used to make this code work. You should first implement a Class called Item that will store information about the individual items. It should have the following public methods.*-Description of Method Item(name, price):-Constructor that takes a name and a price as arguments. The name will be aString and the price will be a double. Should throw anIllegalArgumentException if price is negative.*-Description of Method Item(name, price, bulk quantity,bulk price):- Constructor that takes a name and a single-item price and a bulk quantity and abulk price as arguments. The name will be a String and the quantity will be aninteger and the prices will be doubles. Should throw anIllegalArgumentException if any number is negative.*-Description of Method priceFor(quantity):-Returns the price for a given quantity of the item (taking into account bulk price,if applicable). Quantity will be an integer. Should throw anIllegalArgumentException if quantity is negative.*-Description of Method toString() :-Returns a String representation of this item: name followed by a comma and space followed by price. If this has a bulk price, then you should append anextra space and a parenthesized description of the bulk pricing that has the bulkquantity, the word “for” and the bulk price.You should implement a Class called Catalog that stores information about a collection of these items. It should have the following public methods.*-Description of Method Catalog(name):-Constructor that takes the name of this catalog as a parameter. The name will bea String.*-Description of Method addItem()-Adds an Item at the end of this list.*-Description of Method size()-Returns the number of items in this list.*-Description of Method getIndex()-Returns the Item with the given index (0-based).*-Description of Method getName()-Returns the name of this catalog. *-Description of Method toString()-Returns list of items in the catalog (see output)You should implement a class called ItemOrder that stores information about a particular itemand the quantity ordered for that item. It should have the following public methods:*-Description of Method ItemOrder(item,quantity):-Constructor that creates an item order for the given item and given quantity.The quantity will be an integer.*-Description of Method 12 getPrice():-Returns the cost for this item order.*-Description of Method getItem() :-Returns a reference to the item in this order.You should implement a class called ShoppingCart that stores information about the overall order. It should have the following public methods.*-Description of Method ShoppingCart():-Constructor that creates an empty list of item orders.*-description of Method add(item order):-Adds an item order to the list, replacing any previous order for this item with thenew order. The parameter will be of type ItemOrder.*-Description of Method getTotal():-Returns the total cost of the shopping cart. Notice that when you add an ItemOrder to a ShoppingCart, you have to deal with replacing any old order for the item. A user at one time might request 3 of some item and later change the request to 5 of that item. The order for 5 replaces the order for 3. The user isn’t requesting 8 of the item in making such a change. The add method might be passed an item order with a quantity of 0. This should behave just like the others, replacing any current order for this item or being added to the order list. In the Item class you need to construct a String representation of the price. This isn’t easy to do for a number of reasons, but Java provides a convenient built-in object that will do it for you. It’s called a NumberFormat object and it appears in the java.text package (so you need to import java.text.*). You obtain a formatter by calling the static method called getCurrencyInstance(), asin: NumberFormat nf = NumberFormat.getCurrencyInstance(); You can then call the “format” method of this object passing it the price as a double and it willreturn a String with a dollar sign and the price in dollars and cents. For example, you might say:double price = 38.5;String text = nf.format(price);This would set the variable text to “$38.50”. classes should be stored in files called Item.java, Catalog.java, ItemOrder.java andShoppingCart.java. Below is a Driver for your code: public class Driver { public static void main(String[] args) { ShoppingCart shopCart = new ShoppingCart(); Item I1 = new Item("Pepsi", 3.99); Item I2 = new Item("Apple", 1.99, 10, 5.99); Item I3 = new Item("Orange", 1.25); Item I4 = new Item("Cake", 0.99, 7, 4.25); Item I5 = new Item("Galaxy", 1.0); Item I6 = new Item("Twix", 1.0, 4, 4.0); Item I7 = new Item("Trident", 2.0); Item I8 = new Item("Chips", 0.5, 3, 1.0); Catalog catalog = new Catalog("Ayre Market"); catalog.add(I1); catalog.add(I2); catalog.add(I3); catalog.add(I4); catalog.add(I5); catalog.add(I6); catalog.add(I7); catalog.add(I8); System.out.println(catalog.getName()+" offers "+catalog.size()+" items:"); System.out.println(catalog); ItemOrder IO1 = new ItemOrder(I1, 4); ItemOrder IO2 = new ItemOrder(I2, 25); ItemOrder IO3 = new ItemOrder(I3, 5); ItemOrder IO32 = new ItemOrder(I3, 2); ItemOrder IO4 = new ItemOrder(I4, 13); ItemOrder IO5 = new ItemOrder(I5, 10); ItemOrder IO6 = new ItemOrder(I6, 9); ItemOrder IO7 = new ItemOrder(I7, 2); ItemOrder IO72 = new ItemOrder(I7, 0); ItemOrder IO8 = new ItemOrder(I8, 6); shopCart.add(IO1); shopCart.add(IO2); shopCart.add(IO3); shopCart.add(IO4); shopCart.add(IO5); shopCart.add(IO6); shopCart.add(IO7); shopCart.add(IO8); System.out.println("Your cart total cost is: "+ shopCart.getTotal()); shopCart.add(IO32); shopCart.add(IO72); System.out.println("Your cart total cost is: "+ shopCart.getTotal()); }}Output:Ayre Market offers 8 items:Item 1: Pepsi, $3.99Item 2: Apple, $1.99 (10 for $5.99)Item 3: Orange, $1.25Item 4: Cake, $0.99 (7 for $4.25)Item 5: Galaxy, $1.00Item 6: Twix, $1.00 (4 for $4.00)Item 7: Trident, $2.00Item 8: Chips, $0.50 (3 for $1.00)Your cart total cost is: 79.33Your cart total cost is: 71.58 PLEASE NOTE: THIS IS NOT AN ASSIGNMENT.
0
aasif-avatar
almost 12 years ago

Illustrate the change that java script brought.

Hello to everyone on this website. Can any one elaborate the change that java script brought?
0

Is Java language going to be phased out in android app development in the future?

I feel like Android Studio is favoring Kotlin language now. A lot of new projects I see in companies are using Kotlin completely. ¿Estás buscando tonos de llamada únicos y divertidos para tu celular?
15
Solved

why we can't assign array in java ?

Each element of an array must have its value assigned individually. This error has the following causes and solutions: You inadvertently tried to assign a single value to an array variable without specifying the element to which the value should be assigned. You tried to assign a whole array to another array
1

Java and python are same

1. YesYes java and python are No java and python are not2. No
8
Solved

What is ADT in Java ?

Please help me explain it and give example.
3

Describe how you would develop object-oriented features of Java for the Quiz program developed in the Programming Assignments. In particular, describe how the program could use each of the following: class variables, instance variables, inheritance,

Describe how you would develop object-oriented features of Java for the Quiz program developed in the Programming Assignments. In particular, describe how the program could use each of the following: class variables, instance variables, inheritance, polymorphism, abstract classes, "this", "super", interfaces, and event listeners.
1

I need help solving this question, it is related to Java

##### Write a program that reads a file of numbers of type int and writes all the numbers to another file, but without any duplicate numbers.##### Assume that the numbers in the input file are already ordered from smallest to largest. After the program is run, the new file will contain all the numbers in the original file, but no number will appear more than once in the file. The numbers in the output file should also be sorted from smallest to largest. Your program should obtain both file names from the user
1
1-6 of 286

Is Java language going to be phased out in android app development in the future?

I feel like Android Studio is favoring Kotlin language now. A lot of new projects I see in companies are using Kotlin completely. ¿Estás buscando tonos de llamada únicos y divertidos para tu celular?
15
Solved
sum-dsh-avatar
over 6 years ago

java interview question

describ what is system.out.println?
1
astarloa-avatar
almost 12 years ago

Can you give some details of The while statement in loops?

Hi all, need help!!!!!! Provide the general form to use the The while statement of conditional loops?
8
astarloa-avatar
almost 12 years ago

Can you give some details of The do statement in loops?

Provide the general form to use The do statement of conditional loops?
6
astarloa-avatar
almost 12 years ago

Can you give some details of The for statement in loops?

Provide the general form to use the The for statement of conditional loops?
8
leonpan-avatar
almost 12 years ago

Define the Jumps in Loops of programming?

Can you determine Jumps in Loops of Java Programming?
6
1-6 of 286
Java Programming