Declare the attributes/methods as protected rather than public so that only the methods of its subclass may have access to them.
Declare the attributes/methods as protected rather than public so that only the methods of its subclass may have access to them.
As JavaAddict points out, it is the checking issue that makes Katana24's method does not work perfectly. Therefore, some code has to be modified as:
for( int i = 0; i < myArray.length; i++ )
{
try {
int currentValue = Integer.parseInt( sT.nextToken().trim() );
myArray[i] = currentValue;
}catch(NumberFormatException e){
System.out.println("Non-digit character is involved. Input is not valid");
return null;
}
}
In this way the method return null, implying the input string is not valid.
The above code for suggestion (2) is not properly made.
There is a modified bobble sort for your reference.
public static void sortStringBubble( String x [ ] ) {
int i, j, n = x.length;
boolean flag=false; //determine if sort is finished.
String temp;
/* Notes
* after each outer loop one has to check if the flag is true. flag is true, implying that every elements are already in the order.
* If so, the outer "for loop" terminates immediately because every elements are already in order.*/
for (i=0; (i <n-1) && !flag; i++) {
flag = true; // before starting the next scanning make flag true, assuming that every elements are in the order
for ( j = 0; j < n-1-i; j++ )// n-1-i implying the looping upper range becomes smaller and smaller because no need to check the "stable region"
if( x [ j ].compareToIgnoreCase( x [ j+1 ] ) > 0 ){ // ascending sort
temp = x [ j ];
x [ j ] = x [ j+1]; // swapping
x [ j+1] = temp;
flag = false; // Since there is a swapping the flag becomes false. This means further scanning/looping is needed.
}
// if no swapping happened, implying that every elements are in order and further scanning (looping) is not needed.
}
}
One error: In line 7 you define name as String instead of String array.
Suggestion:
(1) Should we just use the argument of the main method so that the body of the main method will be:
sortStringBubble (args);
for ( String s: args )
System.out.print( s + " " );
System.out.println();
(2) To enhance the efficiency of the bobble sort one may add an outer loop ( for (int i =0; i<x.length-1 ;i++){...} ) so that one may not check the stable region.
while ( flag )
{
flag = false;
for (int i =0; i < x.length -1; i++)
for ( j = i; j < x.length - 1; j++ )
{
if( x [ j ].compareToIgnoreCase( x [ j+1 ] ) > 0 )
{ // ascending sort
temp = x [ j ];
x [ j ] = x [ j+1]; // swapping
x [ j+1] = temp;
flag = true;
}
}
}
(1) In void actionPerformed(ActionEvent e)method body there are missing code blocks for two cases:
if (e.getSource() == displayBtn){...} and
if (e.getSource() == resetBtn){...}
(2) in void actionPerformed(ActionEvent e)method body
one curly bracket '}' is missing in line 178
That's why, I guess, the buttons do not work properly.
Please have a look at the thread:
array sort of 10 integers in ascending and descending order
Bubble sort
http://www.daniweb.com/forums/thread299093.html
I do not understand your question. Anyway, I am nocited that
to capture the output in DOS window one may use pipe:
java ABC > data.dat
so that the output by intepreting ABC will be captured/stored in the file data.dat
You may also save the Sentinel flag (boolean stop)by using "break" to terminate the while loop (" while(true){...}).
The guard for inputed name is made of
if(empName.equalsIgnoreCase("stop")){ // guard for input name
System.out.println("See you later.");
break; // jump out of the loop
}
We have no need to use "if(){ ...}; else{...}" any more. Only "if(){}" is enough.
However, you have to say "Good Bye!" before jumping out of the loop (the "break"). Why?
import java.util.Scanner;
public class Payroll2
{
//main method to execute program
public static void main (String args[] )
{
//main execution
Scanner input = new Scanner( System.in );
//variables
String empName;
float wage;
float hours;
float pay;
double overTimePay;
while( true ){
System.out.printf( "Enter employee name or 'stop' to exit:");
empName = input.next();
if(empName.equalsIgnoreCase("stop")){ // guard for the input name
System.out.println("See you later.");
break; // jump out of the loop
} // no need else{..}
System.out.printf( "What is the hourly rate?");
wage = input.nextFloat();
while (wage <=0)
{
System.out.print("Please enter an amount above 0 dollars");
wage = input.nextFloat();
}
System.out.print( "How many hours?");
hours = input.nextFloat();
while (hours <=0)
{
System.out.print("Please enter an amount above 0 hours:");
hours = input.nextFloat();
}
if (hours>40)// Overtime
{
pay = hours * wage;//multiplication
overTimePay = (hours-40) * (wage*1.5);
//using printf and println
System.out.println("Employee:" + empName);
System.out.printf("Hourly Rate: $%.2f\n", wage);
System.out.println("Regular Hours worked:" + "40");
System.out.println("Overtime Hours worked:" + (hours-40));
System.out.printf("Total Pay: $%.2f\n", pay);
System.out.printf("Overtime Pay: $%.2f\n", overTimePay);
System.out.printf("Gross Pay: $%.2f\n", pay+overTimePay);
}
else // Under …
No, you have to make a small chage to meet the request.
Please just make while loop (i.e. while( !stop) {....}) to cover the code from 18 to 66
After the while loop, we should have only the 3 lines of code left:
System.out.println( "Bye for now.");
}//end main
}//end class
As long as the client types in "stop", the boolean flag becomes true,resulted in violating the while loop condition ( ! top ), so that the loop terminates.
Finally, you have to say "Good Bye" to your customer.
Attached please find the code modified for your reference
import java.util.Scanner;
public class Payroll2
{
//main method to execute program
public static void main (String args[] )
{
//main execution
Scanner input = new Scanner( System.in );
//variables
String empName;
float wage;
float hours;
float pay;
double overTimePay;
boolean stop=false;
while( !stop ){
System.out.printf( "Enter employee name or 'stop' to exit:");
empName = input.next();
if(empName.equalsIgnoreCase("stop"))
stop = true;
else{
System.out.printf( "What is the hourly rate?");
wage = input.nextFloat();
// the curly bracket '}' has been removed
while (wage <=0)
{
System.out.print("Please enter an amount above 0 dollars");
wage = input.nextFloat();
}
System.out.print( "How many hours?");
hours = input.nextFloat();
while (hours <=0)
{
System.out.print("Please enter an amount above 0 hours:");
hours = input.nextFloat();
}
if (hours>40)// Overtime
{
pay = hours * wage;//multiplication
overTimePay = (hours-40) * (wage*1.5);
//using printf and println
System.out.println("Employee:" + empName);
System.out.printf("Hourly Rate: $%.2f\n", wage);
System.out.println("Regular Hours worked:" + "40");
System.out.println("Overtime Hours worked:" + (hours-40));
System.out.printf("Total Pay: $%.2f\n", pay);
System.out.printf("Overtime Pay: $%.2f\n", overTimePay);
System.out.printf("Gross Pay: $%.2f\n", pay+overTimePay);
}
else // Under 40 Hours
{
pay = hours * wage;//multiplication
//using printf and println
System.out.println("Employee:" + empName);
System.out.printf("Hourly Rate: $%.2f\n", wage);
System.out.println("Regular Hours worked:" + hours);
System.out.printf("Gross Pay: $%.2f\n", pay);
}
}
}
System.out.println( "Bye for now.");
}//end main
}//end class
Yes, provided i,j are withing the ranges of the 2D array.
Over one month ago there was a thread discussing the similar project which might help you:
How to extract columns of coordinate values from text file (in java) ?
http://www.daniweb.com/forums/thread294844-1.html
The reason is: the loop body still needs i.
the (i=cis.read(cipherTextBytes)) is consider as the returning value. If the value returned is not -1 the loop continues.
capsitan, you made a mistake. You should remove the curly bracket in line 38 (i.e. the line 26 in the following modified code) so that the wage would be assigned a value:
wage = input.nextFloat(); // line 25 in the following modified code.
Following is the code I have modified:
import java.util.Scanner;
public class Payroll2
{
//main method to execute program
public static void main (String args[] )
{
//main execution
Scanner input = new Scanner( System.in );
//variables
String empName;
float wage;
float hours;
float pay;
double overTimePay;
boolean stop=false;
System.out.printf( "Enter employee name or 'stop' to exit:");
empName = input.nextLine();
if(empName.equalsIgnoreCase("stop"))
stop=true;
else{
System.out.printf( "What is the hourly rate?");
wage = input.nextFloat();
// the curly bracket '}' has been removed
while (wage <=0)
{
System.out.print("Please enter an amount above 0 dollars");
wage = input.nextFloat();
}
System.out.print( "How many hours?");
hours = input.nextFloat();
while (hours <=0)
{
System.out.print("Please enter an amount above 0 hours:");
hours = input.nextFloat();
}
if (hours>40)// Overtime
{
pay = hours * wage;//multiplication
overTimePay = (hours-40) * (wage*1.5);
//using printf and println
System.out.println("Employee:" + empName);
System.out.printf("Hourly Rate: $%.2f\n", wage);
System.out.println("Regular Hours worked:" + "40");
System.out.println("Overtime Hours worked:" + (hours-40));
System.out.printf("Total Pay: $%.2f\n", pay);
System.out.printf("Overtime Pay: $%.2f\n", overTimePay);
System.out.printf("Gross Pay: $%.2f\n", pay+overTimePay);
}
else // Under 40 Hours
{
pay = hours * wage;//multiplication
//using printf and println
System.out.println("Employee:" + empName);
System.out.printf("Hourly Rate: $%.2f\n", wage);
System.out.println("Regular Hours worked:" + hours);
System.out.printf("Gross Pay: $%.2f\n", pay);
}
System.out.printf( "Enter employee name or 'stop' to exit:"); …
In Unix/Linux/DOS windows the commands for compiling and runing java program are the same provided the environmental variable is set up properly.
javac Hello.java
java Hello
If you develop an applet application, you may use
appletviewer Hello.html
to open the html file Hello.html to run the applet.
boolean variable "stop" is a sentinel flag. If "stop" is true the "while loop" must terminate immediately. So you should check the empName to see if it is "stop" or not. Therefore, the lines of code starting for checking the name would be:
if( empName.equalsIgnoreCase("stop"))
stop=true; // stop becomes true and the excution jumps out of the "while loop" immediately
else { // if the stop is true this code block will not be executed
System.out.printf( "What is the hourly rate?");
wage = input.nextFloat(); // in this way the wage is initialized
.......
Can you manage to modify your program accordingly?
static methods/variables are associated with class-wide situation which has one copy only while non-static, i.e. member methods/variables belong to each instance. Each instance/object has its own copy of its methods/variable.
You may use super's class name to replace the handle "super":
one.show();
to meet your purpose.
In other word, one may use the class name instead of instance variable as the handle to call a static method.
A nested while loop may do the job.
Here is the code:
import java.util.*;
import java.util.StringTokenizer;
public class AutoTextSumm {
public static void main(String[] args) {
String s1,s2;
String sDelim = ".?!";
StringTokenizer str1=new StringTokenizer("i like you very much.i do not hate you!i do.",sDelim);
while(str1.hasMoreTokens()) { // get 3 sentense
s1=str1.nextToken();
s1=s1.trim();
StringTokenizer str2=new StringTokenizer(s1, " ");
while(str2.hasMoreTokens()){ // check each word
s2=str2.nextToken();
s2=s2.trim();
if (s2.compareTo("do")!=0) // check word "do"
System.out.print(s2+ " "); // print/store the valid words
}
System.out.println();
}
}
}
Thank you jon for reminding me about keanoppy's intention.
keanoppy, thank you for your try. You may probably put a semicolon after the if (...)line of code so it does not work. I have tested positively.
The code is printed as follows.
keanoppy, if you want to remove the "do" from the three sentenses, one has to write a method to remove the sub string "do" from any string, as I understand, since only single character should be a delimiter.
import java.util.*;
import java.util.StringTokenizer;
public class AutoTextSumm {
public static void main(String[] args) {
String s1;
String sDelim = ".?! ";
StringTokenizer str1=new StringTokenizer("i like you very much.i do not hate you!i do.",sDelim);
while(str1.hasMoreTokens()) {
s1=str1.nextToken();
s1=s1.trim();
if (s1.compareTo("do")!=0)
System.out.print(s1+ " ");
}
}
}
According to NormR1's suggestion,
(1) Add one space character as an extra delimiter into the sDelim string in line 8:
String sDelim = ".? !";
(2)Insert the following line of code after line 14
if (s1.compareTo("do")!=0)
so that the "do" will not be printed on DOS
import java.util.*;
import java.util.StringTokenizer;
public class AutoTextSumm {
public static void main(String[] args) {
String s1;
String sDelim = ".?! ";
StringTokenizer str1=new StringTokenizer("i like you very much.i do not hate you!i do.",sDelim);
while(str1.hasMoreTokens()) {
s1=str1.nextToken();
s1=s1.trim();
if (s1.compareTo("do")!=0)
System.out.print(s1+ " ");
}
}
}
The for loop body shows that after assignments are made to every elements of the array diveScore the guard starts to check the "input variable element". (It's too late). Actually no assignment has been made to the variable element. If only the values varying from 0 to 10 are acceptable in terms of valid scores, the guard you have set up ("if ...") can not do the checking job. You should use "while loop" as the guard, and place the guard before any assignment is made to the array of diveScore. I have modified your code as follows so that only the scores between 0 and 10 pass the guard and then assigned to the array of diveScore.
import java.io.*;
import java.util.*;
public class KeyBoard {
public static void main(String args[]) {
Scanner keyboard=new Scanner(System.in);
double[] diveScores = new double[7];
int scoreCount = 1;
for (double element : diveScores)
{
System.out.println("Enter score " + scoreCount);
element = keyboard.nextDouble();
while (element < 0 || element > 10)
{
System.out.println("Score out of range 0 - 10. Please enter a valid score.");
element = keyboard.nextDouble();
}
diveScores[scoreCount-1] = element;
scoreCount++;
}
for (double d : diveScores)
System.out.print(d + " ");
System.out.println();
}
}
The following code is an example demonstrating what I am thinking about. I have tested positively. You may write code differently to read the file one by one. I hope you may understand me.
import java.io.*;// read several input files as indicated via the arguments of main method
class XML{
public static void main(String args[]){
int length;
byte buf[]=new byte[1024];
for (int i=0; i< args.length ;i++ ) // each loop read one file.
try{
FileInputStream in;
in =new FileInputStream(args[i]); // establish the input channel for read each file
while((length=in.read(buf,0,1024))!=-1) // read one line of character
System.out.println(new String(buf)); // print out the line of character on DOS
}catch(IOException e){
System.out.println("Error: "+e);
System.exit(-1);
}
}
}
Under the same folder, for example, you may have several files to be read: 1.txt, 2.txt, 3.txt.
You may compile the program, and then run the program with the following command lines on DOS
javac XML.java
java XML 1.txt 2.txt 3.txt
The program thus prints the contents of all the files on DOS window accordingly.
You may write a program to open and read several files whose names are passed via the String args[] array as the arguments of the main methods. The first argument tells the program how many files to be proceesed, and the following arguments represent the names of every files. For example:
java XML 4 input1.txt input2.txt input3.txt input4.txt
provided the files are located under the same folder
The data type of choice is int. So you should define each case by a constant of type int. Therefore the case bady should be:
case 1:
howKilometers(meters);
break;
case 2 :
showInches(meters);
break;
case 3 :
showFeet(meters);
break;
case 4 :
System.exit(0);
default: JOptionPane.showMessageDialog(null, "Invalid number");
May I suggest you write a program to open and read a file, and the file name is the first String argument ( args[0]) for the main method :
public static void main(String args[]) {...}
so that each time your command should simply be :
java XML input1.txt
If it is the case (3), in the method body the argument n (the instance of Node) rather than "jemz" should be used for comparison. The content of the data member of the node n could be any string. You are searching for the node n in the list which has nothing to do with "jemz". So there are some misunderstandings in your method body. If I were you I would choose (2) which may make more sense.
If you understand me could you please write a search method based on the choice (2)?
Are you going to search for a specific string "jemz" in a list? If so, your seach method should be declared as follows:
(1) public Boolean search(String s);
where the argument s will contain a string, such as "jemz". If there is a node where the data member value is "jemz" in the list, the method returns true. If not it returns false.
Or
(2) public Node search(String s); if there is a node where the data member value is "jemz" then the method returns that node.
(3) Your declaration is :
public Boolean search(Node n); which means this method is going to search for a specific Node.
Depending on different situations you have to choose only one from the above 3 declaration.
Please go to C forum. The code you presented is not in Java.
Should we first establish the input channel properly?
(1) In line 20 the "input= " is missing.
The corrected code would be:
input = JOptionPane.showInputDialog("Enter the next number");
(2) lines 15, 16 are deleted.
(3) before comming into the while loop the variable number should be initiated, e.g., as 0.
(4) try to print out each input. Test if the channel is established successfully or nor.
Then you may consider how to get max/min values among the series of input values.
I am sorry for the above post which is partially correct.
I should say: "I am also noticed that if the image file stored in your computer is an animated gif, it will be shown like cartoon with its own thread (provided it is obtained in the above way)." However if you obtain the image file via other method such as the method
try {
File f = new File("Alberta.jpg");
image = ImageIO.read(f);
} catch (Exception e) {}
provided by javax.imageio.ImageIO
, an animated gif will have no animation (dead).
I am also noticed that if the image file stored in your computer is an animated gif, it will be shown like cartoon with its own thread (provided it is obtained in the above way). However if you obtain the image file via other method such as the method getImage(getCodeBase(),...) privided by Applet, an animated gif will have no animation (dead).
I have modified your final code for the image files located in your own computer.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Slide1 {
public static JButton button;
public static JLabel label;
public static ImageIcon img[]=new ImageIcon[3];
public static JFrame frame;
public static int count=0;
public static void main(String args[]) {
for (int i=0; i<3;i++)
img[i]=new ImageIcon("/home/noon/workspace/eclipse/Applets/src/images/ima" + (i+1) + "png");
button = new JButton("Click!");
label = new JLabel(img[1]);
frame = new JFrame("Slide");
frame.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 20));
frame.add(label);
frame.add(button);
JFrame.setDefaultLookAndFeelDecorated(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(750, 500);
frame.setVisible(true);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
label.setIcon(img[(int)(Math.random()*3)]);
}
});
}
}
If you use the image file in your own computer to create a ImageIcon instance, e.g. img1, the code in the first post you made will work well. You may simply replace the URL in line 11:
"http://calindragan.files.wordpress.com/2010/06/pictura_muzica.jpg"
by
"/home/noon/workspace/eclipse/Applets/src/images/ima1.jpg"
Try it.
i want to add two case
You may have one choice only for the output: either all lower case or all upper one unless you want to have two kinds of output: Upper and Lower. If you want both you have to do twice.
i use it in a case instead of default
I have no solution. We need help.
line 7 : case Character.isUpperCase(ch): is wrong. The reason is:
Only constant values may define each case. That is, Following each "case" must be a constant rather than variable/expression. The Character.isUpperCase(ch) is not a constant, thus it is not working.
If you don't like "if... " you may delete "if... ", which also works well. So the correct code for the switch could be:
switch (ch) {
case '\u0020':
break;
case '\u0009':
break;
default:
ch=Character.toLowerCase(ch);
store+=ch;
}
You may learn how to write Psuedo code from web sites, such as
http://www.unf.edu/~broggio/cop2221/2221pseu.htm
Following the samples overthere we may write as follows:
create an input channel
ask client to type in score
convert the input into int variable
if .....
The job to convert uppercase character to lower case should be done after the confirmation of the non-space character(i.e. it is not a space). Therefore the switch code should be:
switch (ch)
{
case ' ':
break;
default:
if (Character.isUpperCase(ch))
ch = Character.toLowerCase(ch);
store+=ch;
}
Since the wrapper class Character is used one has to import the package: java.lang.*;
Attached please find the code modified.
Accodring to your for loop body, if a space has been found, the “break" is executed so that the loop operation terminates. It will not continue to do scanning. You should replace "break" by "continue".
for (int i=0; i<ln; i++)
{
ch=value.charAt(i);
if (ch==' ')
continue;
else
store+=ch;
}
import java.io.*;
import java.lang.*;
class Test
{
public static void main (String arge[]) throws IOException
{
InputStreamReader values = new InputStreamReader (System.in);
BufferedReader br = new BufferedReader (values);
String value,store;
char ch;
System.out.print ("Input String: ");
value = br.readLine();
store = "";
int ln = value.length();
for (int i=0; i<ln; i++)
{
ch=value.charAt(i);
switch (ch)
{
case ' ':
break;
default:
if (Character.isUpperCase(ch))
ch = Character.toLowerCase(ch);
store+=ch;
}
}
System.out.println(store);
}
}
The method name should always be starting with lower case conventionally speaking.
the code should be:
ch=value.charAt(i);
If you have already had JDK 1.6 in your machine then
download Java ME SDK 3.0
http://www.oracle.com/technetwork/java/javame/downloads/sdk30-jsp-139759.html
do some programing in J2ME
Then under your working folder : projectName/dist/ you may find the corresponding file ***.jar ready for mobile phone .
jemz, when removing a node from a list one has to specify which node is going to be deleted. For example, if you are going to delete a node where the data member value is a specific string, e.g. "wonderful". You may have to do a search for the specific string in the list. In this case the signature of the method should be:
Node remove(String s) {...} rather than Node remove(Node n){....} unless you just want to delete a specific node n.
Anyway, I write the following two methods to delete 1. the head or 2. the tail node for your reference. Provided that Node definition is:
class Node{
String value;
Node next;
}
public Node removeFirst(){// delete the head node of the list
if (isEmpty()) // if the list is empty
return null; // return null, i.e. no node can be returned
else { // if the list is not empty
Node p = head; // make node p to represent the head node
head = head.next; // after delete the head the next node of the original head will be the new head
return p; // return the previous head represented by p
}
}
public Node removeLast(){ // delete the tail of the list
if (isEmpty()) // if the list is empty
return null; // return no node
else { // if the list is not empty
Node p = head; // make p to represent the original head
while(p.next !=tail) //when …
jemz, I have comments on your program:
(1) In your program, the declaration of some methods should be changed.
For example, public Node addFirst(Node n) // in line 26
It does not make sense if you have to return a node after successfully inserting the new node.So, when you are going to insert a new node n into the list the return type should altered with boolean or void.
After 37 line you should insert a code:
Size++; .// since you have inserted a new code before the head.
skyzer, Is the n an instance of Node or that of String?
I think some things in jemz declare of the method "remove" should be altered as :
public boolean remove(String n) {...}
provided the definition of the class Node is wirtten as :
class Node {
String item;
Node next;
}
Not at all. Please make sure you mark the thread as solved if your queries have been answered.
Not at all. Please make sure you mark the thread as solved if your queries have been answered.
toferdagofer, As I said before, within constructor you re-define/re-declare the label2,label4,label6, and label8 as local variable of the type JTextField, which is wrong. Why? While you re-declare and initiate them as local variables, the attributes of the same names, as you declared for the class, are in fact not initiated. Therefore, the run time error message : “java.lang.NullPointerException” is thrown when executing the line of code:
adultPrice = label2.getText() ; //(line 99)
because the attribute label2 is null.
I also have a comment on the naming of variables: label2,…label8, which are in fact TextField’s instances. I would name them as textfield1,... textfield4 so that their names are meaningful.
In constructor you redefine the label2,label4,label6, and label8 as local variable of the type JTextField, which is wrong. You have already declared them as attributes.
You should thus replace the 8 lines of code in the constructor by the following code:
JLabel label1 = new JLabel("Enter the price of one adult ticket : ");
label2 = new JTextField(10);
JLabel label3 = new JLabel("Enter the number of adult tickets sold : ");
label4 = new JTextField(10);
JLabel label5 = new JLabel("Enter the price of one child ticket : ");
label6 = new JTextField(10);
JLabel label7 = new JLabel("Enter the number of child tickets sold : ");
label8 = new JTextField(10);
I have no solution for this thread, but I have a comment on above coding.
class b extends a. The following line of code leads to a compiling error.
b obj = new a();// The instance of a super class cann't always be the one of its sub class.
The following line of code is valid:
a obj = new b(); // the instance of a sub-class will always be the one of its super class
Class Student extends class Person.
The student David, an instance of class Student( the sub class of class Person) is always a person (an instance of its super class) although a person (an instance of super class) is not necessarily a student ( an instance of sub class).
David is a student. Is David a person? Yes, he definitely is a person.
Robert is a person. But he isn't necessarily a student.
(1) if ((suit !='C') || (suit !='D') || (suit !='H') || (suit !='S')) means that suit can be any character.
and
(2) if ((suit !='C') && (suit !='D') && (suit !='H') && (suit !='S')) implies that
suit can be any character other than 'C' or 'D' or 'H' or 'S'
As far as I know, there is no other case to involve an abstract method.
For Details of a Method Declaration, please see the following web site:
http://www.cab.u-szeged.hu/WWW/java/tutorial/java/javaOO/methoddecl.html
Thank you, JavaAddict. The code you have modified above is definitely much better than previous code. I would like to put a comment on how to write a new line in a file.
My code:
bw.write(name + (char)10); // Add the ASCII code 10 for the character new line
works partially. After execution I have opened the output file “write.txt” via notepad where the new line character doesn’t work (it is shown as an unrecognized symbol). It works only in the case of opening the file by MS Word.
So one should use the way as JavaAddict writes:
bw.newLine(); // for changing line when writing to a file.