Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Item{
- private String name;
- private int num;
- private double price;
- void put(){
- System.out.print("Enter name, Quantity of stock, and price respectively: ");
- name = Console.readToken();
- num = Console.readInt();
- price = Console.readDouble();
- }
- double value(){
- return (double)(num*price);
- }
- public static void main(String [] args){
- Item a = new Item();
- a.put();
- Item b = new Item();
- b.put();
- System.out.println(a.value());
- if(a.value()>b.value()){
- System.out.println("the first item has the larger stock value which is " + a.value());
- }
- else{
- System.out.println("the second item has the larger stock value which is " + b.value());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment