Vote count: -1
I'm trying to let users to input values to get a new display, but I still can't get the correct output.
import java.util.Scanner;
/** * A class for displaying three lines of information at various positions * on the screen (the standard output), which may be used as a display of * the "opening screen" of any console program. For example, a typical use * might be used to display the programmer's ID information, the submission * identifier, and the title of the submission. * */enter code here
public class OpeningScreen
{
private int numberOfBlankLinesBefore;
private int numberOfBlankLinesAfter;
private int numberOfSpacesToIndent;
private String firstLine;
private String secondLine;
private String thirdLine;
public OpeningScreen()
{
System.out.println("\n\n\n\n\n\n\n\n\n\n\n\t\t"
+"*******:*******:*******\n\t\t*******"
+" \n\t\tConstructors for the Opening Screen Class"
+"\n\n\n\n\n\n\n\n\n\n\n");
}
public OpeningScreen
(
String firstLine, //in
String secondLine, //in
String thirdLine //in
)
{
this(firstLine,secondLine,thirdLine,0,0,0);
}
public OpeningScreen
(
String firstLine, //in
String secondLine, //in
String thirdLine, //in
int numberOfSpacesToIndent //in
)
{
this(firstLine,secondLine,thirdLine,numberOfSpacesToIndent,0,0);
}
public OpeningScreen
(
String firstLine, //in
String secondLine, //in
String thirdLine, //in
int numberOfSpacesToIndent, //in
int numberOfBlankLinesBefore, //in
int numberOfBlankLinesAfter //in
)
{
this.firstLine = firstLine;
this.secondLine = secondLine;
this.thirdLine = thirdLine;
this.numberOfSpacesToIndent = numberOfSpacesToIndent;
this.numberOfBlankLinesBefore = numberOfBlankLinesBefore;
this.numberOfBlankLinesAfter = numberOfBlankLinesAfter;
}
public void display()
{
Scanner keyboard = new Scanner(System.in);
for(int i=0;i<=numberOfBlankLinesBefore;i++)
{
if(i>0)
System.out.print("\n");
}
for(int i=0;i<=numberOfSpacesToIndent;i++)
{
if(i>0)
System.out.print(" ");
}
System.out.print(firstLine+"\n");
for(int i=0;i<=numberOfSpacesToIndent;i++)
{
if(i>0)
System.out.print(" ");
}
System.out.print(secondLine+"\n");
for(int i=0;i<=numberOfSpacesToIndent;i++)
{
if(i>0)
System.out.print(" ");
}
System.out.print(thirdLine+"\n");
for(int i=0;i<=numberOfBlankLinesAfter;i++)
{
if(i>0)
System.out.print("\n");
}
}
private void pause()
{
Scanner keyboard = new Scanner(System.in);
System.out.print("Press Enter to continue ... ");
keyboard.nextLine();
}
public static void main(String[] args)
{
while(true)
{
Scanner keyboard = new Scanner(System.in);
String firstLine;
String secondLine;
String thirdLine;
int numberOfBlankLinesBefore;
int numberOfBlankLinesAfter;
int numberOfSpacesToIndent;
firstLine= keyboard.next();
secondLine= keyboard.next();
thirdLine= keyboard.next();
numberOfSpacesToIndent=keyboard.nextInt();
numberOfBlankLinesBefore=keyboard.nextInt();
numberOfBlankLinesAfter=keyboard.nextInt();
OpeningScreen p1 = new OpeningScreen();
OpeningScreen p2 = new OpeningScreen(firstLine,secondLine,thirdLine);
OpeningScreen p3 = new OpeningScreen(firstLine,secondLine,thirdLine,
numberOfSpacesToIndent);
OpeningScreen p4 = new OpeningScreen(firstLine,secondLine,thirdLine,
numberOfSpacesToIndent,numberOfBlankLinesBefore,
numberOfBlankLinesAfter);
p1.display();
p2.display();
p3.display();
p4.display();
OpeningScreen openingScreen= new OpeningScreen();
openingScreen.pause();
}
}
}
asked 58 secs ago
java overloading constructor and main method output
Aucun commentaire:
Enregistrer un commentaire