Home Answers Viewqa Java-Beginners Java using Netbeans Object Oriented Programming

 
 


Sean Braxton
Java using Netbeans Object Oriented Programming
1 Answer(s)      2 years and a month ago
Posted in : Java Beginners

I am trying to make a program that uses a main class and a separate class with one public method and one private method. The main method in the main class asks the user for 2 strings and a set of numbers for an array. This array is then sorted in descending numerical order. It then initiates the public method in the second class to print a report to the console. The private method of the second class determines the ,average and mean values of the array and returns that as another array. My code is pasted below. "_" is an underscore

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.io.*; import java.util.*; import java.text.*;

package Lab09SB;

/** * * @author ConfibulatoryMadness */ public class Main {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
int MainM = 1;
while(MainM==1){
    Scanner scanner = new Scanner(System.in);
    System.out.print("Please enter the student's first name - "); //Prompts user to enter name
    String studentFirst_Name = scanner.nextLine();
    System.out.print("Please enter the student's last name  - ");
    String studentLast_Name = scanner.nextLine();
    System.out.printf("\nHow many grades will you be entering for %s %s- ", studentFirst_Name, studentLast_Name); //asks user how many grades
    short numOfGrades = scanner.nextShort();

    short[] grades  = new short[numOfGrades];
    System.out.println("\nPlease enter the grades one at a time, pressing enter after each value.\n");

     for(int i = 0; i< numOfGrades; i++)
     {
         grades[i] = scanner.nextShort();             //Allows user to input grades
     java.util.Arrays.sort(grades); //sorts the array
     }
  Student student1= new Student(studentFirst_Name,studentLast_Name, grades);
  student1.ConsoleOut();
System.out.println("Do you wish to continue ( Yes / No ) -");
String Continue = scanner.nextLine();
Continue.toLowerCase();
if(Continue == "no"){
   MainM++;        
}else if (Continue == "yes"){
    MainM=1;
}
}
}
    }

class Student {

float [] grades;
String studentFirst_Name;
String studentLast_Name;
private float [] GradeStatistics(){
    float sum = 0f;
 for(int i = 0; i<grades.length; i++)
 {
        sum += grades[i]; //gets sum of Array
 }
 float average = sum/grades.length; //finds the average



 float[] studentReport = {average, grades[0], grades[grades.length - 1]}; //get lowest value in sorted array  //gets max value in sorted array
 return studentReport;

}
public void ConsoleOut(){
    System.out.printf("\nThe following is a grade report for %s %s :\nGrades\n"+grades+"\n"+GradeStatistics(),studentFirst_Name,studentLast_Name);
}

}

View Answers

November 3, 2011 at 3:33 PM


In your program everything working fine, but replace the Confirmation code as follows, then it works fine.

 String Continue = "";
 System.out.print("Do you want to Continue (Yes/No) : \n");
 while(Continue.equals("")){
             Continue = scanner.nextLine();
             Continue = Continue.toLowerCase();
             if(Continue.equals("no")){
                 MainM++;
             }else if(Continue.equals("yes")){
                 MainM = 1;
             }
             }









Related Pages:
Java using Netbeans Object Oriented Programming
Java using Netbeans Object Oriented Programming   I am trying to make a program that uses a main class and a separate class with one public method and one private method. The main method in the main class asks the user for 2
Object-Oriented Design - Overview
Java: Object-Oriented Design - Overview Background. Software development... best practice is use of object-oriented approaches, using Object-Oriented Design (OOD) and implementing the design with Object-Oriented Programming (OOP
object oriented programming - Java Beginners
object oriented programming  sir, i read in the book tat object oriented program exhibits recurring structures. i want to know "what is meant by recurring structures?"  Hi Friend, Any structure to be occurred over
Object-Oriented programming - Java Beginners
Object-Oriented programming  Write a program to display the names and salaries of 5 employees.Make use of a class and an array.The salary of each employee should increase by 5% and displayed back.  Hi friend, Code
An Overview of Java      Java is a programming language      Java is Object Oriented Programming
; Java as a programming language Java is an Object oriented application programming language developed by Sun Microsystems. Java is a very...; Java as an Object Oriented Language In this section, we will discuss the OOPs
object oriented programming protocol
object oriented programming protocol  What is object oriented programming protocol? Is it different from objective c protocol programming?? Thanks
Object Oriented Programming in PHP
Object Oriented Programming in PHP  Hi, Which version of PHP supports OOPS. How can I learn Object Oriented Programming in PHP? Thanks
Is Java a pure object oriented language?
Is Java a pure object oriented language?   Hi, Is Java a pure object oriented language? thanks   Hi No, Java is an object oriented programming language but not purely a object oriented language. In OOPs programming
Object-Oriented Implementation of Numerical Methods - Java Tutorials
Object-Oriented Implementation of Numerical Methods 2002-04-01 The Java Specialists' Newsletter [Issue 044] - Review: Object-Oriented Implementation... - Vince Sabio) on my distribution list. Review: Object-Oriented
Object Oriented
Object Oriented  C++ is Purely object oriented or not .Then why java called purely object oriented
Object Oriented Programming II
Object Oriented Programming II  Instructions: ->each class to be created must have encapsulated fields, setters and getters methods, and constructors Create a class named "Paper" with the following attributes
Java Programming using Netbeans - IDE Questions
Java Programming using Netbeans  Hello Dear sir, i got one scenario... & address using netbeans jframe then i have to store these data into my package so... visit the following link: http://www.roseindia.net/java/example/java/swing/add
What are the features and advantages of OBJECT ORIENTED PROGRAMMING?
What are the features and advantages of OBJECT ORIENTED PROGRAMMING?  What are the features and advantages of OBJECT ORIENTED PROGRAMMING
Java Object
Java Object         Object is the basic entity of object oriented programming language. Object.../java-object-oriented-language.shtml  
java is pure object oriented
java is pure object oriented  java is pure object oriented or not.? reason.?   Java is not pure object oriented language because... are not object 2)It does not support operator overloading multiple inheritance. 3
Object-Oriented Programming
Java: Object-Oriented Programming Beyond OOP Here's an interesting article about going beyond OOP: The Next Move in Programming: A Conversation with Sun's Victoria Livschitz at java.sun.com/developer/technicalArticles/Interviews
Java as an Object Oriented Language
Java as an Object Oriented Language   ... applications and programs. OOP stands for Object Oriented Programming.... There are four main pillars of an Object Oriented Programming Language
java : object oriented
java : object oriented   (a) Write a class named CarRental... the user for the data needed for a rental and creates an object of the correct... an object of the correct type. Display the total rental fee
Object oriented program - Java Beginners
Object oriented program  Write a class called RaceCar.java that contains instance variables horsepower, weight, zeroTo60, and milesPerGal. The value of zeroTo60 (in second) is determined by the formula zeroTo60 = weight
Object Oriented concepts
OOP stands for Object Oriented Programming. This is a technique used to develop programs revolving around the real world entities. In OOPs programming... on the following links Object Oriented concepts
object oriented program.. - Java Beginners
object oriented program..  Write a class called RaceCar.java that contains instance variables horsepower, weight, zeroTo60, and milesPerGal. The value of zeroTo60 (in second) is determined by the formula zeroTo60 = weight
Object
are the basic units of the object-oriented programming. Objects are the part of our day... in terms of object-oriented programming. Objects are key to understanding object-oriented programming. Just look around and you'll find a lot of examples of real
JavaScript Object Oriented Feature
; JavaScript supports the main principles of object-oriented programming...; </body> </html> Object-Oriented Programming The Object Oriented programming is a computer programming paradigm. Object Oriented
fully object oriented language - Java Beginners
fully object oriented language  Is java is a fully object oriented language?if no,why?  Hi Friend, Java is not a fully object oriented... int,float which are not object 2)It does not support operator overloading
Object-Oriented Language: Java / APIs, Java OOPs
. Java is one of the useful Object Oriented programming language. Other Object..., Lasso, Perl 5,PHP5, VBScript, VBA etc. Java is popular object oriented programming...Java OOPs In this section we will learn Object Oriented (OOPs) Concepts 
Introduction
the java applications and programs. OOP means Object Oriented Programming... Java as an Object Oriented Language   .... But in case of java,  it is a fully Object Oriented language because
Inheritance in java with example
Inheritance in java with example          Inheritance is one of the concept of the Object- Oriented programming. The advantage of using the inheritance
OOP Tutorial [first draft]
-Oriented Design (OOD) and Object-Oriented Programming (OOP) An important part... in the design process. In contrast to this, Object-Oriented Programming is concerned... = Object Oriented Programming Grouping related data with methods lets you not only
About Java Programming Language
About Java Programming Language       Java is an Object oriented application programming language developed by Sun Microsystems. Java is a very powerful general-purpose programming
Learn Java - Learn Java Quickly
;    Java is an object oriented programming language... useful than other object oriented languages. It is now most demanded... the page using any web browser.  Also programs developed by using Java
OOPs and Its Concepts in Java
;  Brief Introduction to OOP Object Oriented Programming... certain things common. In object oriented programming classes can inherit some common..., preparing a solution, coding and finally its maintenance. Java is a object
Create JSF Application Using NetBeans IDE
environment (IDE) written in the Java programming language. The NetBeans project... Create JSF Application Using NetBeans IDE  ... using NetBeans 6.1. Follow the following steps to create the JSF application
NetBeans JSF Tutorial
Application Using NetBeans IDE The NetBeans IDE is a flexible arrangement... application using NetBeans IDE.    Creating... using NetBeans This example illustrates you how to create a login form
Java swing in NetBeans - Swing AWT
Java swing in NetBeans   thanks a lot sir for everything you answered.... i will specify a swing code for JTable using NETBEANS so would you tell me... = res.getMetaData(); columns = md.getColumnCount(); Object r[][]=new
OOP
; Object Oriented Programming which was totally based on the real life entities... for Object oriented  Programming. Previously we used to follow... the object creation process, programmatically. Read more at : www.roseindia.net/java
Object oriented design - Java. - Design concepts & design patterns
Object oriented design - Java.  Hi, Everyone.Pls help me to develope my project of Object oriented design, as I have to submit it on thursday,3rd Dec. 2009.Nowadayz I am suffering from fever and not able to concentrate
What is attribute oriented programming?
What is attribute oriented programming?  Hi, What is attribute oriented programming? Thanks
Netbeans program
. TicTacToeGame is another program that uses a TicTacToe object to actually play a two human player game of Tic-Tac-Toe. Using the NetBeans design tool also create...Netbeans program  I need to write a program that does the following
Object in java - Java Beginners
/java/master-java/java-object-oriented-language.shtml http...Object in java  Hi deepak, I am new to java, can u tell me what... as a class object. Object: Object is the basic entity of object oriented
java object - Java Beginners
of objects. The primitive data type and keyword void is work as a class object. Object: Object is the basic entity of object oriented programming language...java object  i want a complete memory description of objects,methods
core java code in object oriented manner - Java Interview Questions
core java code in object oriented manner   hi this is komali .i want small code for this question .its very urgent .please send me as soon as possible . i am waiting for code Sports Associations in India
java object - Java Beginners
are stayed  Hi friend, Instance Variables (Non-static fields): In object oriented programming, objects store their individual states in the "non-static...java object  i want to where in the memory the java objects,local
java programming
java programming  Hi friends i need simple login form coding using two labels,two textfields and two buttons in netbeans without using database connection. . if you know that logic please tell
Exp.4 Write any C++ programs to demonstrate multiple inheritance concept of an object oriented programming.
Exp.4 Write any C++ programs to demonstrate multiple inheritance concept of an object oriented programming.  (Aim:- The main aim of this experiment is reusability of code and getting idea about classifying objects , identifying
Netbeans GUI Ribbon
Netbeans GUI Ribbon  how to create ribbon task in java GUI using netbeans
Programming with Java - Java Beginners
Programming with Java    Using valid Java code from Chapter 1 to 6, create an object oriented(Java application ) program with a minimum of two... with dynamic allocation, in your java test program class to initialize all
java programming
java programming  Hi friends, i need a simple login form source code. in that program i have two labels,two text fields and two buttons namely ok and cancel buttons. how to write for that one using netbeans without database
Java Training and Tutorials, Core Java Training
Java is a powerful object-oriented programming language with simple code... interfaces because Java has built-in application programming interface (API) and due... Java Training and Tutorials, Core Java Training  
Master Java In A Week
as a programming language Java is an Object oriented application programming... programming language.   Java as an Object Oriented... Platform Independent and Object Oriented makes the java powerful to build
Java Programming: Contents
Introduction to Programming Using Java, Fourth Edition Table of Contents...: Fundamental Building Blocks of Programs Section 5: Objects and Object-oriented...: Constructors and Object Initialization Section 3: Programming with Objects Section 4

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.