A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Engineering
»
IDEs, Version Control and other tools
Author
Netbeans and Ctrl + z (end of file)
Nick Petas
Ranch Hand
Joined: Jan 31, 2007
Posts: 38
posted
Aug 24, 2010 07:37:40
0
How can I use Ctrl + z (end of file) inside netbeans?
I am reading a deitel's book about
java
.
Thank you.
Nick Petas
Ranch Hand
Joined: Jan 31, 2007
Posts: 38
posted
Aug 24, 2010 08:23:44
0
Here is the code : (I managed to run it properly in a console window but only after removing the package commands)
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ //package javaapplication54; /** * GradeBook class uses switch statement to count letter grades */ import java.util.Scanner; public class GradeBook { private String courseName; //name of course this GradeBook represents //int instance variable are initialized to 0 by default private int total; //sum of grades private int gradeCounter; //number of grades entered private int aCount; //count of A grades private int bCount; private int cCount; private int dCount; private int fCount; //constructor public GradeBook(String name) { courseName = name; } //get and set methods public void setCourseName(String name) { courseName = name; } public String getCourseName() { return courseName; } //--other methods //display welcome message public void displayMessage() { System.out.printf("Welcome to the grade book for\n%s!\n\n", getCourseName()); } //input arbitrary number of grades from user public void inputGrades() { Scanner input = new Scanner(System.in); int grade; //grade entered by the user System.out.printf("%s\n%s\n %s\n %s\n", "Enter the integer grades in the range 0-100.", "Type the end-of-file indicator to terminate input:", "On UNIX/Linux/Mac OS X type <Ctrl> d then press Enter", "On Windows type <Ctrl> z then press Enter"); //loop until user enters the end-of-file indicator while (input.hasNext()) { grade = input.nextInt(); //read grade total += grade; //add grade to total ++gradeCounter; //increment number of grades //call method to increment appropriate counter incrementLetterGradeCounter(grade); } }//end methdo inputGrades //add 1 to appropriate counter for specified grade private void incrementLetterGradeCounter(int grade) { //determine which grade was entered switch (grade / 10) { case 9: case 10: ++aCount; break; case 8: ++bCount; break; case 7: ++cCount; break; case 6: ++dCount; break; default: //grade was less than 60 ++fCount; break; }//end switch }//end method incrementLetterGradeCounter //display a report based on the grades entered by user public void displayGradeReport() { System.out.println("\nGrade Report:"); //if user entered at least one grade... if (gradeCounter != 0) { //calculate average of all grades entered double average = (double)total / gradeCounter; //output summary of results System.out.printf("Total of the %d grades entered is %d\n", gradeCounter, total); System.out.printf("Class average is %.2f\n", average); System.out.printf("%s\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n", "Number of students who received each grade:", "A: ", aCount, "B: ", bCount, "C: ", cCount, "D: ", dCount, "F: ", fCount); } } }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ //package javaapplication54; /** * Create GradeBook object, input grades and display grade report */ public class GradeBookTest { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here GradeBook myGradeBook = new GradeBook("CS101 Introduction to Java Programming"); myGradeBook.displayMessage(); myGradeBook.inputGrades(); myGradeBook.displayGradeReport(); } }
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12617
I like...
posted
Aug 24, 2010 17:06:13
0
Run it from the command line--I don't know if you can enter in all the control characters inside the NetBeans wrapper around the console. If you can't, stick to the command line--you learn more that way anyway.
I agree. Here's the link:
http://zeroturnaround.com/jrebel
- it saves me about five hours per week
subject: Netbeans and Ctrl + z (end of file)
Similar Threads
Laundry disaster narrowly averted
An invalid XML character Unicode: 0x19
What does EOF mean?
Detecting EOF?
how to make the java application developed in windows environment work on FreeBSD?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter