Question

Lab Exercise 7.1 Instructions: Name your program as YourLastNameFirstinitialLE71.java. From the code in LE 6.2, do the following: 1. You will NOT be changing any of the logic in the code for LE 6.2 2. Create a separate class called Sports Teams. This class will have NO main(). 3. Insert a default constructor in the Sports Teams class. This is a method that is empty (with only open and close braces), and its header looks like this: public NameOfClass() 4. Code an overloaded constructor that will receive and capitalize the name of the fan, Brett, when an object for Sports Teams is created in the main(). a. In the SportsTeams class store the fans name in a field (class- level variable) called fan. b. You will insert the fans name in the header of the output. 5. Except, for the main(), take all the other methods in LE 6.2 and put them in the Sports Teams class. 6. Transfer the fields from LE 6.2 to SportsTeams. 7. Strip the word static from the fields and the method headers in the SportsTeams class. 8. Cut and paste the main() from LE 6.2 into your program file for LE 7.1 a. Create an object of the Sports Teams class. 1) Format: NameOfClass objectName= new NameOfClass(NameOfFan), b. Use that object for the method calls in the main(). 1) Format: objectName.methodName() 9. Make sure both classes are in the same directory. 10. To run both programs, you must run the class with the main().

Below is the code from LE 6.2 that LE 7.1 is referring to.

import java.util.Scanner;

public class lastNameLE62 {
private static Scanner in = new Scanner(System.in);

private static int size;

public static void arraySize() {
System.out.printf("How many sports are you interested in? ");
size = Integer.parseInt(in.nextLine());
}

public static String[] setFavoriteSports() {
String []favSports = new String[size];

for(int i=1; i<=size; i++) {
System.out.printf("Enter sport #%d: ", i);
favSports[i-1] = in.nextLine();
}

return favSports;
}

public static String[] setFavoriteTeams(String[] sports) {
String []teams = new String[size];

for(int i=1; i<=size; i++) {
System.out.printf("Enter your favorite %s team: ", sports[i-1]);
teams[i-1] = in.nextLine();
}

return teams;
}

public static String[] setLastChampionship(String[] teams) {
String []years = new String[size];

for(int i=1; i<=size; i++) {
System.out.printf("Enter the year of the %s' last championship: ", teams[i-1]);
years[i-1] = in.nextLine();
}

return years;
}

public static void printSportsTeams(String []sports, String []teams, String []years) {
System.out.println("MY SPORTS TEAMS");
for(int i=1; i<=size; i++) {
System.out.printf("%nSport: %s" +
"%nTeam: %s" +
"%nLast Championship: %s ", sports[i-1], teams[i-1], years[i-1]);
}
}
public static void main(String[] args) {
arraySize();
String sports[] = setFavoriteSports();
String teams[] = setFavoriteTeams(sports);
String years[] = setLastChampionship(teams);
printSportsTeams(sports, teams, years);
in.close();
  
} //end method main

} //end class lastNameLE62

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SportsTeam.java

import java.util.Scanner;

public class SportsTeam {

String fan;

private Scanner in = new Scanner(System.in);

private int size;

public SportsTeam() {

}

public SportsTeam(String fan) {

this.fan = fan.toUpperCase();

}

public void arraySize() {

System.out.printf("How many sports are you interested in? ");

size = Integer.parseInt(in.nextLine());

}

public String[] setFavoriteSports() {

String[] favSports = new String[size];

for (int i = 1; i <= size; i++) {

System.out.printf("Enter sport #%d: ", i);

favSports[i - 1] = in.nextLine();

}

return favSports;

}

public String[] setFavoriteTeams(String[] sports) {

String[] teams = new String[size];

for (int i = 1; i <= size; i++) {

System.out.printf("Enter your favorite %s team: ", sports[i - 1]);

teams[i - 1] = in.nextLine();

}

return teams;

}

public String[] setLastChampionship(String[] teams) {

String[] years = new String[size];

for (int i = 1; i <= size; i++) {

System.out.printf("Enter the year of the %s' last championship: ", teams[i - 1]);

years[i - 1] = in.nextLine();

}

return years;

}

public void printSportsTeams(String[] sports, String[] teams, String[] years) {

System.out.println("MY SPORTS TEAMS");

for (int i = 1; i <= size; i++) {

System.out.printf("%nSport: %s" + "%nTeam: %s" + "%nLast Championship: %s ", sports[i - 1], teams[i - 1],

years[i - 1]);

}

}

}

__________________________YourLastNameFirstInitialLE71.java__________________

public class YourLastNameFirstInitialLE71 {

public static void main(String[] args) {

SportsTeam st=new SportsTeam("Brett");

st.arraySize();

String sports[] = st.setFavoriteSports();

String teams[] = st.setFavoriteTeams(sports);

String years[] = st.setLastChampionship(teams);

st.printSportsTeams(sports, teams, years);

//in.close();

}

}

__________________Output________________________

D lastNameLE62.java D YourLastNameFirstlnitiaILE71.java X SportsTeam.java R M □ P 愧s 膼D s l , p C., X P..· 1 package pp; 2 3 public class YourastNameFirstinitialLEz1 <terminated> YourLastNameFirstInitialLE71 [Java Application] C:\Program Files\ How many sports are you interested in?1 Enter sport #1: Cricket Enter your favorite Cricket team: India Enter the year of the India last championship: 1018 MY SPORTS TEAMS public static void main(String[] args) SportsTeam st-new SportsTeam( Brett); 6 7 8 9 10 st.arraySize); String sports[] = st. setFavoritesports(); string teams[] st. setFavoriteTeams(sports); String years = st. setLastChampionship(teams); st.printSportsTeams (sports, teams, years); //in.close); Sport: Cricket Team: India Last Championship: 1018 12 13 14 15 16

Add a comment
Know the answer?
Add Answer to:
Below is the code from LE 6.2 that LE 7.1 is referring to. import java.util.Scanner; public...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • LE 7.1 Create a separate class called Family. This class will have NO main(). Insert a...

    LE 7.1 Create a separate class called Family. This class will have NO main(). Insert a default constructor in the Family class. This is a method that is empty and its header looks like this: public NameOfClass() Except, for the main(), take all the other methods in LE 6.2 and put them in the Family class. Transfer the class variables from LE 6.2 to Family. Strip the word static from the class variables and the method headers in the Family...

  • import java.util.Scanner; public class TriangleMaker {    public static void main(String[] args) {        //...

    import java.util.Scanner; public class TriangleMaker {    public static void main(String[] args) {        // TODO Auto-generated method stub        System.out.println("Welcome to the Triangle Maker! Enter the size of the triangle.");        Scanner keyboard = new Scanner(System.in);    int size = keyboard.nextInt();    for (int i = 1; i <= size; i++)    {    for (int j = 0; j < i; j++)    {    System.out.print("*");    }    System.out.println();    }    for (int...

  • Need help with the UML for this code? Thank you. import java.util.Scanner;    public class Assignment1Duong1895...

    Need help with the UML for this code? Thank you. import java.util.Scanner;    public class Assignment1Duong1895    {        public static void header()        {            System.out.println("\tWelcome to St. Joseph's College");        }        public static void main(String[] args) {            Scanner input = new Scanner(System.in);            int d;            header();            System.out.println("Enter number of items to process");            d = input.nextInt();      ...

  • Cant figure out how to fix error Code- import java.io.File; import java.io.IOException; import java.util.*; public class Program8 {    public static void main(String[] args)throws IOException{       ...

    Cant figure out how to fix error Code- import java.io.File; import java.io.IOException; import java.util.*; public class Program8 {    public static void main(String[] args)throws IOException{        File prg8 = new File("program8.txt");        Scanner reader = new Scanner(prg8);        String cName = "";        int cID = 0;        double bill = 0.0;        String email = "";        double nExempt = 0.0;        String tExempt = "";        int x = 0;        int j = 1;        while(reader.hasNextInt()) {            x = reader.nextInt();}        Customers c1 [] = new Customers [x];        for (int...

  • import java.util.Random; import java.util.ArrayList; /** * */ public class hw5_task8 { public static void main(String[] args)...

    import java.util.Random; import java.util.ArrayList; /** * */ public class hw5_task8 { public static void main(String[] args) { int[] grades = randomIntArr(10); printIntArray("grades", grades); ArrayList<Integer> indexesF_AL = selectIndexes_1(grades); System.out.println(" indexesF_AL: " + indexesF_AL); int[] indexesF_Arr = selectIndexes_2(grades); printIntArray("indexesF_Arr",indexesF_Arr); } public static int[] randomIntArr(int N){ int[] res = new int[N]; Random r = new Random(0); for(int i = 0; i < res.length; i++){ res[i] = r.nextInt(101); // r.nextInt(101) returns an in in range [0, 100] } return res; } public static void...

  • Given java code is below, please use it! import java.util.Scanner; public class LA2a {      ...

    Given java code is below, please use it! import java.util.Scanner; public class LA2a {       /**    * Number of digits in a valid value sequence    */    public static final int SEQ_DIGITS = 10;       /**    * Error for an invalid sequence    * (not correct number of characters    * or not made only of digits)    */    public static final String ERR_SEQ = "Invalid sequence";       /**    * Error for...

  • For the below code, what will be printed? public class mathchar { public static void main(String[]...

    For the below code, what will be printed? public class mathchar { public static void main(String[] args) { int i = 81, j = 3, k = 6; char w = 'f'; System.out.printf("%.2f\n", Math.sqrt(i)); System.out.printf("%.2f\n", Math.pow(j,k)); System.out.printf("%c\n", Character.toUpperCase(w)); System.out.printf("%c\n", Character.toLowerCase(w)); System.out.printf("%d\n", (int)(Math.random() * 21 + 6)); /* just tell range of possible values */ } }

  • //LinkedList import java.util.Scanner; public class PoD {    public static void main( String [] args )...

    //LinkedList import java.util.Scanner; public class PoD {    public static void main( String [] args ) { Scanner in = new Scanner( System.in ); LinkedList teamList = new LinkedList(); final int TEAM_SIZE = Integer.valueOf(in.nextLine()); for (int i=0; i<TEAM_SIZE; i++) { String newTeamMember = in.nextLine(); teamList.append(newTeamMember); } while (in.hasNext()) { String removeMember = in.nextLine(); teamList.remove(removeMember); }    System.out.println("FINAL TEAM:"); System.out.println(teamList); in.close(); System.out.print("END OF OUTPUT"); } } =========================================================================================== //PoD import java.util.NoSuchElementException; /** * A listnked list is a sequence of nodes with...

  • Consider the following sample program: import java.util.Scanner; public class Palindrome { public static void main(String[] args){...

    Consider the following sample program: import java.util.Scanner; public class Palindrome { public static void main(String[] args){ Scanner kb = new Scanner(System.in); System.out.println("Enter a word:"); String word = kb.next();    String reverse = ""; for (int i=word.length()-1; i>=0; i--) reverse += word.charAt(i); boolean result = reverse.equalsIgnoreCase(word);    if (result) System.out.println("The word " +word+ " is a Palindrome."); else System.out.println("The word " +word+ " is not a Palindrome."); } } Rewrite the program so that the main method is: public static void...

  • *This needs comments for each line of code. Thanks in advance!* import java.util.Scanner; public class LabProgram...

    *This needs comments for each line of code. Thanks in advance!* import java.util.Scanner; public class LabProgram {     public static void main(String[] args) {         Scanner scnr = new Scanner(System.in);         int numCount = scnr.nextInt();         int[] Array = new int[numCount];                for(int i = 0; i < numCount; ++i) {             Array[i] = scnr.nextInt();         }         int jasc = Array[0], gws = Array[1], numbers, tempo;         if (jasc > gws) {             tempo = jasc;             jasc...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT