Primitive Wrappers | java.lang | java.util CUSTOMER ADDRESS USING STRING BUILDER Sample Input & Output: Enter Address Details : Enter Line 1 : 152, South Block Enter Line 2 : Raisina Hill Enter City : New Delhi Enter Country : India Enter Zip Code : 110011 Address Details : 152, South Block, Raisina Hill, New Delhi - 110011 India CODE: // fill your code here public class Address { private String line1; private String line2; private String city; private String country; private int zipCode; public String getLine1() { return line1; } public void setLine1(String line1) { this.line1 = line1; } public String getLine2() { return line2; } public void setLine2(String line2) { this.line2 = line2; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getCountry() { return country; } public void setCountry(String country) { this.country = country...
Collections: ARRAYLIST - INTRODUCTION Sample Input and Output 1: Enter the username 1 John Do you want to continue?(y/n) y Enter the username 2 Joe Do you want to continue?(y/n) n The Names entered are: John Joe CODE: import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String args[]) { String user; Scanner sc = new Scanner(System.in); ArrayList<String> al = new ArrayList<String>(); int i = 1; do { System.out.println("Enter the username "+i); al.add(sc.nextLine()); System.out.println("Do you want to continue?(y/n)"); user = sc.nextLine(); i++; }while(user.equalsIgnoreCase("y")); System.out.println("The Names entered are:"); for(String a:al) { System.out.println(a); } } }
Collections: TREEMAP To assist Event organizers, you need to develop a console application that shows the number of tickets sold in a particular price category. Sample Input and Output : [All Texts in bold corresponds to the input and rest are output] Enter the number of events: 3 Enter event details in CSV(Customer Name,Ticket Price,No of Seats Booked) Emily ,100,5 Natalie ,200,10 Grace ,100,3 Ticket Price Tickets Booked 100 8 200 10 CODE: //package com.mycom.collections.map; import java.util.Scanner; import java.util.Set; import java.util.TreeMap; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the number of events:"); int num = Integer.parseInt(sc.nextLine()); TreeMap<I...
Comments
Post a Comment