Question

The goal in this exercise is to develop a program that will print out a list...

The goal in this exercise is to develop a program that will print out a list of student names together with other information foreach. The tab character

(an escape sequence) is helpful in getting the list to line up nicely. A program with only two names is in the file Names.java.

// ************************************************************

// Names.java

//

// Prints a list of student names with their hometowns

// and intended major

// ************************************************************

public class Names

{

// --------------------------

//

main prints the list

// --------------------------

public static void main (String[] args)

{

System.out.println ();

System.out.println (" \tName\t\tHometown") ;

System.out.println ("\t====\t\t========");

System.out.println ("\tSally\t\tRoanoke");

System.out.println ("\tAlexander\tWashington")

System.out.println ();

}

}

1. Save Names.java to your directory. Compile and run it to see how it works.

2. Modify the program so that your name and hometown and the name and hometown of at least two classmates sitting near

you in lab also are printed. Save, compile and run the program. Make sure the columns line up.

3. Modify the program to add a third column with the intended major of each person (assume Sally's major is Computer

Science and Alexander's major is Math). Be sure to add a label at the top of the third column and be sure everything is

lined up (use tab characters!).

Homework Answers

Answer #1

//names.java file content

import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class names{

public static void main(String []args){
System.out.println ();
System.out.println (" \tName\t\tHometown") ;
System.out.println ("\t====\t\t========");
System.out.println ("\tSally\t\tRoanoke");
System.out.println ("\tAlexander\tWashington");
//add two more student sitting near you
System.out.println ("\tJohn\t\tNewyork");
System.out.println ("\tSamanth\t\tBoston");
System.out.println ();
  
}
}

if executing in linux env , first compile

javac names.java

then execute using java names

//output of the program after adding two more names

        Name            Hometown                                                                                                                                                

        ====            ========                                                                                                                                                

        Sally           Roanoke                                                                                                                                                 

        Alexander       Washington                                                                                                                                              

        John            Newyork                                                                                                                                                 

        Samanth         Boston   

---------------------------------------------------------------------------

//program to add one more column major

import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class names{

public static void main(String []args){
System.out.println ();
System.out.println (" \tName\t\tHometown\tMajor") ;
System.out.println ("\t====\t\t========\t=====");
System.out.println ("\tSally\t\tRoanoke\t\tComputer science");
System.out.println ("\tAlexander\tWashington\tMath");
//add two more student sitting near you
System.out.println ("\tJohn\t\tNewyork\t\tElectronics");
System.out.println ("\tSamanth\t\tBoston\t\tSocial");
System.out.println ();
  
}
}

--------------------------------------------------------

output of second program

sh-4.3$ javac names.java                                                                                                                                                        

sh-4.3$ java -Xmx128M -Xms16M names

                                                                                                                                                                                

        Name            Hometown        Major                                                                                                                                   

        ====            ========        =====                                                                                                                                   

        Sally           Roanoke         Computer science                                                                                                                        

        Alexander       Washington      Math                                                                                                                                    

        John            Newyork         Electronics                                                                                                                             

        Samanth         Boston          Social   

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
public class Programming { public static void main(String args[]) { System.out.println("I am learning how to program.");...
public class Programming { public static void main(String args[]) { System.out.println("I am learning how to program."); } } Compile this and execute this program then modify it to display I am learning how to program in Java. Change class name to Javaprogramming.java. compile and execute. Modify the Javaprogramming class so it prints two lines of output. Change name to Awesome. Add second output statement that displays That's awesome ! Save as awesome.java then compile and execute
7.6 LAB: Exception handling to detect input String vs. Integer The given program reads a list...
7.6 LAB: Exception handling to detect input String vs. Integer The given program reads a list of single-word first names and ages (ending with -1), and outputs that list with the age incremented. The program fails and throws an exception if the second input on a line is a String rather than an Integer. At FIXME in the code, add a try/catch statement to catch java.util.InputMismatchException, and output 0 for the age. Ex: If the input is: Lee 18 Lua...
Task 1: You will modify the add method in the LinkedBag class.Add a second parameter to...
Task 1: You will modify the add method in the LinkedBag class.Add a second parameter to the method header that will be a boolean variable: public boolean add(T newEntry, boolean sorted) The modification to the add method will makeit possible toadd new entriesto the beginning of the list, as it does now, but also to add new entries in sorted order. The sorted parameter if set to false will result in the existing functionality being executed (it will add the...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
I am trying to make a program in C# and was wondering how it could be...
I am trying to make a program in C# and was wondering how it could be done based on the given instructions. Here is the code that i have so far... namespace Conversions { partial class Form1 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if...
Coding in Python Add radio button options for filing status to the tax calculator program of...
Coding in Python Add radio button options for filing status to the tax calculator program of Project 1. The user selects one of these options to determine the tax rate. The Single option’s rate is 20%. The Married option is 15%. The Divorced option is 10%. The default option is Single. Be sure to use the field names provided in the comments in your starter code. ================== Project 1 code: # Initialize the constants TAX_RATE = 0.20 STANDARD_DEDUCTION = 10000.0...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the following subsections can all go in one big file called pointerpractice.cpp. 1.1     Basics Write a function, int square 1(int∗ p), that takes a pointer to an int and returns the square of the int that it points to. Write a function, void square 2(int∗ p), that takes a pointer to an int and replaces that int (the one pointed to by p) with its...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
I've posted this question like 3 times now and I can't seem to find someone that...
I've posted this question like 3 times now and I can't seem to find someone that is able to answer it. Please can someone help me code this? Thank you!! Programming Project #4 – Programmer Jones and the Temple of Gloom Part 1 The stack data structure plays a pivotal role in the design of computer games. Any algorithm that requires the user to retrace their steps is a perfect candidate for using a stack. In this simple game you...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 565 Error 2 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 761 I need this code to COMPILE and RUN, but I cannot get rid of this error. Please Help!! #include #include #include #include using namespace std; enum contactGroupType {// used in extPersonType FAMILY, FRIEND, BUSINESS, UNFILLED }; class addressType { private:...