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 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 Tutorials/Questions & Answers:
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 programming - Java Beginnersobject 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
Advertisements
Object-Oriented programming - Java BeginnersObject-
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
object oriented programming protocolobject oriented programming protocol What is
object oriented programming protocol? Is it different from objective c protocol
programming??
Thanks
Object Oriented Programming in PHPObject Oriented Programming in PHP Hi,
Which version of PHP supports OOPS. How can I learn
Object Oriented Programming in PHP?
Thanks
(adsbygoogle = window.adsbygoogle || []).push
Object Oriented Programming in JavaOOPS acronym for
Object Oriented Programming is a model or concept that works...
using the wrapper class.
In
Java class is a group of similar
object. Objects... is an instance of a
class.
For a language to be an
Object Oriented Programming Object Oriented Programming IIObject 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
object oriented programming data scienceobject oriented programming data science Hi,
I am beginner in Data...:
object oriented programming data science
Try to provide me good examples or tutorials links so that I can learn the
topic "
object oriented programming Is Java object oriented?Is
Java object oriented? Hi,
Is
Java object oriented?
Thanks
Hi,
Java is
object oriented programming language. It is supports OPPS concepts:
Object
Class
Inheritance
Polymorphism
Abstraction
Encapsulation
All
Java Programming using Netbeans - IDE QuestionsJava 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
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 java is pure object orientedjava 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
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 OrientedObject Oriented C++ is Purely
object oriented or not .Then why
java called purely
object oriented Object oriented program - Java BeginnersObject 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 program.. - Java Beginnersobject 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
fully object oriented language - Java Beginnersfully
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
Java Object
Java Object
Object is the basic entity of
object oriented
programming language.
Object.../
java/master-
java/
java-
object-
oriented-language.shtml
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 Object Oriented conceptsOOP 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
Learning Java Programming for BeginnersJava is an
Object Oriented Programming Language that was developed by Sun.... There are several ways by
which a young developer can learn
Java programming, one of them is online
Java
training.
Learning
Java programming for beginners
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
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
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 Programming using arrayJava Programming using array I'm creating a
programming using array that will accept 10 letters and test if those letters are consonant...','H','J','K','L','M','N','P','
Q','R','S','T','V','W','X','Y','Z'};
char ch
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 Looking for sample project in java using netbeansLooking for sample project in
java using netbeans Hi all,
i am novice in developing desktop application in
java using netbeans. can anyone pls help me by sending project built in
netbeans as soon as possible. so that i could
java programming using RMI - RMIjava programming using RMI Write a program
using RMI to sell an item to the customer remotely and don't allow the customer to purchase the item if the stock is nil , by displaying an appropriate message
Introduction to JavaJava is an open source
object oriented programming language..., Mike Sheridan under James Goslings decided to develop a
programming
language that is better than C and C++. They thought that the
programming
language must
Learn Java Programming you proficient in the language.
Java is an
Object Oriented Programming(OOP... in it, Learn
Java programming online with tutorials and simple examples... and mobile phones. Career in
Java programming is vast and that is why most
Java programming using ArrayList Help?Java programming using ArrayList Help? Hi,can anybody help and guide me on doing this
java program?
(Largest rows and columns)Write a program that randomly fills in 0s and 1s into an n-by-n matrix,prints the matrix,and finds
Java programming using ArrayList Help?Java programming using ArrayList Help? Hi,can anybody help and guide me on doing this
java program?
(Largest rows and columns)Write a program that randomly fills in 0s and 1s into an n-by-n matrix,prints the matrix,and finds
Inheritance in java with exampleInheritance in
java with example
Inheritance is one of the concept of the
Object-
Oriented programming. The advantage of
using the
inheritance
Login Form with Java GUI using NetbeansLogin Form with
Java GUI
using Netbeans Hi there!
I'm a beginner in
Java. I've created 2 class files:
1) TestAssign.java
2) NewFrame.java
How can I have different user to login? Now that I've only administrator who is able
Master Java In A Week
as a
programming language
Java is an
Object oriented application
programming language...
programming
language.
Java as an
Object Oriented Language... Independent and
Object Oriented makes the
java powerful to build the flexible
Import object in Excel using java swingImport
object in Excel
using java swing Hi sir,
I want to make a swing application where I can import a
object by clicking a button. I am
using... in 'Insert' ribbon.
first select a cell (cell no will be inside
java code) then go
Java as a general purpose language
Java as a general purpose language
Java is an
Object oriented application
programming
language... of applications can be written in
Java programming
language such as any small
OOPs and Its Concepts in Java.
Java is a
object oriented programming and to understand... certain things common. In
object oriented programming classes can
inherit some...;
Brief Introduction to OOP
Object Oriented How to use Java?Java, an
Object Oriented Programming language was developed by Sun... and computing devices.
Java has been based on C and C++
programming language... Nokia, Siemens, Vodafone are
using Java technology