Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


Meera
Class SALE
2 Answer(s)      4 years and 9 months ago
Posted in : Java Beginners



Advertisement
View Answers

December 16, 2009 at 3:39 PM


Hi Friend,

We have create a loop for only 3 items, you can modify it to 10.
import java.io.*;
import java.util.*;

public class SALE {
public static void main(String[] args) throws Exception {
ArrayList l1=new ArrayList();
ArrayList l2=new ArrayList();
ArrayList l3=new ArrayList();
ArrayList l4=new ArrayList();
ArrayList l5=new ArrayList();
ArrayList l6=new ArrayList();
ArrayList l7=new ArrayList();
double sum=0.0,sum1=0.0,sum2=0.0,sum3=0.0,sum4=0.0,sum5=0.0,sum6=0.0,sum7=0.0,p11=0.0,p12=0.0,p13=0.0,p21=0.0,p22=0.0,p23=0.0,p31=0.0,p32=0.0,p33=0.0,p41=0.0,p42=0.0,p43=0.0,p51=0.0,p52=0.0,p53=0.0,p61=0.0,p62=0.0,p63=0.0,p71=0.0,p72=0.0,p73=0.0,pp1=0.0,pp2=0.0,pp3=0.0;
Scanner scan = new Scanner(System.in);
int menu = 0;
System.out.println("Main Menu");
System.out.println();
System.out.println("1. Monday");
System.out.println("2. Tuesday");
System.out.println("3. Wednesday");
System.out.println("4. ThursDay");
System.out.println("5. Friday");
System.out.println("6. Saturday");
System.out.println("7. Sunday");
System.out.println("8. Exit");
double itemname[]=new double[3];
boolean quit = false;
do{
System.out.print("Please enter your choice: ");
menu = scan.nextInt();
System.out.println();

switch(menu) {
case 1:

for(int i=1;i<=3;i++){
System.out.print("Item Name:");
String name1=scan.next();
System.out.print("Quantity");
int q1=scan.nextInt();
System.out.print("Price");
double p1=scan.nextDouble();
double t1=p1*q1;
l1.add(t1);
sum1+=t1;
}
p11=Double.parseDouble((l1.get(0)).toString());
p12=Double.parseDouble((l1.get(1)).toString());
p13=Double.parseDouble((l1.get(2)).toString());
System.out.println(p11);
break;
case 2:

for(int i=1;i<=3;i++){
System.out.print("Item Name:");
String name2=scan.next();
System.out.print("Quantity");
int q2=scan.nextInt();
System.out.print("Price");
double p2=scan.nextDouble();
double t2=p2*q2;
l2.add(t2);
sum2+=t2;
}
p21=Double.parseDouble((l2.get(0)).toString());
p22=Double.parseDouble((l2.get(1)).toString());
p23=Double.parseDouble((l2.get(2)).toString());
System.out.println(p21);
break;
case 3:

for(int i=1;i<=3;i++){
System.out.print("Item Name:");
String name3=scan.next();
System.out.print("Quantity");
int q3=scan.nextInt();
System.out.print("Price");
double p3=scan.nextDouble();
double t3=p3*q3;
l3.add(t3);
sum3+=t3;
}
p31=Double.parseDouble((l3.get(0)).toString());
p32=Double.parseDouble((l3.get(1)).toString());
p33=Double.parseDouble((l3.get(2)).toString());
System.out.println(p31);
break;
case 4:

for(int i=1;i<=3;i++){
System.out.print("Item Name:");
String name4=scan.next();
System.out.print("Quantity");
int q4=scan.nextInt();
System.out.print("Price");
double p4=scan.nextDouble();
double t4=p4*q4;
l4.add(t4);
sum4+=t4;
}
p41=Double.parseDouble((l4.get(0)).toString());
p42=Double.parseDouble((l4.get(1)).toString());
p43=Double.parseDouble((l4.get(2)).toString());
System.out.println(p41);
break;


December 16, 2009 at 3:40 PM


continue..

case 5:

for(int i=1;i<=3;i++){
System.out.print("Item Name:");
String name5=scan.next();
System.out.print("Quantity");
int q5=scan.nextInt();
System.out.print("Price");
double p5=scan.nextDouble();
double t5=p5*q5;
l5.add(t5);
sum5+=t5;
}
p51=Double.parseDouble((l5.get(0)).toString());
p52=Double.parseDouble((l5.get(1)).toString());
p53=Double.parseDouble((l5.get(2)).toString());
System.out.println(p51);
break;
case 6:

for(int i=1;i<=3;i++){
System.out.print("Item Name:");
String name6=scan.next();
System.out.print("Quantity");
int q6=scan.nextInt();
System.out.print("Price");
double p6=scan.nextDouble();
double t6=p6*q6;
l6.add(t6);
sum6+=t6;
}
p61=Double.parseDouble((l6.get(0)).toString());
p62=Double.parseDouble((l6.get(1)).toString());
p63=Double.parseDouble((l6.get(2)).toString());
System.out.println(p61);
break;
case 7:

for(int i=1;i<=3;i++){
System.out.print("Item Name:");
String name7=scan.next();
System.out.print("Quantity");
int q7=scan.nextInt();
System.out.print("Price");
double p7=scan.nextDouble();
double t7=p7*q7;
l7.add(t7);
sum7+=t7;
}
p71=Double.parseDouble((l7.get(0)).toString());
p72=Double.parseDouble((l7.get(1)).toString());
p73=Double.parseDouble((l7.get(2)).toString());
System.out.println(p71);
break;
case 8:
quit = true;
pp1=p11+p21+p31+p41+p51+p61+p71;
pp2=p12+p22+p32+p42+p52+p62+p72;
pp3=p13+p23+p33+p43+p53+p63+p73;
System.out.println("Total sale of Item1 is: "+pp1);
System.out.println("Total sale of Item2 is: "+pp2);
System.out.println("Total sale of Item3 is: "+pp3);
sum=sum1+sum2+sum3+sum4+sum5+sum6+sum7;
System.out.println("Total Weekly Sale= "+sum);
System.out.println("Average Weekly Sale per day= "+sum/7);
break;
default:
System.out.println("Invalid Entry!");
}
}
while (!quit);
}
}

Hope that the above code will be helpful for you.
Thanks


Related Tutorials/Questions & Answers:
Class SALE - Java Beginners
Class SALE  A company sale 10 items at different rates and details.... import java.io.*; import java.util.*; public class SALE { public static void... to Sunday. Write calss SALE to enter sale amount for each item, compute
Point of Sale - Java Beginners
Point of Sale   I am to create a java application that displays a GUI for a point of sale pogram. I have to GUI created, but I am not sure how to get... java.text.NumberFormat; import java.awt.event.*; public class PosGUI extends
Advertisements
implement sale purchaes
implement sale purchaes  i want to implement a code in advance java with connectivity .. i have a table in database in which i have some stack of sms if customer puchases and enter value in text box the amount will be deduct
code for implementing sale purchase
code for implementing sale purchase  i have two tables in database. in one table i have stock of sms and further details and other table is for customer .if customer purchases my sms then the value will be deduct from my table
Total summay from a sale table
Total summay from a sale table  Total summay from a sale table
Calculate Company's Sale using Java
*; import java.util.*; public class SALE { public static void main(String[] args... to calculate Company's sale. A company sales 3 items at different rates and details...: a) The total weekly sale of the company b) The total sale of each item at the end
Open Source Point of sale
Open Source Point of sale point of sale Point of sale, or POS..., or any combination of these devices.    Open source point of sale Another term for a POS (point of sale) application is "cash register
Java Class Question?
Java Class Question?  Create a class names Purchase Each purchase contains an invoice number, amount of sale and amount of sales tax. Include set methods for the invoice number and sale amount. Within the set() method
class
class  Is a class a subclass of itself
class
is a class to represent a country in medal tally. It has an attribute of country... medals. In this class, you should also define constructors, and assessor, mutator methods. Task 2 MedalTally.java is a class to model a medal tally, containing
Class
Class, Object and Methods       Class : Whatever we can see in this world all the things... is termed as a class. All the objects are direct interacted with its class
Super class of an Exception class
Super class of an Exception class  hello,,, What is super class of an Exception class?   hii,, the super class of an exception is throwable class. and the super class of an throwable class is the object class
Class
Class       This section explores the concept of a class in reference to object oriented programming techniques. A class defines the properties of  objects and methods used
Explain final class, abstract class and super class.
Explain final class, abstract class and super class.  Explain final class, abstract class and super class.   Explain final class, abstract class and super class. A final class cannot be extended. A final class
.class and .tld
.class and .tld  how to create .class and .tld file
class loaders
class loaders   Explain static and dynamic class loaders
class file
class file  How to create class file in jsf easily
inner class
inner class  what is mean by inner class   Inner class is a non-static class which is defined inside another class
Node class
Node class   hii, What is a node class?   hello, A node class is a class that has added new services or functionality beyond the services inherited from its base class
Matrix Class
Matrix Class   A class to manage matrices and add them. Create in the driver class two objects of it and use the add method
Matrix Class
Matrix Class   A class to manage matrices and add them. Create in the driver class two objects of it and use the add method
lock on a class
lock on a class  hello, Can a lock be acquired on a class?   hiii,, Yes, a lock can be acquired on a class. This lock is acquired on the class's Class object
Java class
Java class  What is the purpose of the Runtime class
immutable class
immutable class  How to make a class immutable
Locale class
Locale class  What is the Locale class
singleton class
singleton class  What is singleton class
Abstract class
Abstract class  Can an abstract class be final
Abstract class
Abstract class  what is an Abstract class
printstrim class
printstrim class  discribe PrintStream class
printstrim class
printstrim class  discribe PrintStream class
wrapper class
wrapper class  list wrapper class methods
wrapper class
wrapper class  wrapper class methods
objective c extending a class with a class
objective c extending a class with a class  I need an example for extending a class with a class in objective c. thanks
objective c extending a class with a class
objective c extending a class with a class  I need an example for extending a class with a class in objective c. thanks
robot class
robot class  please send me uses of robot class and some examples using robot class
Nested class
Nested class  What is nested class?  when a class is defined within another class then such a class is called a nested class. Nested... readable and maintainable code. class OuterClass { ... static class
abstract class
abstract class  Can there be an abstract class with no abstract methods
java.sql.DriverManager class
java.sql.DriverManager class  Why isn't the java.sql.DriverManager class being found
Adapter Class
Adapter Class  Hello Everybody, Can anybody help me to describe what is Adapter class and when to use this class and give a suitable example... visit the following links: What is Adapter Class Example of Adapter Class
class file
class file  how to convert java classfile into java sourcefile
create a class
create a class  plz provide any example related to class
super class
super class  which is the super base class in java
wrapper class
wrapper class  why wrapper class does not have a default constructor
Wrapper Class
Wrapper Class  what is wrapper class in java and why we use it   Hi Friend, Wrapper class is a wrapper around a primitive data type. It represents primitive data types in their corresponding class instances e.g.
GregorianCalendar class
GregorianCalendar class   hello,, What is the GregorianCalendar class?   hii, The GregorianCalendar provides support for traditional Western calendars
Dictionary class
Dictionary class  hello,, What is the Dictionary class?   hii,, The Dictionary class provides the capability to store key-value pairs
abstract class
abstract class  abstract class AbstractClass{ } is possible and compile the class or any compile time error occur tell me the answer Blockquote
Sealed class
Sealed class  Hi........ What are sealed class? Please give an example Thanks  Ans: Sealed class: Sealed classes conserve memory..., and the compiler can provide better error feedback. The class which is not dynamic
Sealed class
between sealed class and dynamic classes? Please give me an example of each class Thanks  Ans: Dynamic class: Specifies that instances of a class may possess dynamic properties added at run time. Sealed class: Sealed
abstract class
abstract class   Explain the concept of abstract class and it?s use with a sample program.   Java Abstract Class An abstract class is a class that is declared by using the abstract keyword. It may or may not have
 

 

 

DMCA.com