[Solved] my math is broken on TextView

The problem is here: double calcTipsPerHour = resultTotalHours / totalTips; This is currently doing 2 / 10 = 0.2. You want to do the reciprocal: double calcTipsPerHour = totalTips / resultTotalHours; This should also fix your waiter’s pay 0 solved my math is broken on TextView

[Solved] Calculate the difference between two dates in hours:minutes:seconds?

Try this function:- //1 minute = 60 seconds //1 hour = 60 x 60 = 3600 //1 day = 3600 x 24 = 86400 public void printDifference(Date startDate, Date endDate){ //milliseconds long different = endDate.getTime() – startDate.getTime(); System.out.println(“startDate : ” + startDate); System.out.println(“endDate : “+ endDate); System.out.println(“different : ” + different); long secondsInMilli = 1000; … Read more

[Solved] printing data of specific element from array in java [duplicate]

Your implementation of Clip class is wrong. It should be something like this: public class Clip { private String title; private String author; public Clip(String title, String author) { this.title = title; this.author = author; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getAuthor() … Read more

[Solved] How to get day of week name from selected date month and year in Android?

First convert your Date in to specific Date format using SimpleDateFormat Use SimpleDateFormat simpleDateFormat = new SimpleDateFormat(“EEEE”); to get Day name in week WHERE EEEE -> Day name in week SAMPLE CODE SimpleDateFormat inFormat = new SimpleDateFormat(“dd-MM-yyyy”); try { Date myDate = inFormat.parse(date+”-“+month+”-“+year); SimpleDateFormat simpleDateFormat = new SimpleDateFormat(“EEEE”); String dayName=simpleDateFormat.format(myDate); } catch (ParseException e) { … Read more

[Solved] creating a simple symmetric table in java [closed]

Your code is a beginning, but doesn’t fill all values. You should nest your for-loops, and only fill the left part. The right entry can then be mirrored from the left entry. Try this: public static void main(String[] args) { int[][] table = new int[5][8]; for (int row = 0; row < 5; row++) { … Read more

[Solved] Creating a method in Java

Declaration: void printNames(Iterable<Teacher> teachers) { for (Teacher teacher : teachers) { System.out.printf(“%s “, teacher.getName()); } } Usage: switch (selection) { case 1: printNames(teachers); break; solved Creating a method in Java

[Solved] Need Help Regarding Percentage Calculator Project [closed]

you can do it like this EditText input = (EditText) findViewById(R.id.ip); Button button = (Button) findViewById(R.id.calcbutton); TextView textView = findViewById(R.id.tv15); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int num = Integer.parseInt(input.getText().toString()); // for 0.15% float fifteen_percent = (float) ((num * 0.15) + num); textView.setText(String.valueOf(fifteen_percent)); } }); You can do the same for remaining … Read more

[Solved] Extracting two numbers from a string using java

For this you don’t even need regex. Just split the String and call the right indices: String latLongString = “Tracking info Latitude: 3.9574667 Longitude: 7.44882167″; //yours obviously won’t be hardcoded String[] split = latLongString.split(” “); String lat = split[3]; String lon = split[5]; solved Extracting two numbers from a string using java

[Solved] How are variables involved in a for loop’s body if they are not defined? [closed]

In your for loop, the variable result Is created outside of the for loops scope. Essentially, you are just changing the result variable that has already been created. If you attempted to create a new variable within the for loop such as “newResult = base * result”, it would fail if you attempted to use … Read more