public class tenquantrongdenthesao { Map<String, double> cayvl =new HashMap<String, double>(); private ArrayList<String> d1 = new ArrayList<>(); private ArrayList<String> d2 = new ArrayList<>(); private String ten; private String maso; public tenquantrongdenthesao(String ten, String maso) { this.ten = ten; this.maso = maso; }
Question
public class tenquantrongdenthesao { Map<String, double> cayvl =new HashMap<String, double>(); private ArrayList<String> d1 = new ArrayList<>(); private ArrayList<String> d2 = new ArrayList<>(); private String ten; private String maso; public tenquantrongdenthesao(String ten, String maso) { this.ten = ten; this.maso = maso; }
Solution
This is a Java class named "tenquantrongdenthesao". Here's a step-by-step explanation of the code:
-
Map<String, double> cayvl =new HashMap<String, double>();This line declares a HashMap named "cayvl" with String as the key and double as the value. -
private ArrayList<String> d1 = new ArrayList<>();This line declares a private ArrayList of Strings named "d1". -
private ArrayList<String> d2 = new ArrayList<>();This line declares a private ArrayList of Strings named "d2". -
private String ten;This line declares a private String variable named "ten". -
private String maso;This line declares a private String variable named "maso". -
public tenquantrongdenthesao(String ten, String maso) { this.ten = ten; this.maso = maso; }This is a constructor for the class "tenquantrongdenthesao". It takes two parameters, both of which are Strings. The values of these parameters are assigned to the class's private variables "ten" and "maso" respectively.
Please note that the class does not have a main method, so it cannot be run as a standalone program. It seems to be a part of a larger program.
Similar Questions
import java.util.*; public class Test { public static void main(String[] args) { Map<Set<String>, List<String>> m = new HashMap<>(); ArrayList<String> list1 = new ArrayList<>(); list1.add("30"); list1.add("40"); ArrayList<String> list2 = new ArrayList<String>(); list2.add("35"); list2.add("45"); Set<String> set1 = new HashSet<>(); set1.add("ravi"); set1.add("ravi"); m.put(set1,list1); m.put(set1,list2); System.out.println(m); } }
public class Account{ private int accountNumber; private String holderName; private double balance; public Account(int accountNumber, String holderName, double balance) { this.accountNumber = accountNumber; this.holderName = holderName; this.balance = balance; } } public class Main{ public static void main(String args[]) { Account accObj1=new Account(1001,"Chandru",50000); System.out.println(accObj1); }}If the above code should give the output as “Account Number : 1001, Holder : Chandru, Balance : 50000”, which method should be overridden and that method should be written in which class.Select one:a.Override toString() method in Account classb.Override tostring() method in Account classc.Override tostring() method in Main classd.Override toString() method in Main class
What will be the output of the following Java code?Code:import java.util.*;import java.util.Map.Entry;public class OrderValue{ public static void main(String a[]){ Map<String, Integer> names = new HashMap<String, Integer>(); names.put("Anne", 10); names.put("John", 35); names.put("Bob", 2); Set<Entry<String, Integer>> set = names.entrySet(); List<Entry<String, Integer>> list = new ArrayList<Entry<String, Integer>>(set); Collections.sort( list, new Comparator<Map.Entry<String, Integer>>() { public int compare( Map.Entry<String, Integer> order1, Map.Entry<String, Integer> order2) { return (order2.getValue()).compareTo( order1.getValue() ); } }); for(Map.Entry<String, Integer> entry:list){ System.out.print(" "+entry.getKey()); } }}
public class Employee { public int id; public String name; private int sal; public Employee(int id, String name , int sal) { this.id = id; this.name = name; this.sal = sal; } public void setSal(int sal) { this.sal = sal; } public int getSal() { return sal; } public static List<Employee> getEmpList() { List<Employee> list = new ArrayList<>(); list.add(new Employee(111, "A", 2000)); list.add(new Employee(222, "B", 3000)); list.add(new Employee(333, "C", 4000)); list.add(new Employee(444, "D", 5000)); return list; }}public class Appp { public static void main(String[] args) { List<Employee> list = Employee.getEmpList(); for(Employee e : list) { //line 1 e.setSal(e.getSal()*2); //line 2 } //line 3 }}Choose the appropriate option to replace code line 1 to 3 to get the same output from the program. listEmployees.forEach(e -> e.setSal(e.getSal()*2));for(Employee e : listEmployees) {e -> e.setSal(e.getSal()*2);}for(Employee e : listEmployees) {forEach(e -> e.setSal(e.getSal()*2));}for(Employee e : listEmployees) {e.forEach() -> e.setSal(e.getSal()*2);}SubmitPowered by Infosys Wingspan
public class Employee {private int id;private String name;private float salary;private String pancardno;public Employee(){System.out.println("In default constructor");}public Employee(int id, String name, float salary) {this.id = id;this.name = name;this.salary = salary;}public Employee(int id, String name, float salary, String pancardno) {this(id,name,salary); this.pancardno = pancardno; }this();}
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.