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
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________________________
Below is the code from LE 6.2 that LE 7.1 is referring to. import java.util.Scanner; public...
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...
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(); ...
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...
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.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...
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[] 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 */ } }
*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...
java programming how would i modify the code below to add a GUI (with a main menu with graphics and buttons, etc...) and include an option to print a list of all students added in a grid format and short by name, course, instructor, and location. ///main public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList<Student>students = new ArrayList<>(); int choice; while(true) { displayMenu(); choice = in.nextInt(); switch(choice) { case 1: in.nextLine(); System.out.println("Enter Student Name"); String name...
Convert Code from Java to C++ Convert : import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Template { public static void main(String args[]) { Scanner sc1 = new Scanner(System.in); //Standard input data String[] line1 = sc1.nextLine().split(","); //getting input and spliting on basis of "," String[] line2 = sc1.nextLine().split(" "); //getting input and spiliting on basis of " " Map<String, String> mapping = new HashMap<String, String>(); for(int i=0;i<line1.length;i++) { mapping.put(line1[i].split("=")[0], line1[i].split("=")[1]); //string in map where in [] as key and...