Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
LAB 1 – Intro to Java | Washington Sarmiento's ePortfolio OpenLab Logo Home About People Courses Projects Clubs Portfolios Help Toggle navigation My OpenLab Home About People Courses Projects Clubs Portfolios Help Sign Up Log In Washington Sarmiento's ePortfolio A City Tech OpenLab ePortfolio Menu Skip to content Portfolio Profile Home About Me CET 3640 LAB 0 – Open Lab and Eclipse LAB 1 – Intro to Java LAB 2 – Classes and Methods LAB 3 – Inheritance LAB 4 – Polymorphism LAB 5 – Data Structures LAB 5PT2 – Data Structure Second Version LAB 6 – My First App Academics Courses Sample Course Internships Career Resume Achievements LAB 1 – Intro to Java Lab Report 1 – Description For LAB1 we need to create a program that will prompt the user to enter numbers to compute several statistics. We need to display a menu that will ask the user to (1) enter a number or (2) exit. The user should be able to enter as many numbers as wished (positives or negatives). When the user finishes the following statistics should be displayed: First number entered, Last number entered, Count of number entered, Lowest two numbers, Highest two numbers, Total Sum, and Average. I created a class which contains setMethods, getMethods, constructors,  and functions.  Later, I created another class containing public static void main where i create an object where I pass the name to constructor.  Once this is done i am able to call on my functions and just display the results of my functions.   Code:   /*First class*/ package LAB_1; import java.util.Scanner; /*Created a class for constructors, setmethods, getmethods, and such so I can call upon them in my main program*/ public class INPUTS { String welcome; int numbers = 0; int frstnum = 0; int lstnum = 0; int lownum = 0; int highnum = 0; int scdhighnum = 0; int scdlownum = 0; int count = 0; int sum = 0; public INPUTS(String Program) { welcome = Program; } public void setWELCOME(String Program) { welcome = Program; } public String getWELCOME() { return welcome; } public void MSGDISPLAY() { System.out.printf("Welcome to Washington Sarmiento's First Program\n%s!\n\n", getWELCOME()); } public void INPUTNUMS() { Scanner switchy = new Scanner( System.in ); Scanner INPUT = new Scanner( System.in ); Scanner brk = new Scanner( System.in ); System.out.print("Enter '1' to run the program or '2' to exit: \n"); int choice =switchy.nextInt(); while(choice != 2) { System.out.println("Enter 0 to continue "); System.out.println("To terminate program enter n/N after these statements:"); //(n/ or N) char will terminate program after last number is entered String brk1 = brk.next(); char brk2 = brk1.charAt(0); System.out.println("Enter a set of numbers:\n"); numbers = INPUT.nextInt(); lstnum = numbers; sum += numbers; count++; if (numbers > highnum) { scdhighnum = highnum; highnum = numbers; } else if (numbers > scdhighnum) { scdhighnum = numbers; } if (numbers < lownum) { scdlownum = lownum; lownum = numbers; } else if (numbers < scdlownum) { scdlownum = numbers; } if ( count == 1 ) { frstnum = numbers; highnum = numbers; lownum = numbers; } if ( brk2 == 'n' || brk2 == 'N' ) //if(numbers == 0) { break; } } } public void DISPLAYRSLTS () { System.out.println("FIRST NUMBER: " +frstnum); System.out.println("LAST NUMBER: " +lstnum); System.out.println("COUNT: "+count); System.out.println("LOWEST NUMBER: " +lownum); System.out.println("SECOND LOWEST NUMBER: " +scdlownum); System.out.println("HIGHEST NUMBER: " +highnum); System.out.println("SECOND HIGHEST NUMBER: " +scdhighnum); System.out.println("TOTAL SUM: " +sum); System.out.println("AVERAGE: " +sum/count); } } /*Second class*/ package LAB_1; /*this class contains main which will run the program I and will call the setmethods, getmethods and others from inputs class*/ public class INPUTSTEST { public static void main(String[] args) { INPUTS userINPUTS = new INPUTS("CET3640f2013 LAB 1: Introduction to Java Programming"); userINPUTS.MSGDISPLAY(); userINPUTS.INPUTNUMS(); userINPUTS.DISPLAYRSLTS(); } } } Screenshots: Leave a Reply Cancel reply Your email address will not be published. Required fields are marked * Comment Name * Email * Website Save my name, email, and website in this browser for the next time I comment. Δ Write a brief paragraph to introduce yourself to your visitors and explain what they will find on this site. Be sure to add more developed content to your About Me page. (Edit this paragraph in Dashboard > Widgets > Text) Search for: Learning Blog Archives Learning Blog Archives Select Month August 2013 Recent Posts Welcome! Categories Categories Select Category Coursework Field Trips Tags City Tech OpenLab Proudly powered by WordPress The OpenLab at City Tech:A place to learn, work, and share The OpenLab is an open-source, digital platform designed to support teaching and learning at City Tech (New York City College of Technology), and to promote student and faculty engagement in the intellectual and social life of the college community. New York City College of Technology | City University of New York Support Help | Contact Us | Privacy Policy | Terms of Use | Credits Accessibility Our goal is to make the OpenLab accessible for all users. Learn more about accessibility on the OpenLab Copyright Creative Commons - Attribution - NonCommercial - ShareAlike © New York City College of Technology | City University of New York top The OpenLab at City Tech:A place to learn, work, and share The OpenLab is an open-source, digital platform designed to support teaching and learning at City Tech (New York City College of Technology), and to promote student and faculty engagement in the intellectual and social life of the college community. New York City College of Technology | City University of New York Support Help | Contact Us | Privacy Policy | Terms of Use | Credits Accessibility Our goal is to make the OpenLab accessible for all users. Learn more about accessibility on the OpenLab Copyright Creative Commons - Attribution - NonCommercial - ShareAlike © New York City College of Technology | City University of New York Washington Sarmiento's ePortfolio Open Search Search the OpenLab Submit