Free Essay

Codes

In:

Submitted By iammenard20
Words 1127
Pages 5
//////////////I N V E N T O R Y C O N T R O L S Y S T E M////////////////

import java.io.*; import java.lang.*;

class store
{
private InputStreamReader ir=new InputStreamReader(System.in); private BufferedReader br; private FileOutputStream fos; private PrintStream ps; private FileReader frs; //function to check the existence for a file private boolean checkFile(String filename) { File myFile=new File(filename); boolean b=myFile.exists(); return b; } //function for auto-generating the product id private String generate_id() { String id=" "; String thisLine; String[] fullText = new String[200]; String[] lastLine=new String[5]; int counter=0,nid=0,l=0,z=0; boolean b=checkFile("Item.txt"); if(b==false) { id="00001"; } else { try { frs=new FileReader("Item.txt"); br=new BufferedReader(frs); while((thisLine=br.readLine()) != null) { counter=counter+1; fullText[counter] = thisLine; } frs.close(); lastLine=fullText[counter].split(","); nid=Integer.parseInt(lastLine[0]); nid=nid+1; l=(String.valueOf(nid)).length(); z=5-l; for(int i=1;i<=z;i++) { id=id+"0"; } id=id+String.valueOf(nid); id=id.substring(1); } catch(Exception ex) { System.out.println("Could not generate the Item ID...!"); } } return id; } //function to add new product private void addItem() { String desc; String id; double price=0; int stock=0,rol=0; try { id=generate_id(); System.out.print("\n Product ID :"+id+"\n"); br=new BufferedReader(ir); System.out.print("\n Product Description :"); desc=br.readLine(); System.out.print("\n Unit Price : Rs."); price=Double.parseDouble(br.readLine()); System.out.print("\n Starting stock value :"); stock=Integer.parseInt(br.readLine()); System.out.print("\n Re-order Level :"); rol=Integer.parseInt(br.readLine()); fos=new FileOutputStream("Item.txt",true); ps=new PrintStream(fos); ps.println(id+","+desc+","+price+","+stock+","+rol); fos.close(); System.out.println("Successfully added one product..."); } catch(Exception ex) { System.out.println("Error in accepting item specifications..."); } } //function to make selling transaction for a specific product private void makeTransaction() { String id,desc,s="y"; String msg,stock; String value[]=new String[5]; double price=0,amount=0; int qty=0; try { while(s.equals("y")) { br=new BufferedReader(ir); System.out.print("\n Enter Product ID :"); id=br.readLine(); msg=findProduct(id); if(msg.equals("Product not found...")) { System.out.print("\n"+msg); continue; } br=new BufferedReader(ir); value=msg.split(","); if(Integer.parseInt(value[3])==Integer.parseInt(value[4])) { System.out.println("Product in Re-Order Level."); System.out.println("Need to generate a purchase order..."); continue; } desc=value[1]; price=Double.parseDouble(value[2]); stock=value[3]; if(Integer.parseInt(stock)==0) { System.out.println("Current stock is NIL..."); System.out.println("Could not process any transaction on this product..."); continue; } System.out.print("\n Qty to sold :"); qty=Integer.parseInt(br.readLine()); if(qty>Integer.parseInt(stock)) { System.out.println("Out of stock...!"); System.out.println("Could not sell out this product..."); continue; } amount=qty*price; int d=updateStock(id,qty); if(d==1) { System.out.println("Failed to update the stock...!"); } frs=new FileReader("Item.txt"); br=new BufferedReader(frs); while((msg=br.readLine()) != null) { value=msg.split(","); if(value[0].equals(id)) { stock=value[3]; break; } } fos=new FileOutputStream("Transaction.txt",true); ps=new PrintStream(fos); ps.println(id+","+desc+","+qty+","+amount+","+stock); fos.close(); s="n"; } System.out.println("Transaction processed successfully..."); } catch(Exception ex) { System.out.println("Could not process the transaction...!"); } } //function for searching a product in the master file private String findProduct(String pID) throws IOException { int counter=0,i=0,flag=0; String s; String cline[]=new String[255]; String cID[]=new String[5]; String value=" "; frs=new FileReader("Item.txt"); br=new BufferedReader(frs); try { while((s=br.readLine()) != null) { counter=counter+1; cline[counter]=s; cID=cline[counter].split(","); if(cID[0].equals(pID)) { for(;i<cID.length;i++) { value=value+","+cID[i]; } flag=1; break; } } switch(flag) { case 0: value="Product not found..."; break; case 1: value=value.substring(2); break; } } catch(Exception ex) { System.out.println("Could continue operation on searching the product...!"); } return value; } //function for updating the value of current stock whenever a specific item is sold out private int updateStock(String pID,int qty) throws IOException { int counter=0,i=0,pos=0; String s; String cline[]=new String[255]; String cID[]=new String[5]; String row[]=new String[5]; String desc,price,rol; int stock=0,status=0; try { frs=new FileReader("Item.txt"); br=new BufferedReader(frs); while((s=br.readLine()) != null) { counter=counter+1; cline[counter]=s; cID=s.split(","); if(cID[0].equals(pID)) { pos=counter; row=s.split(","); } } fos=new FileOutputStream("Item.txt",false); ps=new PrintStream(fos); for(i=0;i<cline.length;i++) { if(i==pos) { desc=row[1]; price=row[2]; stock=Integer.parseInt(row[3])-qty; rol=row[4]; ps.println(pID+","+desc+","+price+","+stock+","+rol); } else { if(cline[i]!=null) { ps.println(cline[i]); } } } fos.close(); status=0; } catch(Exception ex) { status=1; } return status; } //function to generate and print the daily transaction report private void displayReport() { String id,desc,qty,value,stock,s; String cline[]=new String[5]; try { frs=new FileReader("Transaction.txt"); br=new BufferedReader(frs); System.out.println("\nID Description Qty Sold Amount C.Stock"); System.out.println("----------------------------------------------"); while((s=br.readLine()) != null) { cline=s.split(","); id=cline[0]; desc=cline[1]; qty=cline[2]; value=cline[3]; stock=cline[4]; System.out.println(id+" "+desc+" "+qty+" "+"Rs."+value+" "+stock); } } catch(Exception ex) { System.out.println("Some exceptions occured..."); System.out.println("Could not generate the daily transaction report...!"); } } public static void main(String args[]) throws IOException { store inv=new store(); int ch=0; String s; InputStreamReader ir=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(ir); System.out.println("S T O C K M A N A G E M E N T S Y S T E M"); System.out.println("-----------------------------------------------"); System.out.println("1. ADD NEW PRODUCT"); System.out.println("2. SELL PRODUCT"); System.out.println("3. VIEW DAILY TRANSACTION REPORT"); System.out.println("---------------------------------"); System.out.println("4. Exit"); begin: while(ch!=4) { System.out.print("\n"); System.out.print("\n Enter a choice and Press ENTER to continue[1-4]:"); ch=Integer.parseInt(br.readLine()); if(ch>4||ch<1) { System.out.println("This doesn't appear to be a valid option...!"); continue begin; } if(ch==1) { s="y"; while(s.equals("y")||s.equals("Y")) { inv.addItem(); System.out.print("\n Add another[y/n]:"); s=br.readLine(); } continue begin; } else if(ch==2) { s="y"; while(s.equals("y")||s.equals("Y")) { inv.makeTransaction(); System.out.print("\n Sell another[y/n]:"); s=br.readLine(); } } else if(ch==3) { inv.displayReport(); } } System.out.println("Thanks for using this program...!"); }
}

Similar Documents

Premium Essay

Code

...Pseudocode syntax, descriptions and examples Overview: This table provides a reference for commonly used pseudocode for introductory computer program design courses. You should use this as your reference and copy and paste code examples into your projects to ensure you are using proper syntax. Be sure to indent your code to make it more readable and use modify and enhance from the examples as needed. Also, capitalize the first letter of your pseudocode (e.g. While, not while). Pseudocode Write/Prompt Description Displays messages and other information on the screen Flowchart equivalent Write “What is your name?” Input Pauses execution, allowing the user to enter data Input FirstName Input FirstName Compute/Set Assigns a value to a variable Set Avg=(num1+num2)/2 Declare Example usage Write “What is your name?” Write “Your name is “ +YourName + “.” Prompt for ItemName, Price, Quantity Declares a variable to be of a specific type Input Number1, Number2 Compute average value: Set Avg= (num1 + num2)/2 Compute total cost: Set TotalCost= 1.25*Songs Declare FirstName As String Declare FirstName as String Declare Num1, Num2 As Integer Possible datatypes may include: String 1 Call Requests a module, subprogram, or function be executed Call WriteNums(num1, num2)) If End If Tests if a condition is met. If the test condition is true, the statements are executed. Enter Is Number < 5? Character Integer Float Main Module Write “Enter 2 numbers” Input Num1,Num2 Call WriteNums(num1...

Words: 712 - Pages: 3

Free Essay

Assigning Evaluation and Managment Codes

...Assigning evaluation and management codes By Tina Cunningham Initial consultation is performed of a 78 year old female with unexpected weight loss, abdominal pain, and rectal bleeding. A comprehensive history and examination is performed. I would code this 99205 The comprehensive history of the patient with detailed history. A 30 year old patient presents complaining of flu-like symptoms characterized by unremitting cough, sinus pain, and thick nasal discharge. An examination reveals bronchitis and sinus infection. The patient is prescribed a 5- day course of Zithromax. I would code this 99202 the examination was detailed, complaint addressed, and medical decision established. Established patient in lithium presents for routine blood work to monitor therapeutic levels of kidney function. A nurse reviews the results and advices the patient that tests are normal, and no change in dosage is indicated. I would code this 99211 the patient is an established patient and patient has the two components that is required. A 62- year old diabetic female presents for checkup and dressing change of wound on left foot. An examination reveals the wound is healing. The nurse applied new dressing and 0patient will return for a checkup in one week. I would code this as 99212 the patient has had history of the wound, the examination is on the wound and a medical decision was established. A mother brings in her 6 month old male child for a routine...

Words: 270 - Pages: 2

Free Essay

Google Code

...Using Google Code and SVN to Manager project Source Code Sep. 3 Project Source Code Manager on Google Code Using NetBean IDE and SVN 1 MrToanDH * C0907i * FptAptech Using Google Code and SVN to Manager project Source Code Sep. 3 Contents I. Google Code là gì? ............................................................................................................. 3 II. 4 bước để tạo Project trên Google Code:.......................................................................... 4 III. Thiết lập các chức năng cho project : ............................................................................. 7 1.Trang chủ project (Project Home) : ................................................................................ 7 2.Thêm và quản lý các thành viên của 1 project : ............................................................. 8 3.Chức năng download : .................................................................................................... 9 4.Xóa project : ................................................................................................................. 11 IV. Giới Thiệu Về Subversion: .............................................................................................. 12 V. 2 cách cơ bản để quản lý Source code với SVN : ............................................................ 13 1.Thao tác với file và Folder : .............................................................................................

Words: 2085 - Pages: 9

Premium Essay

Code of Ethics

...Code of Ethics Herika Solis BUS/210 08/24/2012 Brendan McFarlan (Jones, 2007, p. 144) “Just as people have to work out the right and wrong ways to act so do companies.” This builds control and Structure, Avi’s Flower Shop is a family business with 8 employees that makes flower arrangements for walk- in customers. The code of conduct has been put in place to promote principles and ethics that will make them attractive to my customers and employees. I expect all of our employees to know and follow the code. The code of ethics and rules that are put in place at Avi’s Flower Shop is as follow; Treat people fairly, treating everyone fairly will ensure a great relationship with co-workers and customers. Act professional at all times, when an employee acts professional it will help make wise decisions and handle issues in a better way. Have a team work mentality; this will help the business work in a harmonious environment which will help the business grow. Always be known for our work ethics, positive attitude, and extraordinary services, having this reputation will ensure we will keep our loyal customers for years and this will also help get new customers. Build trust through integrity, honesty, and customer service, running my business with honesty, integrity, and great customer service will help my business grow in a steady way which will ensure that I will have a business to run for a long time without worrying that my customers will go to another flower shop. Preserve...

Words: 429 - Pages: 2

Premium Essay

Dree Code

...Dress Codes In Junior High And High Schools? Name: Institution: Should There Be Dress Codes In Junior High And High Schools? Introduction The dress code for junior and high schools has been a hot debate over the years. It has sought to address various issues and have resulted in different levels of controversy. For instance, in the early 1970s boys with long hair sometimes got attracted to their classmates. Resultantly, schools required young men to cut their hair short. Moreover, at the beginning of the 1990s several organizations and parents pushed for a dress code as a strategy to curb gang-related violence (Valdez, 2015). Over the years, the desire to create a professional school environment and reduce struggle over designer clothes made uniforms and dress codes become a familiar topic. However, identical strategies are more restrictive than dress code policies. Dress codes are strict as in the case of schools in California and Napa. For instance, schools in this areas required students to put on solid colors and logos or banned images on clothes. The primary objective of this argumentative essay is to provide adequate evidence that there should be dress codes in both junior and high schools. Claim 1: dress code may increase student safety and reduce crime. Each year several schools adopt a certain form of dress code. Although some challenges are emerging on the constitutionality, court’s rulings have supported dress codes that...

Words: 1717 - Pages: 7

Free Essay

Qr Codes

...list I compiled of positives and negatives concerning QR codes. Pros Easy to make. All you really need is a free QR code generator, and there are plenty of them floating around the Internet. Cost effective. Since most of the QR code generators are free, making the actual codes is inexpensive. The cost of printing materials can also remain relatively low, since they can be used on business cards or stickers. Stores can print their QR codes in ads, which they already invest money into. Anyone can make a QR code. Saves paper. People can scan a QR code to do things like enter contact information or store a coupon on a cellphone. Instead of having to carry paper coupons, people can just scan a QR coupon and have it available in their phone. Very quick transfer of information. Since the advent of DSL internet and now the 4G network for cellphones, people have gotten very used to getting information very quickly. Relatively small in size. This makes the codes great to put on business cards, in a corner of an ad, somewhere on a coupon, or anywhere there is a small bit of space. These codes can be made much smaller than the information they contain. So instead of placing a long, ugly, URL, on an advertisement or resume, simply place a small QR code. Cons Potential for over usage. Marketers should be aware that placing a QR code absolutely everywhere can be overkill. Reputation issues. Many people are making their QR code that link to social media, such as Facebook. This might...

Words: 500 - Pages: 2

Free Essay

Dress Code

...black shirt with black pants or a white collared shirt with black shorts?” Dress codes at school are something that all kids hate, but at the same time, it’s something that is going to help them through life. Dress codes are really effective in high school because it reduces cliques, bullying, and gang violence. Students start focusing on their looks instead of their school work, but now with dress codes they help students concentrate on learning and not on their appearance. Dress codes help reduce the smuggling of weapons because most codes restrict baggy clothes. The students will also be ready for future jobs that will require them to wear a uniform because they have been wearing uniforms their whole academic life. Have you ever gone to a school and seen tank tops and baggy clothes there and then went to another school with students wearing uniforms? What was your first impression of the schools? Uniforms on student’s helps the school look organized and makes the students look very mature. The impression you might get of the students is that they get straight A’s in their classes. Students that wear tank tops and other such clothes do not look very mature and might not be the best group of kids to hang out with. There is no one wearing baggy pants or even skinny jeans because of the dress code policies in the school and that helps students to follow future dress codes for future jobs. Dress codes are guidelines to life; they help students look professional and at the same time...

Words: 691 - Pages: 3

Premium Essay

Code of Conduct

...Code of Conduct Cheesecake Factory Code of Conduct Professor Mandiveyi December 15, 2013 Introduction to Business Bus 100 Abstract This paper discusses key areas of interest within the Cheesecake Factory’s code of conduct, which will also identify the significant importance of the code of conduct and why it is important to the success of the Cheesecake Factory. This paper will also explain how the code of conduct can be implemented by the company, checks and balances to measure adherence to the code, and lastly, three ways the restaurant can engage in socially responsive activities in the community in which it operates. The Cheesecake Factory has a rather large code of conduct. There are a few specific ideas within the code of conduct that is of significant importance to the Cheesecake Factory’s business. It is imperative that this code of conduct is established because staff members must understand the Cheesecake Factory’s ethics and belief system in comparison to other organizations because it may differ with regards to cultural content, values, and ordering of beliefs (McShane & Von, 2005). The first significant idea in the code of conduct is conflict of interest. The company specifically states that an employee must avoid situations in which a conflict of interest would exist or have the appearance of a conflict of interest. This is extremely important to the business because it will prevent employees from having the appearance of giving preferential...

Words: 323 - Pages: 2

Free Essay

Qr Code

...VISIBLE LIGHT NETWORKING WITH QR CODES A PROJECT REPORT FOR CSE 561 RYDER ZIOLA AND WILLIAM WEBB 1. Motivation and Design Considerations Telecommunications networks and the internet have enabled many different forms of communication - email, phone, instant messaging, etc. For most users, the fact that all of these are mediated by external networks is not important. However, some users, for instance, human rights activists operating in certain countries, may wish transfer digital data in a fashion that is anonymous, leaving no identifying traces on either participating machine nor any electronic record of the communication in the network. Physical storage media, such as CDs and portable hard drives are possible candidates if mail or an inperson handoff is allowed, but such media can also carry physical evidence, such as hair or fingerprints, and also serial numbers or metadata attached to the stored files. Any of these things could potentially compromise collaborators. Another possibility is to instead execute file transfers between portable machines in a way that uses no physical media and does not rely on any telecom network or exchange of addresses. Smart phones are natural candidates, being portable and increasingly ubiquitous, so for this project, we attempted to leverage common built-in functionality to create a secure channel with the desired properties. We note that many smart phones can communicate via IR ports, but there is always the possibility the that IR transmissions...

Words: 1972 - Pages: 8

Free Essay

Code of Ethics

...CODE OF ETHICS Compliance is the responsibility of all the Company’s directors, officers, managers, and employees.(Capital One,2011). One is responsible for learning the details of the policies, procedures, laws and regulations applicable to one's job and for seeking guidance when needed. It is important to avoid misconduct that violates the law, this Code, or Company policies, but also the appearance of impropriety. The point, which a subject is not explicitly explained in this Code, does not relieve an employee of their responsibility to maintain the highest ethical standards under all circumstances. If one has any concern about whether their actions or inactions could violate a law, it should be discussed with their manager. While no Code of Ethics can or should replace thoughtful behavior or common sense, it can help cultivate a culture that values and rewards honesty, integrity, and accountability. (Avon, n.d.). The principles detailed in the Code will guide in “doing the right thing” and in preserving the Company’s reputation for acting with integrity at all times. TRADE REGULATION Most states have enacted trade regulation laws to ensure fair competition. These laws prohibit price-fixing and other "anti-competitive agreements, deceptive acts, and unfair competitive methods." (Pension Consulting, n.d.). Some forms of joint activities are legally permissible, but others are not. Under no circumstances, should you illegally or improperly...

Words: 2229 - Pages: 9

Premium Essay

Code Meshing Vs Code Switching

...Code Meshing vs. Code Switching: Which One Should be Taught in Schools? In the article “Twitterish,” John McWhorter explains the need for different forms of literacy and multimodality – Standard English and new digital literacies. He also, in a way, talks about code switching and code meshing because he shows how people can switch between different literacies and how they can also incorporate both Standard English and digital literacies into speech and writing together. John White’s paper goes into much greater detail about what code switching is and how to teach it in schools. He says that code switching – the act of changing from a culturally imbued discourse to Standard English, but not necessarily vice versa – is a priority to teach to...

Words: 914 - Pages: 4

Free Essay

Code of Ethics

...Iranian Journal of Public Health Tehran University of Medical Sciences The Code of Ethics for Nurses F Zahedi, M Sanjari, [...], and M Vahid Dastgerdi Additional article information Abstract Nurses are ever-increasingly confronted with complex concerns in their practice. Codes of ethics are fundamental guidance for nursing as many other professions. Although there are authentic international codes of ethics for nurses, the national code would be the additional assistance provided for clinical nurses in their complex roles in care of patients, education, research and management of some parts of health care system in the country. A national code can provide nurses with culturally-adapted guidance and help them to make ethical decisions more closely to the Iranian-Islamic background. Given the general acknowledgement of the need, the National Code of Ethics for Nurses was compiled as a joint project (2009–2011). The Code was approved by the Health Policy Council of the Ministry of Health and Medical Education and communicated to all universities, healthcare centers, hospitals and research centers early in 2011. The focus of this article is on the course of action through which the Code was compiled, amended and approved. The main concepts of the code will be also presented here. No doubt, development of the codes should be considered as an ongoing process. This is an overall responsibility to keep the codes current, updated with the new progresses of science and emerging challenges...

Words: 3684 - Pages: 15

Premium Essay

Hammurabi's Code

...different kingdoms under the protection and governance of the one great umbrella of Babylon. As a ruler of a large society, Hammurabi recognized the need for organized law and knew that in order to govern effectively he had to establish his authority as a fair and impartial ruler. It is generally accepted that Hammurabi’s Code was developed around 1780 BC, during his 44 year rule as king. The Amorites believed that kings were appointed by the gods to administer the law and protect the kingdom. Hammurabi’s Code was a set of 282 laws which established rules for bringing accusations against another and the corresponding punishments to fit the crimes committed, through an “eye for an eye” mentality. The development of Hammurabi’s Code gave structure and order to the kingdom by addressing each of the three social classes; the poor (mushkenu: a free person who was essentially lower or middle class), the rich (awilu: a free person of the upper class), and the slaves (wardu). The code also shows consideration for the protection of women and children and for the weak and the poor (that they might not be destroyed by the strong or the rich and powerful). The code also addressed unpaid debt, allowable reasons for a man or a woman to divorce and provisions to be made for spousal and child support. It also established severe consequences for bringing false accusations, or for verdicts and punishments rendered in error. “If a judge tries a case, reaches a decision, and presents his...

Words: 652 - Pages: 3

Premium Essay

Code of Ethics

...Code of Ethics Teresa Sieck ETH/ 316 July 2, 2012 Ed McCullough Code of Ethics A code of ethics is a collection of principles practiced and followed by management of businesses and corporations around the world (Spiro, 2010). A businesses code of ethics works with a company’s mission statement and policies of conduct that gives employees, partners, venders, and outsiders an understanding of what the company stands for and believes in (Boylan, 2009). It should address the differences or variations in both company’s industry and its broader goals for social responsibility (How to create a company code of ethics, 2012). It should be strong enough to serve as a guide for employees with questions to resolve issues on their own if needed (Trevino & Nelson, 2007). Wal-Mart is one of the largest corporations in the United States. As one of the largest corporations the company has a social responsibility to their employees, customers, and the community. The code of ethics works with and around these principals. Wal-Mart has three basic principles, 1) respect for the individual, 2) service to the customer, and 3) striving for excellence (What is Wal-Mart’s Code of ethics, 2011). The following is an example of what a code of ethics could be and what values a business may have. Vision Statement: People are assets not possessions; employees, customers, and communities should be treated with fairness, respect, honesty and integrity. The corporation’s global vision is to...

Words: 1066 - Pages: 5

Free Essay

Gray Code

...What is Gray code? From Wikipedia The reflected binary code, also known as Gray code after Frank Gray, is a binary numeral system where two successive values differ in only one bit. The reflected binary code was originally designed to prevent spurious output from electromechanical switches. Today, Gray codes are widely used to facilitate error correction in digital communications such as digital terrestrial television and some cable TV systems. One good way to explain the use of Gray code is to take a look at how a hard drive work, in extreme simplicity. A hard drive contains a disc where information is stored. The information on the disc is stored in ones and zero´s, binaries. The disc is divided into sections which each has a binary signature. Here is a picture to explain: As we can see here, section 0 for example has the binary signature 0000 and section 15 has the binary signature 1111. When a hard drive is running it reads section by section and if the hard drive for some reason has a failure and the reader jumps from section 15 to section 0 the reading changes from 0000 to 1111 which means that every bit read is faulty. This could change alot depending on how the information is parsed. A hard drive could be exposed to a lot of external forces and the reader can jump and missread at any time. This cannot be forseen, but it can be prevented to some extent. Enter Gray code. Gray code is a way to sort the binaries so that one binary never...

Words: 1010 - Pages: 5